MCPcopy
hub / github.com/JedWatson/react-select / openMenu

Method openMenu

packages/react-select/src/Select.tsx:904–928  ·  view source on GitHub ↗
(focusOption: 'first' | 'last')

Source from the content-addressed store, hash-verified

902 blur = this.blurInput;
903
904 openMenu(focusOption: 'first' | 'last') {
905 const { selectValue, isFocused } = this.state;
906 const focusableOptions = this.buildFocusableOptions();
907 let openAtIndex = focusOption === 'first' ? 0 : focusableOptions.length - 1;
908
909 if (!this.props.isMulti) {
910 const selectedIndex = focusableOptions.indexOf(selectValue[0]);
911 if (selectedIndex > -1) {
912 openAtIndex = selectedIndex;
913 }
914 }
915
916 // only scroll if the menu isn't already open
917 this.scrollToFocusedOptionOnUpdate = !(isFocused && this.menuListRef);
918
919 this.setState(
920 {
921 inputIsHiddenAfterUpdate: false,
922 focusedValue: null,
923 focusedOption: focusableOptions[openAtIndex],
924 focusedOptionId: this.getFocusedOptionId(focusableOptions[openAtIndex]),
925 },
926 () => this.onMenuOpen()
927 );
928 }
929
930 focusValue(direction: 'previous' | 'next') {
931 const { selectValue, focusedValue } = this.state;

Callers 1

SelectClass · 0.95

Calls 1

onMenuOpenMethod · 0.95

Tested by

no test coverage detected