Skip to content

Commit aeace76

Browse files
committed
refactor(input-otp): rename allowedKeys to pattern
1 parent 3e4fe5a commit aeace76

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

core/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ ion-input,css-prop,--placeholder-opacity,ios
781781
ion-input,css-prop,--placeholder-opacity,md
782782

783783
ion-input-otp,scoped
784-
ion-input-otp,prop,allowedKeys,string | undefined,undefined,false,false
785784
ion-input-otp,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
786785
ion-input-otp,prop,disabled,boolean,false,false,true
787786
ion-input-otp,prop,fill,"outline" | "solid" | undefined,'outline',false,false
788787
ion-input-otp,prop,inputmode,"decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined,undefined,false,false
789788
ion-input-otp,prop,length,number,4,false,false
789+
ion-input-otp,prop,pattern,string | undefined,undefined,false,false
790790
ion-input-otp,prop,readonly,boolean,false,false,true
791791
ion-input-otp,prop,separators,number[] | string | undefined,undefined,false,false
792792
ion-input-otp,prop,shape,"rectangular" | "round" | "soft",'round',false,false

core/src/components.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,10 +1322,6 @@ export namespace Components {
13221322
"value"?: string | number | null;
13231323
}
13241324
interface IonInputOtp {
1325-
/**
1326-
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[a-zA-Z0-9]"
1327-
*/
1328-
"allowedKeys"?: string;
13291325
/**
13301326
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
13311327
*/
@@ -1346,6 +1342,10 @@ export namespace Components {
13461342
* The number of input boxes to display.
13471343
*/
13481344
"length": number;
1345+
/**
1346+
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[a-zA-Z0-9]"
1347+
*/
1348+
"pattern"?: string;
13491349
/**
13501350
* If `true`, the user cannot modify the value.
13511351
*/
@@ -6254,10 +6254,6 @@ declare namespace LocalJSX {
62546254
"value"?: string | number | null;
62556255
}
62566256
interface IonInputOtp {
6257-
/**
6258-
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[a-zA-Z0-9]"
6259-
*/
6260-
"allowedKeys"?: string;
62616257
/**
62626258
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
62636259
*/
@@ -6286,6 +6282,10 @@ declare namespace LocalJSX {
62866282
* Emitted when the input is complete (all boxes filled)
62876283
*/
62886284
"onIonComplete"?: (event: IonInputOtpCustomEvent<InputOtpCompleteEventDetail>) => void;
6285+
/**
6286+
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[a-zA-Z0-9]"
6287+
*/
6288+
"pattern"?: string;
62896289
/**
62906290
* If `true`, the user cannot modify the value.
62916291
*/

core/src/components/input-otp/input-otp.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class InputOTP implements ComponentInterface {
6363
* For numbers (type="number"): "[0-9]"
6464
* For text (type="text"): "[a-zA-Z0-9]"
6565
*/
66-
@Prop() allowedKeys?: string;
66+
@Prop() pattern?: string;
6767

6868
/**
6969
* If `true`, the user cannot modify the value.
@@ -140,11 +140,11 @@ export class InputOTP implements ComponentInterface {
140140
* Get the default allowed keys based on type if not explicitly set
141141
*/
142142
private get validKeys(): RegExp {
143-
const { allowedKeys, type } = this;
143+
const { pattern, type } = this;
144144

145-
if (allowedKeys) {
145+
if (pattern) {
146146
// Create a regex that matches a single character from the provided pattern
147-
return new RegExp(`^${allowedKeys}$`, 'i');
147+
return new RegExp(`^${pattern}$`, 'i');
148148
}
149149
return type === 'number' ? /^[0-9]$/ : /^[a-zA-Z0-9]$/i;
150150
}
@@ -376,7 +376,7 @@ export class InputOTP implements ComponentInterface {
376376
}
377377

378378
render() {
379-
const { color, disabled, fill, hasFocus, inputId, inputRefs, inputValues, length, readonly, shape, size, type } =
379+
const { color, disabled, fill, hasFocus, inputId, inputRefs, inputValues, length, pattern, readonly, shape, size, type } =
380380
this;
381381
const mode = getIonMode(this);
382382
const inputmode = this.getInputmode();
@@ -405,7 +405,7 @@ export class InputOTP implements ComponentInterface {
405405
type="text"
406406
inputmode={inputmode}
407407
maxLength={1}
408-
pattern={type === 'number' ? '[0-9]' : undefined}
408+
pattern={pattern || (type === 'number' ? '[0-9]' : '[a-zA-Z0-9]')}
409409
disabled={disabled}
410410
readOnly={readonly}
411411
tabIndex={index === tabbableIndex ? 0 : -1}

core/src/components/input-otp/test/basic/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h2>Invalid</h2>
6969
<h2>Types</h2>
7070
<ion-input-otp length="6"> Numbers only </ion-input-otp>
7171
<ion-input-otp length="6" type="text"> Letters and numbers </ion-input-otp>
72-
<ion-input-otp type="text" allowed-keys="[a-fA-F]"> Custom Pattern: a-f and A-F </ion-input-otp>
72+
<ion-input-otp type="text" pattern="[a-fA-F]"> Custom Pattern: a-f and A-F </ion-input-otp>
7373
</div>
7474
</div>
7575
</ion-content>

core/src/components/input-otp/test/basic/input-otp.e2e.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
8888
await expect(inputBoxes.nth(3)).toHaveValue('5');
8989
});
9090

91-
test('should accept custom pattern when allowed-keys is set', async ({ page }) => {
91+
test('should accept custom pattern when pattern is set', async ({ page }) => {
9292
await page.setContent(
9393
`
94-
<ion-input-otp type="text" allowed-keys="[a-fA-F]">Description</ion-input-otp>
94+
<ion-input-otp type="text" pattern="[a-fA-F]">Description</ion-input-otp>
9595
`,
9696
config
9797
);

packages/angular/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,14 +1018,14 @@ This event will not emit when programmatically setting the `value` property.
10181018

10191019

10201020
@ProxyCmp({
1021-
inputs: ['allowedKeys', 'color', 'disabled', 'fill', 'inputmode', 'length', 'readonly', 'separators', 'shape', 'size', 'type', 'value']
1021+
inputs: ['color', 'disabled', 'fill', 'inputmode', 'length', 'pattern', 'readonly', 'separators', 'shape', 'size', 'type', 'value']
10221022
})
10231023
@Component({
10241024
selector: 'ion-input-otp',
10251025
changeDetection: ChangeDetectionStrategy.OnPush,
10261026
template: '<ng-content></ng-content>',
10271027
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
1028-
inputs: ['allowedKeys', 'color', 'disabled', 'fill', 'inputmode', 'length', 'readonly', 'separators', 'shape', 'size', 'type', 'value'],
1028+
inputs: ['color', 'disabled', 'fill', 'inputmode', 'length', 'pattern', 'readonly', 'separators', 'shape', 'size', 'type', 'value'],
10291029
})
10301030
export class IonInputOtp {
10311031
protected el: HTMLIonInputOtpElement;

packages/angular/standalone/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,14 +984,14 @@ export declare interface IonInfiniteScrollContent extends Components.IonInfinite
984984

985985
@ProxyCmp({
986986
defineCustomElementFn: defineIonInputOtp,
987-
inputs: ['allowedKeys', 'color', 'disabled', 'fill', 'inputmode', 'length', 'readonly', 'separators', 'shape', 'size', 'type', 'value']
987+
inputs: ['color', 'disabled', 'fill', 'inputmode', 'length', 'pattern', 'readonly', 'separators', 'shape', 'size', 'type', 'value']
988988
})
989989
@Component({
990990
selector: 'ion-input-otp',
991991
changeDetection: ChangeDetectionStrategy.OnPush,
992992
template: '<ng-content></ng-content>',
993993
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
994-
inputs: ['allowedKeys', 'color', 'disabled', 'fill', 'inputmode', 'length', 'readonly', 'separators', 'shape', 'size', 'type', 'value'],
994+
inputs: ['color', 'disabled', 'fill', 'inputmode', 'length', 'pattern', 'readonly', 'separators', 'shape', 'size', 'type', 'value'],
995995
standalone: true
996996
})
997997
export class IonInputOtp {

packages/vue/src/proxies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export const IonInputOtp: StencilVueComponent<JSX.IonInputOtp> = /*@__PURE__*/ d
498498
'fill',
499499
'inputmode',
500500
'length',
501-
'allowedKeys',
501+
'pattern',
502502
'readonly',
503503
'size',
504504
'separators',

0 commit comments

Comments
 (0)