Skip to content

Commit a18513c

Browse files
authored
fix: Cascader should not clear search input when press left/right key (#416)
close ant-design/ant-design#43401
1 parent b9534ee commit a18513c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

examples/adjust-overflow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const placements = {
121121

122122
function Demo() {
123123
return (
124-
<div style={{ position: 'absolute', right: 10, top: 150 }}>
124+
<div>
125125
<MyCascader />
126126
<br />
127127
<br />

src/OptionList/useKeyboard.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react';
2-
import type { RefOptionListProps } from 'rc-select/lib/OptionList';
31
import { useBaseProps } from 'rc-select';
2+
import type { RefOptionListProps } from 'rc-select/lib/OptionList';
43
import KeyCode from 'rc-util/lib/KeyCode';
4+
import * as React from 'react';
55
import type { DefaultOptionType, InternalFieldNames, SingleValueType } from '../Cascader';
66
import { SEARCH_MARK } from '../hooks/useSearchOptions';
77

@@ -125,6 +125,9 @@ export default (
125125
}
126126

127127
case KeyCode.LEFT: {
128+
if (searchValue) {
129+
break;
130+
}
128131
if (rtl) {
129132
nextColumn();
130133
} else {
@@ -134,6 +137,9 @@ export default (
134137
}
135138

136139
case KeyCode.RIGHT: {
140+
if (searchValue) {
141+
break;
142+
}
137143
if (rtl) {
138144
prevColumn();
139145
} else {

tests/keyboard.spec.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ describe('Cascader.Keyboard', () => {
227227
).toHaveLength(0);
228228
});
229229

230+
it('should not switch column when press left/right key in search input', () => {
231+
wrapper = mount(<Cascader options={addressOptions} showSearch />);
232+
wrapper.find('input').simulate('change', {
233+
target: {
234+
value: '123',
235+
},
236+
});
237+
wrapper.find('input').simulate('keyDown', { which: KeyCode.LEFT });
238+
expect(wrapper.isOpen()).toBeTruthy();
239+
wrapper.find('input').simulate('keyDown', { which: KeyCode.RIGHT });
240+
expect(wrapper.isOpen()).toBeTruthy();
241+
});
242+
230243
// TODO: This is strange that we need check on this
231244
it.skip('should not handle keyDown events when children specify the onKeyDown', () => {
232245
wrapper = mount(

0 commit comments

Comments
 (0)