From 07431487f315a79d7b3f72b2f4c81c6b4281777c Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 9 Apr 2021 14:33:59 +0800 Subject: [PATCH] fix(Field): autofocus prop not work (#8488) --- src/field/Field.tsx | 2 ++ src/field/test/index.spec.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/field/Field.tsx b/src/field/Field.tsx index 43c698216..86bf8fb20 100644 --- a/src/field/Field.tsx +++ b/src/field/Field.tsx @@ -59,6 +59,7 @@ export const fieldProps = { formatter: Function as PropType<(value: string) => string>, leftIcon: String, rightIcon: String, + autofocus: Boolean, clearable: Boolean, maxlength: [Number, String], inputAlign: String as PropType, @@ -397,6 +398,7 @@ export default defineComponent({ value: props.modelValue, disabled: getProp('disabled'), readonly: getProp('readonly'), + autofocus: props.autofocus, placeholder: props.placeholder, autocomplete: props.autocomplete, onBlur, diff --git a/src/field/test/index.spec.js b/src/field/test/index.spec.js index feb8f2373..babb4b0c4 100644 --- a/src/field/test/index.spec.js +++ b/src/field/test/index.spec.js @@ -444,3 +444,14 @@ test('should change clear icon when using clear-icon prop', async () => { await input.trigger('focus'); expect(wrapper.find('.van-field__clear').html()).toMatchSnapshot(); }); + +test('should render autofocus attribute to input when using autofocus prop', async () => { + const wrapper = mount(Field, { + props: { + autofocus: true, + }, + }); + + const input = wrapper.find('input'); + expect(input.element.hasAttributes('autofocus')).toBeTruthy(); +});