Skip to content

Commit

Permalink
fix: should stopPropagation when pressing esc (#588)
Browse files Browse the repository at this point in the history
* fix: should stopPropagation when pressing esc

* chore: optimize logic
  • Loading branch information
kerm1it authored Jan 19, 2021
1 parent ea9e62d commit 61aaf4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

1 comment on commit 61aaf4f

@vercel
Copy link

@vercel vercel bot commented on 61aaf4f Jan 19, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.