Skip to content

Commit 6d7066d

Browse files
committed
fix(input-otp): remove reset method, update tabindexes and aria when the value changes
1 parent 2de1519 commit 6d7066d

File tree

7 files changed

+21
-49
lines changed

7 files changed

+21
-49
lines changed

core/api.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ ion-input-otp,prop,shape,"rectangular" | "round" | "soft",'round',false,false
794794
ion-input-otp,prop,size,"large" | "medium" | "small",'medium',false,false
795795
ion-input-otp,prop,type,"number" | "text",'number',false,false
796796
ion-input-otp,prop,value,null | number | string | undefined,'',false,false
797-
ion-input-otp,method,reset,reset() => Promise<void>
798797
ion-input-otp,method,setFocus,setFocus(index?: number) => Promise<void>
799798
ion-input-otp,event,ionBlur,FocusEvent,true
800799
ion-input-otp,event,ionChange,InputOtpChangeEventDetail,true

core/src/components.d.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,10 +1354,6 @@ export namespace Components {
13541354
* If `true`, the user cannot modify the value.
13551355
*/
13561356
"readonly": boolean;
1357-
/**
1358-
* Resets the value and focus state.
1359-
*/
1360-
"reset": () => Promise<void>;
13611357
/**
13621358
* Where separators should be shown between input boxes. Can be a comma-separated string or an array of numbers. For example: `"3"` will show a separator after the 3rd input box. `[1,4]` will show a separator after the 1st and 4th input boxes. `"all"` will show a separator between every input box.
13631359
*/

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,23 +174,6 @@ export class InputOTP implements ComponentInterface {
174174
*/
175175
@Event() ionFocus!: EventEmitter<FocusEvent>;
176176

177-
/**
178-
* Resets the value and focus state.
179-
*/
180-
@Method()
181-
async reset() {
182-
this.value = '';
183-
184-
this.focusedValue = null;
185-
this.hasFocus = false;
186-
187-
this.inputRefs.forEach((input) => {
188-
input.blur();
189-
});
190-
191-
this.updateTabIndexes();
192-
}
193-
194177
/**
195178
* Sets focus to an input box.
196179
* @param index - The index of the input box to focus (0-based).
@@ -211,6 +194,7 @@ export class InputOTP implements ComponentInterface {
211194
@Watch('value')
212195
valueChanged() {
213196
this.initializeValues();
197+
this.updateTabIndexes();
214198
}
215199

216200
/**
@@ -367,7 +351,6 @@ export class InputOTP implements ComponentInterface {
367351
if (newValue.length === length) {
368352
this.ionComplete.emit({ value: newValue });
369353
}
370-
this.updateTabIndexes();
371354
}
372355

373356
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ configs().forEach(({ title, config }) => {
7777
await expect(inputBoxes.nth(3)).toHaveAttribute('aria-hidden', 'true');
7878
});
7979

80+
test('should update aria-hidden when value is set after initialization', async ({ page }) => {
81+
await page.setContent(`<ion-input-otp></ion-input-otp>`, config);
82+
83+
await page.evaluate(() => {
84+
const inputOtp = document.querySelector('ion-input-otp');
85+
if (inputOtp) {
86+
inputOtp.value = '12';
87+
}
88+
});
89+
90+
const inputBoxes = page.locator('ion-input-otp input');
91+
92+
await expect(inputBoxes.nth(0)).toHaveAttribute('aria-hidden', 'false');
93+
await expect(inputBoxes.nth(1)).toHaveAttribute('aria-hidden', 'false');
94+
await expect(inputBoxes.nth(2)).toHaveAttribute('aria-hidden', 'false');
95+
await expect(inputBoxes.nth(3)).toHaveAttribute('aria-hidden', 'true');
96+
});
97+
8098
test('should update aria-label and aria-labelledby when set on host', async ({ page }) => {
8199
await page.setContent(
82100
`<ion-input-otp aria-label="Custom label" aria-labelledby="my-label"></ion-input-otp>`,

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -944,28 +944,4 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
944944
await expect(lastInput).toBeFocused();
945945
});
946946
});
947-
948-
test.describe(title('input-otp: reset method'), () => {
949-
test('should clear all input values and reset focus state', async ({ page }) => {
950-
await page.setContent(`<ion-input-otp value="1234">Description</ion-input-otp>`, config);
951-
952-
const inputOtp = page.locator('ion-input-otp');
953-
const inputBoxes = page.locator('ion-input-otp input');
954-
955-
// Focus an input first
956-
await inputBoxes.nth(2).focus();
957-
await expect(inputBoxes.nth(2)).toBeFocused();
958-
959-
// Call reset
960-
await inputOtp.evaluate((el: HTMLIonInputOtpElement) => {
961-
el.reset();
962-
});
963-
964-
// Check that values are cleared
965-
await verifyInputValues(inputOtp, ['', '', '', '']);
966-
967-
// Check that focus is removed
968-
await expect(inputBoxes.nth(2)).not.toBeFocused();
969-
});
970-
});
971947
});

packages/angular/src/directives/proxies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ This event will not emit when programmatically setting the `value` property.
10191019

10201020
@ProxyCmp({
10211021
inputs: ['autocapitalize', 'color', 'disabled', 'fill', 'inputmode', 'length', 'pattern', 'readonly', 'separators', 'shape', 'size', 'type', 'value'],
1022-
methods: ['reset', 'setFocus']
1022+
methods: ['setFocus']
10231023
})
10241024
@Component({
10251025
selector: 'ion-input-otp',

packages/angular/standalone/src/directives/input-otp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const accessorProvider = {
5454
@ProxyCmp({
5555
defineCustomElementFn: defineCustomElement,
5656
inputs: INPUT_OTP_INPUTS,
57-
methods: ['reset', 'setFocus'],
57+
methods: ['setFocus'],
5858
})
5959
@Component({
6060
selector: 'ion-input-otp',

0 commit comments

Comments
 (0)