Add client-side navigation block with interactive features#76331
Add client-side navigation block with interactive features#76331juanmaguitar merged 3 commits intotrunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
Size Change: 0 B Total Size: 6.89 MB ℹ️ View Unchanged
|
...create-block-interactive-template/block-templates-client-side-navigation/render.php.mustache
Outdated
Show resolved
Hide resolved
...create-block-interactive-template/block-templates-client-side-navigation/render.php.mustache
Outdated
Show resolved
Hide resolved
…, change ref for attributes, add artificial delay and delete an unnecessary withScope.
There was a problem hiding this comment.
Looks good.
@wordpress/interactivity-routeris missing as a dependency. (Fixed in 04215ff.)
...es/create-block-interactive-template/block-templates-client-side-navigation/view.js.mustache
Outdated
Show resolved
Hide resolved
...es/create-block-interactive-template/block-templates-client-side-navigation/view.js.mustache
Outdated
Show resolved
Hide resolved
|
I think it's looking pretty good. I've added a few things:
|
|
Flaky tests detected in 04215ff. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22891178400
|
|
@DAreRodz @luisherranz thanks for your feedback and your code improvements. |
|
@DAreRodz, could you take a look at the |
This case is pretty simple and maintains the HTML structure between navigations, so I see everything fine regarding |
DAreRodz
left a comment
There was a problem hiding this comment.
Codewise, looks good to me. I tested the generated output with the following command on the PR's branch:
npx wp-create-block --template @wordpress/create-block-interactive-template --variant client-side-navigation
The block is correctly generated and works as expected when installed in a WordPress site.
Thanks, @juanmaguitar!
|
@copilot, could you update this section of the client-side navigation guide to use this variant? EDIT, trying this: https://github.com/WordPress/gutenberg/tasks/17da34c7-6620-40b8-9d00-b49c26a66edb |
What?
Closes #76313
Adds a
client-side-navigationvariant to@wordpress/create-block-interactive-template.Why?
Client-side navigation is one of the most impactful features of the Interactivity API, yet there is currently no scaffolding starting point for it.
This variant provides a self-contained, working example that mirrors real-world patterns (query-param navigation for pagination, search results, filtered archives) and works immediately after scaffolding with no posts or setup required.
How?
Adds a new variant with its own dedicated block template directory (
block-templates-client-side-navigation/), since the files diverge significantly from the existing theme-switcher example.Key Interactivity API patterns demonstrated:
data-wp-router-region— marks the swappable content areadata-wp-key— on the quote container to avoid DOM flickerwithSyncEvent+ generator function + dynamicimport('@wordpress/interactivity-router')— following core blocks patternwithScope+setInterval— stopwatch outside the router region proving state persistenceFiles added
block-templates-client-side-navigation/render.php.mustacheblock-templates-client-side-navigation/view.js.mustacheblock-templates-client-side-navigation/edit.js.mustacheblock-templates-client-side-navigation/index.js.mustacheblock-templates-client-side-navigation/style.scss.mustacheblock-templates-client-side-navigation/editor.scss.mustacheblock-templates-client-side-navigation/README.md.mustacheFiles modified
index.js— Addedclient-side-navigationvariant with its ownblockTemplatesPath.Testing Instructions
?quote=3— verify the correct quote renders server-side.npx @wordpress/create-block@latest --template /path/to/gutenberg/packages/create-block-interactive-template # Should prompt with: default, typescript, client-side-navigationTesting Instructions for Keyboard
<a>elements, so they work as normal links when JS is unavailable.