Interactivity API: Support for the data-wp-key directive#53844
Merged
luisherranz merged 9 commits intoadd/interactivity-api-regions-based-client-side-navigationfrom Aug 22, 2023
Conversation
21 tasks
|
Size Change: +11 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
juanmaguitar
requested changes
Aug 21, 2023
|
|
||
| Here is the text for the `wp-key` directive description: | ||
|
|
||
| The `wp-key` directive assigns a unique key to an element to help the Interactivity API identify it when iterating through arrays of elements. This becomes important if your array elements can move (e.g. due to sorting), get inserted, or get deleted. A well-chosen key value helps the Interactivity API infer what exactly has changed in the array, allowing it to make the correct updates to the DOM. |
Contributor
There was a problem hiding this comment.
This becomes important if your array elements can move (e.g. due to sorting), get inserted, or get deleted.
Is there any example we can add here to understand better the value of data-wp-key? I mean, some example that actually rearranges elements, insert them or remove them where having a key is essential.
Member
Author
There was a problem hiding this comment.
juanmaguitar
approved these changes
Aug 21, 2023
|
Flaky tests detected in 5ca3702. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5936029350
|
…ion' into interactivity-api-wp-key-directive
Member
Author
|
Thanks, David! |
d7c1850
into
add/interactivity-api-regions-based-client-side-navigation
DAreRodz
added a commit
that referenced
this pull request
Aug 28, 2023
…53733) * Add router with region-based client-side navigation * Add changelog * Interactivity API: merge new server-side rendered context on client-side navigation (#53853) * Add failing test * Fix the test * Add changelog * Fix lint error * Fix changelog placement * Interactivity API: Support for the `data-wp-key` directive (#53844) * Add failing test * Fix test using key * Replace key with data-wp-key * Refactor test a bit * Add changelog * Add docs * Remove unnecessary paragraph * Fix lint error * Interactivity API: Fix non stable context reference on client side navigation (#53876) * Add failing test * Fix the test * Refactor addPostWithBlock util * Add tests for router regions --------- Co-authored-by: David Arenas <david.arenas@automattic.com>
DAreRodz
added a commit
that referenced
this pull request
Aug 29, 2023
* Add router with region-based client-side navigation * Add changelog * Initial version working * Only add supports.interactivity and enqueue the view.js file if the "Enhanced Pagination" option is enabled * Interactivity API: merge new server-side rendered context on client-side navigation (#53853) * Add failing test * Fix the test * Add changelog * Fix lint error * Fix changelog placement * Interactivity API: Support for the `data-wp-key` directive (#53844) * Add failing test * Fix test using key * Replace key with data-wp-key * Refactor test a bit * Add changelog * Add docs * Remove unnecessary paragraph * Fix lint error * Interactivity API: Fix non stable context reference on client side navigation (#53876) * Add failing test * Fix the test * Add basic accessibility (announcement + focus) * Add basic loading animation Co-authored-by: David Arenas <darerodz@users.noreply.github.com> * Only enqueue styles if they are needed * Add missing CSS props on aria-live element Apparently, some screen readers don't read elements that don't have width and height. * Fix two typos * Update fixture * Simplify loaded text * Move navigation announce style to a class --------- Co-authored-by: David Arenas <darerodz@users.noreply.github.com> Co-authored-by: David Arenas <david.arenas@automattic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Built on top of #53733 (because it's using
navigatein the e2e test).This PR adds support for the
data-wp-keydirective, which is basically (P)React'skey, but using a valid HTML attribute.Why?
Because any framework that wants to modify a list of elements in the DOM needs to have a unique
keyfor each item to avoid deleting/mutating items unnecessarily.Quoting React docs:
How?
Just take a look at the
data-wp-keydirective and if it exists, assign it to thevnode.keyproperty.Tasks