Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/src/components/alert/alert-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface AlertButton {
role?: 'cancel' | 'destructive' | string;
cssClass?: string | string[];
id?: string;
htmlAttributes?: { [key: string]: any };
// TODO(FW-2832): type
handler?: (value: any) => AlertButtonOverlayHandler | Promise<AlertButtonOverlayHandler>;
}
1 change: 1 addition & 0 deletions core/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export class Alert implements ComponentInterface, OverlayInterface {
<div class={alertButtonGroupClass}>
{buttons.map((button) => (
<button
{...button.htmlAttributes}
type="button"
id={button.id}
class={buttonClass(button)}
Expand Down
16 changes: 16 additions & 0 deletions core/src/components/alert/test/a11y/alert.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,21 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
test('should allow for manually specifying aria attributes', async ({ page }) => {
await testAria(page, 'customAria', 'Custom title', 'Custom description');
});

test('should have aria-labelledby and aria-label added to the button when htmlAttributes is set', async ({
page,
}) => {
const didPresent = await page.spyOnEvent('ionAlertDidPresent');

const button = page.locator('#ariaLabelButton');
await button.click();

await didPresent.next();

const alertButton = page.locator('ion-alert .alert-button');

await expect(alertButton).toHaveAttribute('aria-labelledby', 'close-label');
await expect(alertButton).toHaveAttribute('aria-label', 'close button');
});
});
});
18 changes: 18 additions & 0 deletions core/src/components/alert/test/a11y/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h1>Alert - A11y</h1>
<ion-button id="noHeaders" expand="block" onclick="presentNoHeaders()">No Headers</ion-button>
<ion-button id="noMessage" expand="block" onclick="presentNoMessage()">No Message</ion-button>
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button>
<ion-button id="ariaLabelButton" expand="block" onclick="presentAriaLabelButton()">Aria Label Button</ion-button>
</main>

<script>
Expand Down Expand Up @@ -76,6 +77,23 @@ <h1>Alert - A11y</h1>
},
});
}

function presentAriaLabelButton() {
openAlert({
header: 'Header',
subHeader: 'Subtitle',
message: 'This is an alert message with custom aria attributes passed to the button.',
buttons: [
{
text: 'Close',
htmlAttributes: {
'aria-label': 'close button',
'aria-labelledby': 'close-label',
},
},
],
});
}
</script>
</body>
</html>