Skip to content

Commit 3cff629

Browse files
committed
fix: add input search focus & blur methods
1 parent 88f165e commit 3cff629

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

components/input/Search.jsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export default {
2929
this.$emit('search', this.$refs.input.stateValue)
3030
this.$refs.input.focus()
3131
},
32+
focus () {
33+
this.$refs.input.focus()
34+
},
35+
36+
blur () {
37+
this.$refs.input.blur()
38+
},
3239
getButtonOrIcon () {
3340
const { prefixCls, size } = this
3441
const enterButton = getComponentFromProp(this, 'enterButton')
@@ -45,7 +52,7 @@ export default {
4552
},
4653
})
4754
} else if (enterButtonAsElement.tag === 'button') {
48-
return cloneElement(enterButtonAsElement[0], {
55+
return cloneElement(enterButtonAsElement, {
4956
on: {
5057
click: this.onSearch,
5158
},
@@ -93,14 +100,7 @@ export default {
93100
{...inputProps}
94101
class={inputClassName}
95102
ref='input'
96-
>
97-
{/* <Icon
98-
slot='suffix'
99-
class={`${prefixCls}-icon`}
100-
onClick={this.onSearch}
101-
type='search'
102-
/> */}
103-
</Input>
103+
/>
104104
)
105105
},
106106
}
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { mount } from '@vue/test-utils'
2+
import { asyncExpect } from '@/tests/utils'
3+
import Search from '../Search'
4+
import Button from '../../button'
5+
import focusTest from '../../../tests/shared/focusTest'
6+
7+
describe('Input.Search', () => {
8+
focusTest(Search)
9+
10+
it('should support custom button', async () => {
11+
const wrapper = mount({
12+
render () {
13+
return <Search enterButton={<button>ok</button>} />
14+
},
15+
}, { sync: false })
16+
await asyncExpect(() => {
17+
expect(wrapper.html()).toMatchSnapshot()
18+
})
19+
})
20+
21+
it('should support custom Button', async () => {
22+
const wrapper = mount({
23+
render () {
24+
return <Search enterButton={<Button>ok</Button>} />
25+
},
26+
}, { sync: false })
27+
await asyncExpect(() => {
28+
expect(wrapper.html()).toMatchSnapshot()
29+
})
30+
})
31+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Input.Search should support custom Button 1`] = `
4+
<span class="ant-input-search ant-input-search-enter-button ant-input-affix-wrapper ant-input-search ant-input-search-enter-button"><input type="text" class="ant-input ant-input-search ant-input-search-enter-button"><span class="ant-input-suffix"><button type="button" class="ant-btn ant-btn-default ant-input-search-button"><span>ok</span></button>
5+
</span>
6+
</span>
7+
`;
8+
9+
exports[`Input.Search should support custom button 1`] = `<span class="ant-input-search ant-input-search-enter-button ant-input-affix-wrapper ant-input-search ant-input-search-enter-button"><input type="text" class="ant-input ant-input-search ant-input-search-enter-button"><span class="ant-input-suffix"><button class="">ok</button></span></span>`;

0 commit comments

Comments
 (0)