Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/elements/ia-otp-input/ia-otp-input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAOTPInput>(html`<ia-otp-input></ia-otp-input>`);
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<IAOTPInput>(html`<ia-otp-input></ia-otp-input>`);
const inputs = el.shadowRoot?.querySelectorAll('input');
Expand Down
2 changes: 2 additions & 0 deletions src/elements/ia-otp-input/ia-otp-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading