@@ -203,16 +203,27 @@ export class InputOTP implements ComponentInterface {
203203
204204 if ( event . key === 'Backspace' ) {
205205 if ( this . inputValues [ index ] ) {
206- // If current input has a value, clear it
207- this . inputRefs [ index ] . value = '' ;
206+ // Remove the value at the current index
208207 this . inputValues [ index ] = '' ;
208+
209+ // Shift all values to the right of the current index left by one
210+ for ( let i = index ; i < length - 1 ; i ++ ) {
211+ this . inputValues [ i ] = this . inputValues [ i + 1 ] ;
212+ }
213+
214+ // Clear the last box
215+ this . inputValues [ length - 1 ] = '' ;
216+
217+ // Update all inputRefs to match inputValues
218+ for ( let i = 0 ; i < length ; i ++ ) {
219+ this . inputRefs [ i ] . value = this . inputValues [ i ] || '' ;
220+ }
221+
209222 this . updateValue ( ) ;
210- } else if ( index > 0 ) {
211- // If current input is empty, move to previous input and clear its value
223+ event . preventDefault ( ) ;
224+ } else if ( ! this . inputValues [ index ] && index > 0 ) {
225+ // If current input is empty, move to previous input
212226 this . focusPrevious ( index ) ;
213- this . inputRefs [ index - 1 ] . value = '' ;
214- this . inputValues [ index - 1 ] = '' ;
215- this . updateValue ( ) ;
216227 }
217228 } else if ( event . key === 'ArrowLeft' ) {
218229 event . preventDefault ( ) ;
@@ -365,7 +376,8 @@ export class InputOTP implements ComponentInterface {
365376 }
366377
367378 render ( ) {
368- const { color, disabled, fill, hasFocus, inputId, inputRefs, inputValues, length, readonly, shape, size, type } = this ;
379+ const { color, disabled, fill, hasFocus, inputId, inputRefs, inputValues, length, readonly, shape, size, type } =
380+ this ;
369381 const mode = getIonMode ( this ) ;
370382 const inputmode = this . getInputmode ( ) ;
371383 const tabbableIndex = this . getTabbableIndex ( ) ;
0 commit comments