Skip to content

Commit ed79f9e

Browse files
committed
fix(toggle): do not announce helper text twice
1 parent db0c7c0 commit ed79f9e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

core/src/components/toggle/test/bottom-content/toggle.e2e.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
2121
await expect(helperText).toHaveText('Helper text');
2222
await expect(errorText).toBeHidden();
2323
});
24-
test('input should have an aria-describedby attribute when helper text is present', async ({ page }) => {
24+
test('toggle should have an aria-describedby attribute when helper text is present', async ({ page }) => {
2525
await page.setContent(`<ion-toggle helper-text="Helper text" error-text="Error text">Label</ion-toggle>`, config);
2626

27-
const input = page.locator('ion-toggle input[type=checkbox]');
27+
const toggle = page.locator('ion-toggle');
2828
const helperText = page.locator('ion-toggle .helper-text');
2929
const helperTextId = await helperText.getAttribute('id');
30-
const ariaDescribedBy = await input.getAttribute('aria-describedby');
30+
const ariaDescribedBy = await toggle.getAttribute('aria-describedby');
3131

3232
expect(ariaDescribedBy).toBe(helperTextId);
3333
});
@@ -44,42 +44,44 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
4444
await expect(errorText).toHaveText('Error text');
4545
});
4646

47-
test('input should have an aria-describedby attribute when error text is present', async ({ page }) => {
47+
test('toggle should have an aria-describedby attribute when error text is present', async ({ page }) => {
4848
await page.setContent(
4949
`<ion-toggle class="ion-invalid ion-touched" helper-text="Helper text" error-text="Error text">Label</ion-toggle>`,
5050
config
5151
);
5252

53-
const input = page.locator('ion-toggle input[type=checkbox]');
53+
const toggle = page.locator('ion-toggle');
5454
const errorText = page.locator('ion-toggle .error-text');
5555
const errorTextId = await errorText.getAttribute('id');
56-
const ariaDescribedBy = await input.getAttribute('aria-describedby');
56+
const ariaDescribedBy = await toggle.getAttribute('aria-describedby');
5757

5858
expect(ariaDescribedBy).toBe(errorTextId);
5959
});
60-
test('input should have aria-invalid attribute when toggle is invalid', async ({ page }) => {
60+
test('toggle should have aria-invalid attribute when toggle is invalid', async ({ page }) => {
6161
await page.setContent(
6262
`<ion-toggle class="ion-invalid ion-touched" helper-text="Helper text" error-text="Error text">Label</ion-toggle>`,
6363
config
6464
);
6565

66-
const input = page.locator('ion-toggle input[type=checkbox]');
66+
const toggle = page.locator('ion-toggle');
6767

68-
await expect(input).toHaveAttribute('aria-invalid');
68+
await expect(toggle).toHaveAttribute('aria-invalid');
6969
});
70-
test('input should not have aria-invalid attribute when toggle is valid', async ({ page }) => {
70+
test('toggle should not have aria-invalid attribute when toggle is valid', async ({ page }) => {
7171
await page.setContent(`<ion-toggle helper-text="Helper text" error-text="Error text">Label</ion-toggle>`, config);
7272

73-
const input = page.locator('ion-toggle input[type=checkbox]');
73+
const toggle = page.locator('ion-toggle');
7474

75-
await expect(input).not.toHaveAttribute('aria-invalid');
75+
await expect(toggle).not.toHaveAttribute('aria-invalid');
7676
});
77-
test('input should not have aria-describedby attribute when no hint or error text is present', async ({ page }) => {
77+
test('toggle should not have aria-describedby attribute when no hint or error text is present', async ({
78+
page,
79+
}) => {
7880
await page.setContent(`<ion-toggle>Label</ion-toggle>`, config);
7981

80-
const input = page.locator('ion-toggle input[type=checkbox]');
82+
const toggle = page.locator('ion-toggle');
8183

82-
await expect(input).not.toHaveAttribute('aria-describedby');
84+
await expect(toggle).not.toHaveAttribute('aria-describedby');
8385
});
8486
});
8587
});

core/src/components/toggle/toggle.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ export class Toggle implements ComponentInterface {
364364

365365
return (
366366
<Host
367+
aria-describedby={this.getHintTextID()}
368+
aria-invalid={this.getHintTextID() === this.errorTextId}
367369
onClick={this.onClick}
368370
class={createColorClasses(color, {
369371
[mode]: true,
@@ -392,8 +394,6 @@ export class Toggle implements ComponentInterface {
392394
onFocus={() => this.onFocus()}
393395
onBlur={() => this.onBlur()}
394396
ref={(focusEl) => (this.focusEl = focusEl)}
395-
aria-describedby={this.getHintTextID()}
396-
aria-invalid={this.getHintTextID() === this.errorTextId}
397397
required={required}
398398
{...this.inheritedAttributes}
399399
/>

0 commit comments

Comments
 (0)