Skip to content
Merged
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: 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
23 changes: 23 additions & 0 deletions tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,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: 'opt1', value: 'opt1' },
{ label: 'opt2', value: 'opt2' },
]}
/>,
);
fireEvent.change(container.querySelector('input'), { target: { value: 'op' } });
jest.runAllTimers();
keyDown(container.querySelector('input'), KeyCode.DOWN);
keyDown(container.querySelector('input'), KeyCode.ENTER);
jest.runAllTimers();
expect(handleSelect).toHaveBeenCalledTimes(1);
expect(handleSelect).toHaveBeenCalledWith('opt1', expect.anything());
});

// Paste tests
[
{
Expand Down
Loading