Repository navigation
Conversation
| `(max-width: ${ mobileBreakpoint })` | ||
| ); | ||
|
|
||
| console.log( { mobileBreakpoint, isMobileBreakPoint } ); |
|
@mikachan From a Theming perspective would you see this feature as being valuable? Every time I create a theme I"m frustrated by not being able to properly control the Navigation block breakpoint. I assume you've run into this also? |
|
Size Change: +1.26 kB (+0.02%) Total Size: 7.73 MB 📦 View Changed
|
Yes, I think this would be extremely valuable. I love the idea of being able to control the Navigation block breakpoint from the UI. Your video looks promising! Going forward, I wonder if this custom breakpoint should be at a higher level so it can impact more blocks. I really love using intrinsic design but there are some cases (like the Navigation block) where the best solution is probably to use a breakpoint, so it would be great to enable this for more blocks. Perhaps the custom breakpoints could eventually replace the |
|
Yes I agree. I suggest we roll out to the Nav block and then if appetite grows we can consider if/how we extend this outwards to become a system wide tool. I can see other blocks (e.g. Columns) needing something similar to determine when to "stack on mobile" for example. |
|
I don't think we should be having user set this value. Can we leverage container queries to do it automatically based on space? |
|
Yeh I did consider taking a look at that. I appreciate we want to go for intrinsic design principles. I may not have fully groked container queries but as I understand it you can query the width of the parent container and then adjust accordingly. However in Navigaiton blocks we care about switching out an entire layout to "mobile" mode based on the number of items in the Navigation itself. As an example:
If there's a way of solving that (without resorting to JavaScript "measuring" the width of the Nav items) which I have missed then I'd be happy to look into it. |
|
I've had a think about this and left some alternative suggestions under |
|
Great solution, it's really required! |
|
Hey :) everyone. Must have. We are already in the future and screens of any size can be an electronic canvas. This is just obvious and should be a standard principle in Gutenberg. |
|
If you would like to see the PR land then please leave a 👍 emoji on this comment. |
|
Just came across this and would love to get a solution for this! |
|
replicated to this issue |
|
We proposed an alternative to this here: #57587 any feedback is welcome |
|
Hello everyone It would be great with some kind of update or link to an open issue/PR that took over for this PR. Thank you. |
|
We started to explore various ideas in this Discussion @MaggieCabrera look at container queries and also dynamically adjusting the layout based on various heuristics but they all fell short. |
bee7f93 to
ccfeb92
Compare
There was a problem hiding this comment.
Pull request overview
Adds a configurable overlayBreakpoint attribute to the Navigation block so the “mobile overlay vs inline items” switch can happen at a user-selected viewport width, while keeping the existing 600px default behavior unchanged unless explicitly customized.
Changes:
- Introduces
overlayBreakpoint(default600px) across block schema, editor UI, and server rendering, with validation/normalization forpx|em|rem. - Adds editor UI controls (UnitControl + reset) and editor-preview behavior for custom breakpoints.
- Emits instance-scoped frontend CSS (via style engine) only for valid, non-default custom breakpoints; updates docs and adds JS/PHP test coverage.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/eslint/suppressions.json | Removes a now-unneeded lint suppression for the overlay panel implementation. |
| phpunit/blocks/render-block-navigation-test.php | Adds PHPUnit coverage for default/custom/invalid overlay breakpoint behavior and scoped CSS emission. |
| packages/block-library/src/navigation/style.scss | Keeps static break-small() rules for non-custom blocks; custom blocks opt out and rely on scoped rules. |
| packages/block-library/src/navigation/README.md | Documents the new overlayBreakpoint attribute. |
| packages/block-library/src/navigation/index.php | Adds breakpoint constants + validation; adds custom-breakpoint classing and instance-scoped CSS rules. |
| packages/block-library/src/navigation/edit/utils.js | Adds editor-side breakpoint normalization and “has custom” helpers. |
| packages/block-library/src/navigation/edit/test/utils.js | Adds unit tests for breakpoint normalization + custom detection. |
| packages/block-library/src/navigation/edit/test/responsive-wrapper.js | Adds tests for editor preview behavior tied to custom breakpoint matching. |
| packages/block-library/src/navigation/edit/test/overlay-panel.js | Adds tests for overlay breakpoint control UI behavior (units, reset, invalid fallback, visibility). |
| packages/block-library/src/navigation/edit/responsive-wrapper.js | Adds useMediaQuery-based editor preview state for custom breakpoints. |
| packages/block-library/src/navigation/edit/overlay-visibility-control.js | Updates the overlay visibility help text. |
| packages/block-library/src/navigation/edit/overlay-panel.js | Adds the overlay breakpoint UnitControl + reset button and wiring to attributes. |
| packages/block-library/src/navigation/edit/index.js | Wires the new attribute into editor rendering + passes derived props to children. |
| packages/block-library/src/navigation/constants.js | Adds default breakpoint + unit definitions for the UnitControl. |
| packages/block-library/src/navigation/block.json | Adds the new attribute schema/default. |
| docs/reference-guides/core-blocks/README.md | Updates the Navigation block attribute list to include overlayBreakpoint. |
| const handleOverlayBreakpointChange = ( nextValue ) => { | ||
| setAttributes( { | ||
| overlayBreakpoint: normalizeOverlayBreakpoint( nextValue ), | ||
| } ); | ||
| }; |
4e43603 to
4171bfe
Compare
|
@talldan This is not targeting 7.1 so not urgent, but with your experience of Navigation and the recent work on responsive controls I'd love to get your expertise here 🙇 |
What is this part referring to?
Just my opinion, but I think it would be better if there were something that works more in tune with responsive editing/styles. At least to begin with. Otherwise users might be confused that there's a special third breakpoint that only the nav block has, and one that's hard to view precisely. Also that there are systems that work differently. After #79104 custom theme.json breakpoint values are supported for mobile/tablet, in the future that might be more extensible with completely custom breakpoints, so it might be good to keep overlay visibility more aligned with the future of themes. Maybe a place to start for now is by supporting 'Tablet' as a value for the overlay (it could support the same breakpoints that theme.json provides). After that it might be possible to surface the controls as a toggle when 'Responsive styles' is active, similar to what's being explored for block visibility in #79995. Maybe it's possible to follow the same pattern as that PR (if we can decide on something), since the two features have similar values (off, set to breakpoint(s), or always on).
To me, it doesn't matter if the values are stored differently behind the scenes, it's more a matter of surfacing the most useful controls when 'Responsive styles' is active. |
|
@talldan Thanks for the feedback. I'll review this carefully now. I also realised that as the breakpoint is heavily content dependent, it might be necessary to save different values for different languages in multi-lingual setups. Given the menu item data comes from |
Drop the "Internal dependencies" banner comment in navigation edit utils.js to match the rest of the package, and remove a stale suppressions.json entry for overlay-panel.jsx that no longer applies. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4171bfe to
1fbdda7
Compare
🤖 PR meta 🤖🎉 PropsUnlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @sinanisler. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +1.29 kB (+0.01%) Total Size: 8.66 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded in
|
What
Adds an
overlayBreakpointattribute to the Navigation block so the responsive overlay can switch between the collapsed menu button and inline navigation items at a user-configured viewport width.This is a major refresh of the earlier PR direction. The PR had gone stale, so the implementation has been updated to fit the current Navigation block overlay architecture and the newer patterns now present in
trunk.Why
The Navigation block currently uses a fixed breakpoint for its mobile overlay behavior. That can be too limiting for themes and layouts where navigation needs to collapse earlier or later depending on available space, typography, item count, or design requirements.
How
overlayBreakpointblock attribute with a default of600px.px,em, andremvalues, including decimal values.FAQs
Why 600px?
600pxis the breakpoint Navigation already uses today through WordPress's small breakpoint, not a new design decision introduced by this PR.packages/base-styles/_breakpoints.scss:12defines$break-small: 600px.packages/base-styles/_mixins.scss:118exposes that value asbreak-small().Why not automate this?
Two automation routes were explored before returning to an explicit breakpoint control:
Those routes did not give us a robust enough solution for this PR:
X, switch layout." They do not automatically know when the Navigation block's inline items no longer fit.Xis content-dependent. It changes with the number of menu items, label length, font size, spacing, submenu indicators, and translations. A threshold that works for one Navigation instance can be wrong for another instance in the same theme.automode because CSS/container queries could not answer the actual question: "do these navigation items still fit in this layout right now?" That route required measurement heuristics across both Navigation items and parent containers.How does this relate to the WordPress 7.1 responsive styling system?
@mobileand@tablet. Those states are driven bysettings.viewport.mobileandsettings.viewport.tablet.overlayBreakpointis not a responsive style state. It is a Navigation-block behavior setting that controls when one Navigation block switches between inline items and the overlay menu button.settings.viewportdoes not automatically change a Navigation block'soverlayBreakpoint, and changingoverlayBreakpointdoes not redefine the site's@mobileor@tabletstyle breakpoints.overlayBreakpointcontrols when the overlay behavior starts.Testing Instructions
720px,37.5em, or48rem.600pxbreakpoint still behaves as before.npm run test:unit packages/block-library/src/navigation/edit/test.vendor/bin/phpunit phpunit/blocks/render-block-navigation-test.php.