-
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.
Support turbo-stream[action] on turbo-frames
In parallel with `<turbo-stream action="...">`, this commit adds support for the same rendering operations that Turbo Stream elements support. By default, `<turbo-frame>` elements will render (and have historically been rendering) with the `update` behavior. This commit extends that support to also include the other actions: * `append` will extract the contents out of the response frame and append them into the request frame * `prepend` will extract the contents out of the response frame and append them into the request frame * `replace` will extract the contents out of the response frame, remove the request frame, and inject the extracted contents in its place (conceptually similar to setting `outerHTML`) * `remove` will remove the request frame, and ignore the contents of the response frame * `update` (the default behavior) will extract the contents from the response frame, remove the contents of the request frame, and inject the response frame's contents (conceptually similar to setting `innerHTML`) This will enable behaviors that might have been achievable with `GET`-request powered Turbo Stream responses. For example, in-place pagination could be achieved with `action="prepend"` or `action="append"`: ```html <!-- current HTML --> <turbo-frame id="posts" action="append"> <article id="article_1"><!-- contents --></article> <!-- articles 2-9 --> <article id="article_10"><!-- contents --></article> <a href="/posts?page=2">Next page</a> </turbo-frame> <!-- response HTML --> <turbo-frame id="posts" action="append"> <article id="article_11"><!-- contents --></article> <a href="/posts?page=3">Next page</a> </turbo-frame> <!-- HTML after the request --> <turbo-frame id="posts" action="append"> <article id="article_1"><!-- contents --></article> <!-- articles 2-9 --> <article id="article_10"><!-- contents --></article> <a href="/posts?page=2">Next page</a> <article id="article_11"><!-- contents --></article> <a href="/posts?page=3">Next page</a> </turbo-frame> ``` Through the power of a CSS rules utilizing `:last-of-type`, we can hide the pagination links: ```css a { display: none; } a:last-of-type { display: block; } ```
- Loading branch information
1 parent
57a118e
commit 1b57990
Showing
6 changed files
with
136 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