File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -185,7 +185,12 @@ export const InputOtp = React.memo(
185185
186186 default : {
187187 //Prevent non-numeric characters from being entered if integerOnly is true or if the length of the input is greater than the specified length
188- if ( ( props ?. integerOnly && ! ( event . code !== 'Space' && Number ( event . key ) >= 0 && Number ( event . key ) <= 9 ) ) || ( tokens . join ( '' ) . length >= props . length && event . code !== 'Delete' ) ) {
188+ const target = event . target ;
189+ const hasSelection = target . selectionStart !== target . selectionEnd ;
190+ const isAtMaxLength = tokens . join ( '' ) . length >= props . length ;
191+ const isValidKey = props . integerOnly ? / ^ [ 0 - 9 ] $ / . test ( event . key ) : true ;
192+
193+ if ( ! isValidKey || ( isAtMaxLength && event . code !== 'Delete' && ! hasSelection ) ) {
189194 event . preventDefault ( ) ;
190195 }
191196
You can’t perform that action at this time.
0 commit comments