MCPcopy Create free account
hub / github.com/adobe/react-spectrum / open

Method open

packages/@react-aria/test-utils/src/combobox.ts:92–132  ·  view source on GitHub ↗

* Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.

(opts: ComboBoxOpenOpts = {})

Source from the content-addressed store, hash-verified

90 * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
91 */
92 async open(opts: ComboBoxOpenOpts = {}): Promise<void> {
93 let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;
94 let trigger = this.getTrigger();
95 let combobox = this.getCombobox();
96 let isDisabled = trigger!.hasAttribute('disabled');
97
98 if (interactionType === 'mouse') {
99 if (triggerBehavior === 'focus') {
100 await this.user.click(combobox);
101 } else {
102 await this.user.click(trigger);
103 }
104 } else if (interactionType === 'keyboard') {
105 act(() => combobox.focus());
106 if (triggerBehavior !== 'focus') {
107 await this.user.keyboard('{ArrowDown}');
108 }
109 } else if (interactionType === 'touch') {
110 if (triggerBehavior === 'focus') {
111 await this.user.pointer({target: combobox, keys: '[TouchA]'});
112 } else {
113 await this.user.pointer({target: trigger, keys: '[TouchA]'});
114 }
115 }
116
117 await waitFor(() => {
118 if (!isDisabled && combobox.getAttribute('aria-controls') == null) {
119 throw new Error('No aria-controls found on combobox trigger element.');
120 } else {
121 return true;
122 }
123 });
124 let listBoxId = combobox.getAttribute('aria-controls');
125 await waitFor(() => {
126 if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {
127 throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
128 } else {
129 return true;
130 }
131 });
132 }
133
134 /**
135 * Returns an option matching the specified index or text content.

Callers 1

toggleOptionSelectionMethod · 0.95

Calls 5

getTriggerMethod · 0.95
getComboboxMethod · 0.95
actFunction · 0.90
hasAttributeMethod · 0.80
focusMethod · 0.80

Tested by

no test coverage detected