diff --git a/src/BaseSelect/index.tsx b/src/BaseSelect/index.tsx index 788ecd05..2b56b4dc 100644 --- a/src/BaseSelect/index.tsx +++ b/src/BaseSelect/index.tsx @@ -471,7 +471,9 @@ const BaseSelect = React.forwardRef((props, ref) // Enter or Space opens dropdown (ARIA combobox: spacebar should open) if (isEnterKey || isSpaceKey) { // Do not submit form when type in the input; prevent Space from scrolling page - if (mode !== 'combobox') { + const isCombobox = mode === 'combobox'; + const isEditable = isCombobox || showSearch; + if ((isSpaceKey && !isEditable) || (isEnterKey && !isCombobox)) { event.preventDefault(); } diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 46de7641..3cdf6128 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -2985,4 +2985,64 @@ describe('Select.Basic', () => { expect(selectedItem).not.toHaveAttribute('xxx'); }); + + describe('Space key behavior with showSearch', () => { + it('should not call preventDefault on space when showSearch is enabled', () => { + const { container } = render( + ); + + const input = container.querySelector('input'); + input.focus(); + + const keyDownEvent = new KeyboardEvent('keydown', { + key: ' ', + code: 'Space', + bubbles: true, + }); + const preventDefaultSpy = jest.spyOn(keyDownEvent, 'preventDefault'); + + input.dispatchEvent(keyDownEvent); + + expect(preventDefaultSpy).toHaveBeenCalled(); + }); + + it('should not call preventDefault on space in combobox mode', () => { + const { container } = render( +