This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Description
|
function autofocus(el: DetailsDialogElement): void { |
|
let autofocusElement = Array.from(el.querySelectorAll<HTMLElement>('[autofocus]')).filter(focusable)[0] |
|
if (!autofocusElement) { |
|
autofocusElement = el |
|
el.setAttribute('tabindex', '-1') |
|
} |
|
autofocusElement.focus() |
|
} |
Initial focus should be set to the first focusable element instead of the dialog element.
@jscholes: Placing focus on the close button is the correct behaviour if the dialog has an accessible name via aria-label or aria-labelledby, which every dialog should. So a screen reader will announce the name, the role of dialog, then the close button.
The focus priority should be as follows:
- element with [autofocus]
- first focusable element if it's in the beginning of the dialog (usually the close button)
- first element