Skip to content

Commit

Permalink
fix(alert): focus first button when alert opens
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney committed Oct 7, 2024
1 parent 9f30b79 commit 18877e0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion core/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,34 @@ export class Alert implements ComponentInterface, OverlayInterface {

await this.delegateController.attachViewToDom();

await present(this, 'alertEnter', iosEnterAnimation, mdEnterAnimation);
const ariaDescribedBy = this.el.getAttribute('aria-describedby');
const ariaLabelledBy = this.el.getAttribute('aria-labelledby');

if (ariaDescribedBy) {
this.el.removeAttribute('aria-describedby');
}

if (ariaLabelledBy) {
this.el.removeAttribute('aria-labelledby');
}

await present(this, 'alertEnter', iosEnterAnimation, mdEnterAnimation).then(() => {
const firstButton =
this.el.querySelector<HTMLElement>('.alert-button-role-cancel') ||
this.el.querySelector<HTMLElement>('.alert-button');

if (firstButton) {
firstButton.focus();
}

if (ariaDescribedBy) {
this.el.setAttribute('aria-describedby', ariaDescribedBy);
}

if (ariaLabelledBy) {
this.el.setAttribute('aria-labelledby', ariaLabelledBy);
}
});

unlock();
}
Expand Down

0 comments on commit 18877e0

Please sign in to comment.