mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Field: add focus method (#1987)
This commit is contained in:
parent
a995c203dc
commit
7685ecd254
@ -147,6 +147,7 @@ Use ref to get field instance and call instance methods
|
||||
|
||||
| Name | Attribute | Return value | Description |
|
||||
|------|------|------|------|
|
||||
| focus | - | - | Trigger input focus |
|
||||
| blur | - | - | Trigger input blur |
|
||||
|
||||
### Slot
|
||||
|
@ -127,6 +127,10 @@ export default create({
|
||||
},
|
||||
|
||||
methods: {
|
||||
focus() {
|
||||
this.$refs.input && this.$refs.input.focus();
|
||||
},
|
||||
|
||||
blur() {
|
||||
this.$refs.input && this.$refs.input.blur();
|
||||
},
|
||||
|
@ -110,6 +110,16 @@ test('blur method', () => {
|
||||
expect(fn.mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('focus method', () => {
|
||||
const fn = jest.fn();
|
||||
const wrapper = mount(Field);
|
||||
|
||||
wrapper.vm.$on('focus', fn);
|
||||
wrapper.vm.focus();
|
||||
|
||||
expect(fn.mock.calls.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('maxlength', async() => {
|
||||
const wrapper = mount(Field, {
|
||||
attrs: {
|
||||
|
@ -149,6 +149,7 @@ Field 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、`k
|
||||
|
||||
| 方法名 | 参数 | 返回值 | 介绍 |
|
||||
|------|------|------|------|
|
||||
| focus | - | - | 获取输入框焦点 |
|
||||
| blur | - | - | 取消输入框焦点 |
|
||||
|
||||
### Slot
|
||||
|
Loading…
x
Reference in New Issue
Block a user