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(); +});