Skip to content

Commit 3643555

Browse files
fix: open dropdown on spacekey for keyboard accessibility
1 parent d1aeb03 commit 3643555

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/BaseSelect/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,11 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
463463
const { key } = event;
464464

465465
const isEnterKey = key === 'Enter';
466+
const isSpaceKey = key === ' ';
466467

467-
if (isEnterKey) {
468-
// Do not submit form when type in the input
468+
// Enter or Space opens dropdown (ARIA combobox: spacebar should open)
469+
if (isEnterKey || isSpaceKey) {
470+
// Do not submit form when type in the input; prevent Space from scrolling page
469471
if (mode !== 'combobox') {
470472
event.preventDefault();
471473
}
@@ -507,7 +509,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
507509
}
508510
}
509511

510-
if (mergedOpen && (!isEnterKey || !keyLockRef.current)) {
512+
if (mergedOpen && (!isEnterKey || !keyLockRef.current) && !isSpaceKey) {
511513
// Lock the Enter key after it is pressed to avoid repeated triggering of the onChange event.
512514
if (isEnterKey) {
513515
keyLockRef.current = true;

0 commit comments

Comments
 (0)