From 38fa302144c0326f6d5faadfd480cb6ec4543101 Mon Sep 17 00:00:00 2001 From: clau <1281581+dualcnhq@users.noreply.github.com> Date: Wed, 5 Aug 2026 16:20:16 +0800 Subject: [PATCH] add type check and value conversion at the top of the function --- src/elements/ia-otp-input/ia-otp-input.test.ts | 15 +++++++++++++++ src/elements/ia-otp-input/ia-otp-input.ts | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/elements/ia-otp-input/ia-otp-input.test.ts b/src/elements/ia-otp-input/ia-otp-input.test.ts index c2275d7..758c47b 100644 --- a/src/elements/ia-otp-input/ia-otp-input.test.ts +++ b/src/elements/ia-otp-input/ia-otp-input.test.ts @@ -575,6 +575,21 @@ describe('IA OTP Input', () => { expect(inputs?.[5].value).to.equal(''); }); + test('does not throw if prefill value property is set to a non-string value', async () => { + const el = await fixture(html``); + const inputs = el.shadowRoot?.querySelectorAll('input'); + + el.prefillValue = 23456 as unknown as string; + await el.updateComplete; + + expect(inputs?.[0].value).to.equal('2'); + expect(inputs?.[1].value).to.equal('3'); + expect(inputs?.[2].value).to.equal('4'); + expect(inputs?.[3].value).to.equal('5'); + expect(inputs?.[4].value).to.equal('6'); + expect(inputs?.[5].value).to.equal(''); + }); + test('returns focus to first character if inputs cleared', async () => { const el = await fixture(html``); const inputs = el.shadowRoot?.querySelectorAll('input'); diff --git a/src/elements/ia-otp-input/ia-otp-input.ts b/src/elements/ia-otp-input/ia-otp-input.ts index 4bff95b..8d8c687 100644 --- a/src/elements/ia-otp-input/ia-otp-input.ts +++ b/src/elements/ia-otp-input/ia-otp-input.ts @@ -155,6 +155,8 @@ export class IAOTPInput extends LitElement { * Submits the result if enough characters are filled. */ private fillInputs(value: string) { + if (typeof value !== 'string') value = String(value ?? ''); + if (value === '') this.clearInputs(); const charsToFill = value