diff --git a/packages/vant/src/number-keyboard/NumberKeyboard.tsx b/packages/vant/src/number-keyboard/NumberKeyboard.tsx index 7b8dbb7c9..96cb813d2 100644 --- a/packages/vant/src/number-keyboard/NumberKeyboard.tsx +++ b/packages/vant/src/number-keyboard/NumberKeyboard.tsx @@ -79,6 +79,8 @@ function shuffle(array: unknown[]) { export default defineComponent({ name, + inheritAttrs: false, + props: numberKeyboardProps, emits: [ @@ -91,7 +93,7 @@ export default defineComponent({ 'update:modelValue', ], - setup(props, { emit, slots }) { + setup(props, { emit, slots, attrs }) { const root = ref(); const genBasicKeys = () => { @@ -282,6 +284,7 @@ export default defineComponent({ })} onAnimationend={onAnimationEnd} onTouchstartPassive={stopPropagation} + {...attrs} > {Title}
diff --git a/packages/vant/src/number-keyboard/test/index.spec.ts b/packages/vant/src/number-keyboard/test/index.spec.ts index 128496256..6f6b46406 100644 --- a/packages/vant/src/number-keyboard/test/index.spec.ts +++ b/packages/vant/src/number-keyboard/test/index.spec.ts @@ -246,3 +246,18 @@ test('should not emit close event after clicking close button when blur-on-close clickKey(wrapper.findAll('.van-key')[12]); expect(wrapper.emitted('blur')).toBeFalsy(); }); + +test('should inherit attrs when using teleport prop', () => { + const root = document.createElement('div'); + mount(NumberKeyboard, { + props: { + teleport: root, + }, + attrs: { + class: 'foo', + }, + }); + + const el = root.querySelector('.van-number-keyboard'); + expect(el?.classList.contains('foo')).toBeTruthy(); +});