Skip to content

Commit 25fe143

Browse files
committed
feat(menu): add openMenuOnArrows option to allow disabling arrow keys to open the menu
1 parent 28251dc commit 25fe143

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/react-select/src/Select.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ export interface Props<
248248
openMenuOnFocus: boolean;
249249
/** Allows control of whether the menu is opened when the Select is clicked */
250250
openMenuOnClick: boolean;
251+
/** Allows control of whether the menu is opened on up and down arrows */
252+
openMenuOnArrows: boolean;
251253
/** Array of options that populate the select menu */
252254
options: OptionsOrGroups<Option, Group>;
253255
/** Number of options to jump in menu when page{up|down} keys are used */
@@ -310,6 +312,7 @@ export const defaultProps = {
310312
noOptionsMessage: () => 'No options',
311313
openMenuOnFocus: false,
312314
openMenuOnClick: true,
315+
openMenuOnArrows: true,
313316
options: [],
314317
pageSize: 5,
315318
placeholder: 'Select...',
@@ -1565,6 +1568,7 @@ export default class Select<
15651568
onKeyDown,
15661569
tabSelectsValue,
15671570
openMenuOnFocus,
1571+
openMenuOnArrows,
15681572
} = this.props;
15691573
const { focusedOption, focusedValue, selectValue } = this.state;
15701574

@@ -1657,15 +1661,20 @@ export default class Select<
16571661
this.selectOption(focusedOption);
16581662
break;
16591663
case 'ArrowUp':
1664+
console.log('up', menuIsOpen);
16601665
if (menuIsOpen) {
16611666
this.focusOption('up');
1667+
} else if (!openMenuOnArrows) {
1668+
return;
16621669
} else {
16631670
this.openMenu('last');
16641671
}
16651672
break;
16661673
case 'ArrowDown':
16671674
if (menuIsOpen) {
16681675
this.focusOption('down');
1676+
} else if (!openMenuOnArrows) {
1677+
return;
16691678
} else {
16701679
this.openMenu('first');
16711680
}

0 commit comments

Comments
 (0)