mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
This commit is contained in:
parent
ae9e02a6c3
commit
59f805d323
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, mount } from 'enzyme';
|
import { render, mount } from 'enzyme';
|
||||||
import { renderToJson } from 'enzyme-to-json';
|
import { renderToJson } from 'enzyme-to-json';
|
||||||
|
import KeyCode from 'rc-util/lib/KeyCode';
|
||||||
import Cascader from '..';
|
import Cascader from '..';
|
||||||
|
|
||||||
const options = [{
|
const options = [{
|
||||||
@ -51,7 +52,6 @@ describe('Cascader', () => {
|
|||||||
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
|
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('can be selected', () => {
|
it('can be selected', () => {
|
||||||
const wrapper = mount(<Cascader options={options} />);
|
const wrapper = mount(<Cascader options={options} />);
|
||||||
wrapper.find('input').simulate('click');
|
wrapper.find('input').simulate('click');
|
||||||
@ -68,4 +68,13 @@ describe('Cascader', () => {
|
|||||||
.simulate('click');
|
.simulate('click');
|
||||||
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
|
expect(renderToJson(render(wrapper.find('Trigger').node.getComponent()))).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('backspace should work with `Cascader[showSearch]`', () => {
|
||||||
|
const wrapper = mount(<Cascader options={options} showSearch />);
|
||||||
|
wrapper.find('input').simulate('change', { target: { value: '123' } });
|
||||||
|
expect(wrapper.state('inputValue')).toBe('123');
|
||||||
|
wrapper.find('input').simulate('keydown', { keyCode: KeyCode.BACKSPACE });
|
||||||
|
// Simulate onKeyDown will not trigger onChange by default, so the value is still '123'
|
||||||
|
expect(wrapper.state('inputValue')).toBe('123');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,7 @@ import RcCascader from 'rc-cascader';
|
|||||||
import arrayTreeFilter from 'array-tree-filter';
|
import arrayTreeFilter from 'array-tree-filter';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
|
import KeyCode from 'rc-util/lib/KeyCode';
|
||||||
import Input from '../input';
|
import Input from '../input';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
@ -172,6 +173,12 @@ export default class Cascader extends React.Component<CascaderProps, any> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleKeyDown = (e) => {
|
||||||
|
if (e.keyCode === KeyCode.BACKSPACE) {
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleInputChange = (e) => {
|
handleInputChange = (e) => {
|
||||||
const inputValue = e.target.value;
|
const inputValue = e.target.value;
|
||||||
this.setState({ inputValue });
|
this.setState({ inputValue });
|
||||||
@ -334,6 +341,7 @@ export default class Cascader extends React.Component<CascaderProps, any> {
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
onClick={showSearch ? this.handleInputClick : undefined}
|
onClick={showSearch ? this.handleInputClick : undefined}
|
||||||
onBlur={showSearch ? this.handleInputBlur : undefined}
|
onBlur={showSearch ? this.handleInputBlur : undefined}
|
||||||
|
onKeyDown={this.handleKeyDown}
|
||||||
onChange={showSearch ? this.handleInputChange : undefined}
|
onChange={showSearch ? this.handleInputChange : undefined}
|
||||||
/>
|
/>
|
||||||
<span className={`${prefixCls}-picker-label`}>
|
<span className={`${prefixCls}-picker-label`}>
|
||||||
|
Loading…
Reference in New Issue
Block a user