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

Method findOption

packages/@react-aria/test-utils/src/menu.ts:166–182  ·  view source on GitHub ↗

* Returns a option matching the specified index or text content.

(opts: {indexOrText: number | string})

Source from the content-addressed store, hash-verified

164 * Returns a option matching the specified index or text content.
165 */
166 findOption(opts: {indexOrText: number | string}): HTMLElement {
167 let {indexOrText} = opts;
168
169 let option;
170 let options = this.getOptions();
171 let menu = this.getMenu();
172
173 if (typeof indexOrText === 'number') {
174 option = options[indexOrText];
175 } else if (typeof indexOrText === 'string' && menu != null) {
176 option = within(menu!)
177 .getByText(indexOrText)
178 .closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]')! as HTMLElement;
179 }
180
181 return option;
182 }
183
184 /**
185 * Toggles the selection of the desired menu option if possible. Defaults to using the interaction

Callers 3

toggleOptionSelectionMethod · 0.95
Menu.test.tsxFile · 0.45
ListBox.test.jsFile · 0.45

Calls 2

getOptionsMethod · 0.95
getMenuMethod · 0.95

Tested by

no test coverage detected