feat: update input

pull/309/head
tangjinzhou 2018-12-09 11:43:27 +08:00
parent 6d2c5950f9
commit 71300d0c00
5 changed files with 96 additions and 0 deletions

View File

@ -71,6 +71,9 @@ export default {
blur () { blur () {
this.$refs.input.blur() this.$refs.input.blur()
}, },
select () {
this.$refs.input.select()
},
getInputClassName () { getInputClassName () {
const { prefixCls, size, disabled } = this.$props const { prefixCls, size, disabled } = this.$props

View File

@ -29,4 +29,91 @@ describe('Input.Search', () => {
expect(wrapper.html()).toMatchSnapshot() expect(wrapper.html()).toMatchSnapshot()
}) })
}) })
it('should disable enter button when disabled prop is true', () => {
const wrapper = mount({
render () {
return <Search placeholder='input search text' enterButton disabled />
},
})
expect(wrapper.findAll('.ant-btn-primary[disabled]')).toHaveLength(1)
})
// it('should trigger onSearch when click search icon', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('.anticon-search').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with text', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton="button text" onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with customize button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<Button>antd button</Button>} onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button of native', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<button type="button">antd button</button>} onSearch={onSearch} />
// );
// wrapper.find('button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when press enter', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 });
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'keydown',
// preventDefault: expect.any(Function),
// }));
// });
}) })

View File

@ -15,6 +15,10 @@ describe('Input', () => {
expect(wrapper.html()).toMatchSnapshot() expect(wrapper.html()).toMatchSnapshot()
}, 0) }, 0)
}) })
it('select()', () => {
const wrapper = mount(Input)
wrapper.vm.select()
})
}) })
focusTest(TextArea) focusTest(TextArea)

View File

@ -19,6 +19,7 @@
### Input Events ### Input Events
| Events Name | Description | Arguments | | Events Name | Description | Arguments |
| --- | --- | --- | | --- | --- | --- |
| change | callback when user input | function(e) | |
| pressEnter | The callback function that is triggered when Enter key is pressed. | function(e) | | pressEnter | The callback function that is triggered when Enter key is pressed. | function(e) |
> When `Input` is used in a `Form.Item` context, if the `Form.Item` has the `id` and `options` props defined > When `Input` is used in a `Form.Item` context, if the `Form.Item` has the `id` and `options` props defined

View File

@ -19,6 +19,7 @@
### Input 事件 ### Input 事件
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |
| --- | --- | --- | | --- | --- | --- |
| change | 输入框内容变化时的回调 | function(e) | |
| pressEnter | 按下回车的回调 | function(e) | | pressEnter | 按下回车的回调 | function(e) |
> 如果 `Input``Form.Item` 内,并且 `Form.Item` 设置了 `id``options` 属性,则 `value` `defaultValue``id` 属性会被自动设置。 > 如果 `Input``Form.Item` 内,并且 `Form.Item` 设置了 `id``options` 属性,则 `value` `defaultValue``id` 属性会被自动设置。