mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-10-04 15:59:58 +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 |
|
| Name | Attribute | Return value | Description |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
|
| focus | - | - | Trigger input focus |
|
||||||
| blur | - | - | Trigger input blur |
|
| blur | - | - | Trigger input blur |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
@ -127,6 +127,10 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
focus() {
|
||||||
|
this.$refs.input && this.$refs.input.focus();
|
||||||
|
},
|
||||||
|
|
||||||
blur() {
|
blur() {
|
||||||
this.$refs.input && this.$refs.input.blur();
|
this.$refs.input && this.$refs.input.blur();
|
||||||
},
|
},
|
||||||
|
@ -110,6 +110,16 @@ test('blur method', () => {
|
|||||||
expect(fn.mock.calls.length).toEqual(1);
|
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() => {
|
test('maxlength', async() => {
|
||||||
const wrapper = mount(Field, {
|
const wrapper = mount(Field, {
|
||||||
attrs: {
|
attrs: {
|
||||||
|
@ -149,6 +149,7 @@ Field 默认支持 Input 标签所有的原生事件,如 `focus`、`blur`、`k
|
|||||||
|
|
||||||
| 方法名 | 参数 | 返回值 | 介绍 |
|
| 方法名 | 参数 | 返回值 | 介绍 |
|
||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
|
| focus | - | - | 获取输入框焦点 |
|
||||||
| blur | - | - | 取消输入框焦点 |
|
| blur | - | - | 取消输入框焦点 |
|
||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user