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
3 changes: 3 additions & 0 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ const OptionList: React.RefForwardingComponent<
// >>> Close
case KeyCode.ESC: {
onToggleOpen(false);
if (open) {
event.stopPropagation();
}
}
}
},
Expand Down
13 changes: 12 additions & 1 deletion tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,12 @@ describe('Select.Basic', () => {
});

it('close on ESC', () => {
const wrapper = mount(<Select />);
const onKeyDown = jest.fn();
const wrapper = mount(
<div onKeyDown={onKeyDown}>
<Select />
</div>,
);
toggleOpen(wrapper);
wrapper
.find('input')
Expand All @@ -677,6 +682,12 @@ describe('Select.Basic', () => {

expect(wrapper.find('input').props().value).toBe('');
expectOpen(wrapper, false);
expect(onKeyDown).toHaveBeenCalledTimes(0);

// should keep propagation when optionList is closed
wrapper.simulate('keyDown', { which: KeyCode.ESC });
wrapper.update();
expect(onKeyDown).toHaveBeenCalledTimes(1);
});

it('close after select', () => {
Expand Down