Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore focus when transposing Permanent Elements
Problem --- When an interactive element like an `<input>`, `<select>`, `<textarea>`, or `<button>` has an `[id]` attribute and is marked as `[data-turbo-permanent]`, the element and its internal state is preserved _except_ for its focus state. Imagine a search form: ```html <form> <label for="search">Search</label> <input type="search" id="search" name="q" data-turbo-permanent> </form> ``` When typing a query into the box and submitting the `<form>` by <kbd>enter</kbd>, the request is submitted, the page transitions, the element retains its `[value]` attribute, but focus is lost. Solution --- When transposing a permanent element during a `Renderer` descendant's (e.g. [PageRenderer](./src/core/drive/page_renderer.ts), [ErrorRenderer](./src/core/drive/error_renderer.ts), or [FrameRenderer](./src/core/frames/frame_renderer.ts)) render cycle, capture the `document.activeElement`. Once the permanent element is inserted into the new page, use that retained reference to re-focus the element.
- Loading branch information
1 parent
933419b
commit 347a0b0
Showing
11 changed files
with
119 additions
and
14 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
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