Skip to content

Commit 1c9c939

Browse files
committed
fix(input-otp): allow any kind of numeric character in any script for number type
1 parent b0fea61 commit 1c9c939

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

core/src/components.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ export namespace Components {
13471347
*/
13481348
"length": number;
13491349
/**
1350-
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[\\p{L}\\p{N}]"
1350+
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[\\p{N}]" For text (type="text"): "[\\p{L}\\p{N}]"
13511351
*/
13521352
"pattern"?: string;
13531353
/**
@@ -6315,7 +6315,7 @@ declare namespace LocalJSX {
63156315
*/
63166316
"onIonInput"?: (event: IonInputOtpCustomEvent<InputOtpInputEventDetail>) => void;
63176317
/**
6318-
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[0-9]" For text (type="text"): "[\\p{L}\\p{N}]"
6318+
* A regex pattern string for allowed characters. Defaults based on type. For numbers (type="number"): "[\\p{N}]" For text (type="text"): "[\\p{L}\\p{N}]"
63196319
*/
63206320
"pattern"?: string;
63216321
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class InputOTP implements ComponentInterface {
8888
/**
8989
* A regex pattern string for allowed characters. Defaults based on type.
9090
*
91-
* For numbers (type="number"): "[0-9]"
91+
* For numbers (type="number"): "[\\p{N}]"
9292
* For text (type="text"): "[\\p{L}\\p{N}]"
9393
*/
9494
@Prop() pattern?: string;
@@ -318,7 +318,7 @@ export class InputOTP implements ComponentInterface {
318318
if (pattern) {
319319
return pattern;
320320
}
321-
return type === 'number' ? '[0-9]' : '[\\p{L}\\p{N}]';
321+
return type === 'number' ? '[\\p{N}]' : '[\\p{L}\\p{N}]';
322322
}
323323

324324
/**

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ configs({ modes: ['ios'] }).forEach(({ title, config }) => {
7474
await verifyInputValues(inputOtp, ['2', '4', '6', '8']);
7575
});
7676

77+
test('should accept Eastern Arabic numerals by default', async ({ page }) => {
78+
await page.setContent(`<ion-input-otp>Description</ion-input-otp>`, config);
79+
80+
const inputOtp = page.locator('ion-input-otp');
81+
const firstInput = page.locator('ion-input-otp input').first();
82+
await firstInput.focus();
83+
84+
await page.keyboard.type('١٢٣٤');
85+
86+
// There is an issue with Playwright automatically flipping the
87+
// values, so we check for the flipped values from above, even though
88+
// it is entered correctly in the component.
89+
await verifyInputValues(inputOtp, ['١', '٢', '٣', '٤']);
90+
});
91+
92+
test('should accept only Western Arabic numerals when pattern is set to [0-9]', async ({ page }) => {
93+
await page.setContent(`<ion-input-otp pattern="[0-9]">Description</ion-input-otp>`, config);
94+
95+
const inputOtp = page.locator('ion-input-otp');
96+
const firstInput = page.locator('ion-input-otp input').first();
97+
await firstInput.focus();
98+
99+
await page.keyboard.type('12٣٤34');
100+
101+
await verifyInputValues(inputOtp, ['1', '2', '3', '4']);
102+
});
103+
77104
test('should accept Latin characters when type is text', async ({ page }) => {
78105
await page.setContent(`<ion-input-otp type="text">Description</ion-input-otp>`, config);
79106

0 commit comments

Comments
 (0)