Skip to content

Commit

Permalink
fix: Cascader should not clear search input when press left/right key (
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 authored Jul 6, 2023
1 parent b8aa0ed commit 47011b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/adjust-overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const placements = {

function Demo() {
return (
<div style={{ position: 'absolute', right: 10, top: 150 }}>
<div>
<MyCascader />
<br />
<br />
Expand Down
6 changes: 6 additions & 0 deletions src/OptionList/useKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export default (
}

case KeyCode.LEFT: {
if (searchValue) {
break;
}
if (rtl) {
nextColumn();
} else {
Expand All @@ -144,6 +147,9 @@ export default (
}

case KeyCode.RIGHT: {
if (searchValue) {
break;
}
if (rtl) {
prevColumn();
} else {
Expand Down
13 changes: 13 additions & 0 deletions tests/keyboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ describe('Cascader.Keyboard', () => {
).toHaveLength(0);
});

it('should not switch column when press left/right key in search input', () => {
wrapper = mount(<Cascader options={addressOptions} showSearch />);
wrapper.find('input').simulate('change', {
target: {
value: '123',
},
});
wrapper.find('input').simulate('keyDown', { which: KeyCode.LEFT });
expect(wrapper.isOpen()).toBeTruthy();
wrapper.find('input').simulate('keyDown', { which: KeyCode.RIGHT });
expect(wrapper.isOpen()).toBeTruthy();
});

// TODO: This is strange that we need check on this
it.skip('should not handle keyDown events when children specify the onKeyDown', () => {
wrapper = mount(
Expand Down

1 comment on commit 47011b9

@vercel
Copy link

@vercel vercel bot commented on 47011b9 Jul 6, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cascader – ./

cascader-git-master-react-component.vercel.app
cascader-react-component.vercel.app

Please sign in to comment.