@@ -429,6 +429,60 @@ configs({ modes: ['ios'] }).forEach(({ title, config }) => {
429429
430430 await verifyInputValues ( inputOtp , [ '1' , '9' , '3' , '' ] ) ;
431431 } ) ;
432+
433+ test ( 'should handle autofill correctly' , async ( { page } ) => {
434+ await page . setContent ( `<ion-input-otp>Description</ion-input-otp>` , config ) ;
435+
436+ const firstInput = page . locator ( 'ion-input-otp input' ) . first ( ) ;
437+
438+ // Set the value in the 1st input directly and trigger input event
439+ // this simulates the value being set by autofill
440+ await firstInput . evaluate ( ( input ) => {
441+ ( input as HTMLInputElement ) . value = '1234' ;
442+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
443+ } ) ;
444+
445+ const inputOtp = page . locator ( 'ion-input-otp' ) ;
446+ await verifyInputValues ( inputOtp , [ '1' , '2' , '3' , '4' ] ) ;
447+ } ) ;
448+
449+ test ( 'should handle autofill correctly when it exceeds the length' , async ( { page } ) => {
450+ await page . setContent ( `<ion-input-otp>Description</ion-input-otp>` , config ) ;
451+
452+ const firstInput = page . locator ( 'ion-input-otp input' ) . first ( ) ;
453+
454+ // Set the value in the 1st input directly and trigger input event
455+ // this simulates the value being set by autofill
456+ await firstInput . evaluate ( ( input ) => {
457+ ( input as HTMLInputElement ) . value = '123456' ;
458+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
459+ } ) ;
460+
461+ const inputOtp = page . locator ( 'ion-input-otp' ) ;
462+ await verifyInputValues ( inputOtp , [ '1' , '2' , '3' , '4' ] ) ;
463+ } ) ;
464+
465+ test ( 'should handle autofill correctly when using autofill after typing 1 character' , async ( { page } ) => {
466+ await page . setContent ( `<ion-input-otp>Description</ion-input-otp>` , config ) ;
467+
468+ const firstInput = page . locator ( 'ion-input-otp input' ) . first ( ) ;
469+ await firstInput . focus ( ) ;
470+
471+ await page . keyboard . type ( '9' ) ;
472+
473+ const secondInput = page . locator ( 'ion-input-otp input' ) . nth ( 1 ) ;
474+ await secondInput . focus ( ) ;
475+
476+ // Set the value in the 2nd input directly and trigger input event
477+ // this simulates the value being set by autofill from the 2nd input
478+ await secondInput . evaluate ( ( input ) => {
479+ ( input as HTMLInputElement ) . value = '1234' ;
480+ input . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
481+ } ) ;
482+
483+ const inputOtp = page . locator ( 'ion-input-otp' ) ;
484+ await verifyInputValues ( inputOtp , [ '1' , '2' , '3' , '4' ] ) ;
485+ } ) ;
432486 } ) ;
433487
434488 test . describe ( title ( 'input-otp: focus functionality' ) , ( ) => {
0 commit comments