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 b9534ee commit a18513c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
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
10 changes: 8 additions & 2 deletions src/OptionList/useKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import type { RefOptionListProps } from 'rc-select/lib/OptionList';
import { useBaseProps } from 'rc-select';
import type { RefOptionListProps } from 'rc-select/lib/OptionList';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
import { SEARCH_MARK } from '../hooks/useSearchOptions';

Expand Down Expand Up @@ -125,6 +125,9 @@ export default (
}

case KeyCode.LEFT: {
if (searchValue) {
break;
}
if (rtl) {
nextColumn();
} else {
Expand All @@ -134,6 +137,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 @@ -227,6 +227,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

0 comments on commit a18513c

Please sign in to comment.