@@ -210,7 +210,8 @@ TextField can be customized to create an OTP (one-time password) input by hiding
210210 inputMode = " numeric"
211211 pattern = " [0-9]*"
212212 autoComplete = " one-time-code"
213- className = " absolute inset-0 w-full h-full opacity-0 cursor-text caret-transparent"
213+ className = " absolute inset-0 w-full h-full
214+ opacity-0 cursor-text caret-transparent"
214215 />
215216 </TextField >
216217 );
@@ -222,23 +223,27 @@ TextField can be customized to create an OTP (one-time password) input by hiding
222223
223224 return (
224225 <div className = " flex gap-1.5 pointer-events-none" >
225- { Array .from ({length }, (_ , i ) => (
226- <div
227- key = { i }
228- className = { `
229- w-10 h-12 flex items-center justify-center
230- text-xl font-medium tabular-nums
231- rounded-lg bg-white dark:bg-zinc-900
232- border border-gray-300 dark:border-zinc-600
233- text-gray-900 dark:text-zinc-100
234- transition-shadow duration-150
235- ${focused && (value .length === i || (i === length - 1 && value .length >= length ))
236- ? ' ring-2 ring-blue-600 dark:ring-blue-500'
237- : ' ' }
238- ` } >
239- { value [i ] ?? ' ' }
240- </div >
241- ))}
226+ { Array .from ({length }, (_ , i ) => {
227+ let isAtCaret = value .length === i ;
228+ let isLastFilled = i === length - 1 && value .length >= length ;
229+ return (
230+ <div
231+ key = { i }
232+ className = { `
233+ w-10 h-12 flex items-center justify-center
234+ text-xl font-medium tabular-nums
235+ rounded-lg bg-white dark:bg-zinc-900
236+ border border-gray-300 dark:border-zinc-600
237+ text-gray-900 dark:text-zinc-100
238+ transition-shadow duration-150
239+ ${focused && (isAtCaret || isLastFilled )
240+ ? ' ring-2 ring-blue-600 dark:ring-blue-500'
241+ : ' ' }
242+ ` } >
243+ { value [i ] ?? ' ' }
244+ </div >
245+ );
246+ })}
242247 </div >
243248 );
244249 }
0 commit comments