-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not autofocus inert or hidden elements
Closes [#546][] According to the specification, there is an [algorithm][] for determining the [focusable area][], that is, the elements with the `[autofocus]` attribute that can receive focus: > Elements that meet all the following criteria: > * the element's [tabindex][] value is non-null, or the element is determined by the user agent to be focusable; > * the element is either not a shadow host, or has a shadow root whose delegates focus is false; > * the element is not actually [disabled][]; > * the element is not [inert][]; > * the element is either being rendered or being used as relevant canvas fallback content. This commit extends the `Snapshot.firstAutofocusableElement` to programmatically determine the focusable area based on the available attributes, including checks for `<details>` and `<dialog>` ancestors that do not declare `[open]`. [#546]: #546 [tabindex]: https://html.spec.whatwg.org/multipage/interaction.html#tabindex-value [algorithm]: https://html.spec.whatwg.org/multipage/interaction.html#get-the-focusable-area [disabled]: https://html.spec.whatwg.org/multipage/semantics-other.html#concept-element-disabled [inert]: https://html.spec.whatwg.org/multipage/interaction.html#inert [focusable area]: https://html.spec.whatwg.org/multipage/interaction.html#focusable-area [hidden]: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden
- Loading branch information
1 parent
1563ebb
commit 8d36ac5
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Autofocus</title> | ||
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script> | ||
<script src="/src/tests/fixtures/test.js"></script> | ||
</head> | ||
<body> | ||
<h1>Autofocus With Inert Elements</h1> | ||
<dialog> | ||
<button id="dialog-autofocus-element" autofocus>dialog[autofocus]</button> | ||
</dialog> | ||
<details> | ||
<button id="details-autofocus-element" autofocus>details[autofocus]</button> | ||
</details> | ||
<div hidden> | ||
<button id="hidden-autofocus-element" autofocus>div[hidden][autofocus]</button> | ||
</div> | ||
<div inert> | ||
<button id="inert-autofocus-element" autofocus>div[inert][autofocus]</button> | ||
</div> | ||
<button id="disabled-autofocus-element" disabled autofocus>button[disabled][autofocus]</button> | ||
<form disabled> | ||
<button id="visible-autofocus-element" autofocus>button[autofocus]</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters