-
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.
When a `<turbo-stream>` modifies the document, it has the potential to affect which element has focus. For example, consider an element with an `[id]` that has focus: ```html <label for="an-input"> <input id="an-input" value="an invalid value"> <!-- this element has focus --> ``` Next, consider a `<turbo-stream>` element to replace it: ```html <turbo-stream action="replace" target="an-input"> <template> <input id="an-input" value="an invalid value" class="invalid-input"> </template> </turbo-stream> ``` Prior to this commit, rendering that `<turbo-stream>` would remove the element with focus, and never restore it. After this commit, the `Session` will capture the `[id]` value of the element with focus (if there is any), then "restore" focus to an element in the document with a matching `[id]` attribute _after_ the render. Similarly, consider a `<turbo-stream>` that appends an element with `[autofocus]`: ```html <turbo-stream action="append" targets="body"> <template> <input autofocus> </template> </turbo-stream> ``` Prior to this commit, inserting an `[autofocus]` into the document with a `<turbo-stream>` had no effect. After this commit, the `Session` will scan any `<turbo-stream>` elements its about to render, extracting the first focusable element that declares an `[autofocus]` attribute. Once the rendering is complete, it will attempt to autofocus that element. Several scenarios will prevent that, including: * there aren't any `[autofocus]` elements in the collection of `<turbo-stream>` elements * the `[autofocus]` element does not exist in the document after the rendering is complete * the document already has an element with focus
- Loading branch information
1 parent
2aed8a0
commit a68606d
Showing
7 changed files
with
199 additions
and
18 deletions.
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
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
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
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