diff --git a/packages/vant/src/number-keyboard/NumberKeyboard.tsx b/packages/vant/src/number-keyboard/NumberKeyboard.tsx index 4a702d161..bde3a6f94 100644 --- a/packages/vant/src/number-keyboard/NumberKeyboard.tsx +++ b/packages/vant/src/number-keyboard/NumberKeyboard.tsx @@ -123,7 +123,9 @@ export default defineComponent({ const { extraKey } = props; const extraKeys = Array.isArray(extraKey) ? extraKey : [extraKey]; - if (extraKeys.length === 1) { + if (extraKeys.length === 0) { + keys.push({ text: 0, wider: true }); + } else if (extraKeys.length === 1) { keys.push( { text: 0, wider: true }, { text: extraKeys[0], type: 'extra' }, diff --git a/packages/vant/src/number-keyboard/test/__snapshots__/index.spec.ts.snap b/packages/vant/src/number-keyboard/test/__snapshots__/index.spec.ts.snap index c86be78a9..9afba9c93 100644 --- a/packages/vant/src/number-keyboard/test/__snapshots__/index.spec.ts.snap +++ b/packages/vant/src/number-keyboard/test/__snapshots__/index.spec.ts.snap @@ -61,3 +61,13 @@ exports[`should render title-left slot correctly 1`] = ` `; + +exports[`should render zero key correctly when extra-key prop is an empty array 1`] = ` +
+ 0 +
+`; diff --git a/packages/vant/src/number-keyboard/test/index.spec.ts b/packages/vant/src/number-keyboard/test/index.spec.ts index 4f11db5ae..edca9c823 100644 --- a/packages/vant/src/number-keyboard/test/index.spec.ts +++ b/packages/vant/src/number-keyboard/test/index.spec.ts @@ -105,6 +105,16 @@ test('should render extra-key slot correctly', () => { expect(wrapper.findAll('.van-key')[9].html()).toMatchSnapshot(); }); +test('should render zero key correctly when extra-key prop is an empty array', () => { + const wrapper = mount(NumberKeyboard, { + props: { + theme: 'custom', + extraKey: [], + }, + }); + expect(wrapper.findAll('.van-key')[9].html()).toMatchSnapshot(); +}); + test('should render delete slot correctly', () => { const wrapper = mount(NumberKeyboard, { slots: {