Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/demo/search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: search
nav:
title: Demo
path: /demo
---

<code src="../examples/search.tsx"></code>
18 changes: 18 additions & 0 deletions docs/examples/search.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import Select, { Option } from '@rc-component/select';
import '../../assets/index.less';

const Demo = () => {
return (
<Select placeholder="placeholder" showSearch>
<Option value="11" text="lucy">
lucy
</Option>
<Option value="21" text="disabled">
disabled
</Option>
</Select>
);
};

export default Demo;
5 changes: 3 additions & 2 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,16 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
// KeyDown
const onInternalKeyDown: React.KeyboardEventHandler<HTMLDivElement> = (event) => {
const clearLock = getClearLock();
const { key } = event;
const { key, target } = event;

const isEnterKey = key === 'Enter';
const isSpaceKey = key === ' ';
const isTypingInput = (target as HTMLElement)?.tagName === 'INPUT';

// 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') {
if (!isTypingInput && mode !== 'combobox') {
event.preventDefault();
}

Expand Down
Loading