Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 7 additions & 1 deletion src/SelectInput/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
const { value: nextVal } = event.currentTarget;

// Handle Enter key submission - referencing Selector implementation
if (key === 'Enter' && mode === 'tags' && !compositionStatusRef.current && onSearchSubmit) {
if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是不是应该检测一下是否有内容再决定?按理说这个 Input 的优先级会更高,只有没有内容的时候再认为是 option 响应会比较好~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他地方应该有处理
image
这里只补充了!open

key === 'Enter' &&
mode === 'tags' &&
!open &&
!compositionStatusRef.current &&
onSearchSubmit
) {
onSearchSubmit(nextVal);
}

Expand Down
32 changes: 31 additions & 1 deletion tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import openControlledTest from './shared/openControlledTest';
import removeSelectedTest from './shared/removeSelectedTest';
import maxTagRenderTest from './shared/maxTagRenderTest';
import throwOptionValue from './shared/throwOptionValue';
import { injectRunAllTimers, findSelection, expectOpen, toggleOpen, keyDown } from './utils/common';
import {
injectRunAllTimers,
findSelection,
expectOpen,
toggleOpen,
keyDown,
keyUp,
} from './utils/common';
import type { CustomTagProps } from '@/BaseSelect';

describe('Select.Tags', () => {
Expand Down Expand Up @@ -140,6 +147,29 @@ describe('Select.Tags', () => {
expectOpen(container, false);
});

it('should trigger onSelect once when pressing Enter to select option in tags mode (dropdown open)', () => {
const handleSelect = jest.fn();
const { container } = render(
<Select
mode="tags"
open
showSearch
onSelect={handleSelect}
options={[
{ label: 'Dacryoadenitis', value: 'opt1' },
{ label: 'Dacryocystitis', value: 'opt2' },
]}
/>,
);
fireEvent.change(container.querySelector('input'), { target: { value: 'da' } });
jest.runAllTimers();
fireEvent.mouseMove(container.querySelectorAll('.rc-select-item-option')[0]);
keyDown(container.querySelector('input'), KeyCode.ENTER);
keyUp(container.querySelector('input'), KeyCode.ENTER);
jest.runAllTimers();
expect(handleSelect).toHaveBeenCalledTimes(1);
});

// Paste tests
[
{
Expand Down
Loading