-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interactivity API: Support for the data-wp-key
directive
#53844
Interactivity API: Support for the data-wp-key
directive
#53844
Conversation
Size Change: +11 B (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
|
||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! ✅
Flaky tests detected in 5ca3702. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5936029350
|
…ion' into interactivity-api-wp-key-directive
Thanks, David! |
d7c1850
into
add/interactivity-api-regions-based-client-side-navigation
…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>
* 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>
What?
Built on top of #53733 (because it's using
navigate
in the e2e test).This PR adds support for the
data-wp-key
directive, 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
key
for each item to avoid deleting/mutating items unnecessarily.Quoting React docs:
How?
Just take a look at the
data-wp-key
directive and if it exists, assign it to thevnode.key
property.Tasks