File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
core/src/components/input-otp Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -304,12 +304,19 @@ export class InputOTP implements ComponentInterface {
304304 * Otherwise, use the default regex pattern based on type
305305 */
306306 private get validKeys ( ) : RegExp {
307- const { pattern, type } = this ;
307+ return new RegExp ( `^${ this . getPattern ( ) } $` ) ;
308+ }
308309
310+ /**
311+ * Gets the string pattern to pass to the input element
312+ * and use in the regex for allowed characters.
313+ */
314+ private getPattern ( ) : string {
315+ const { pattern, type } = this ;
309316 if ( pattern ) {
310- return new RegExp ( `^ ${ pattern } $` ) ;
317+ return pattern ;
311318 }
312- return type === 'number' ? / ^ [ 0 - 9 ] $ / : / ^ [ a - z A - Z 0 - 9 ] $ / ;
319+ return type === 'number' ? ' [0-9]' : ' [a-zA-Z0-9]' ;
313320 }
314321
315322 /**
@@ -717,15 +724,14 @@ export class InputOTP implements ComponentInterface {
717724 inputRefs,
718725 inputValues,
719726 length,
720- pattern,
721727 readonly,
722728 shape,
723729 size,
724- type,
725730 } = this ;
726731 const mode = getIonMode ( this ) ;
727732 const inputmode = this . getInputmode ( ) ;
728733 const tabbableIndex = this . getTabbableIndex ( ) ;
734+ const pattern = this . getPattern ( ) ;
729735
730736 return (
731737 < Host
@@ -751,7 +757,7 @@ export class InputOTP implements ComponentInterface {
751757 autoCapitalize = { autocapitalize }
752758 inputmode = { inputmode }
753759 maxLength = { 1 }
754- pattern = { pattern || ( type === 'number' ? '[0-9]' : '[a-zA-Z0-9]' ) }
760+ pattern = { pattern }
755761 disabled = { disabled }
756762 readOnly = { readonly }
757763 tabIndex = { index === tabbableIndex ? 0 : - 1 }
You can’t perform that action at this time.
0 commit comments