Navigation Submenu: Parent dropdown arrow and submenu container visible on viewports where all children are hidden
Description
This was originally reported on WordPress Core Trac ticket here: https://core.trac.wordpress.org/ticket/64835
When all child items of a core/navigation-submenu block are hidden on a specific viewport block, the parent item still renders its dropdown arrow and submenu container on that viewport.
On further check, it looks like items hidden via "Hide on Desktop/Tablet/Mobile" still emit their full HTML and the hiding is handled purely by CSS via wp-block-hidden-* classes on the child <li>. So $inner_blocks_html is never empty, and $has_submenu is always true regardless of visibility settings.
https://github.com/WordPress/gutenberg/blob/23f840960ebf80b59832a0d724fa1c018e79a186/packages/block-library/src/navigation-submenu/index.php#L89-L93
Step-by-step reproduction instructions
- Create a page with a Navigation block
- Add a submenu parent item
- Add one or more child links inside it
- For each child, click on three dots for block settings > Hide > select all viewport options.
- Save and preview on the front end
Expected: The parent item renders as a plain link with no dropdown arrow and no submenu container, since there are no visible children on any viewport.
Actual: The parent item still shows a dropdown arrow and renders an empty submenu container
Screenshots, screen recording, code snippet
Environment info
- WordPress: 7.1-alpha-62201
- PHP: 8.3.30
- Server: Apache/2.4.66 (Debian)
- Database: mysqli (Server: 11.8.6-MariaDB-ubu2404 / Client: mysqlnd 8.3.30)
- Browser: Chrome 146.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
- Gutenberg 23.1.0-rc.1
- Test Reports 1.2.1
Please confirm that you have searched existing issues in the repo.
- [x] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- [x] Yes
Please confirm which theme type you used for testing.
- [x] Block
- [ ] Classic
- [ ] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
I'm closing this issue per @jeryj's comment on the PR.
I think it's still a valid issue - I just wasn't sure about the fix in #78148. Should we reopen this?
I thought you said, it's too edge casy. I'm fine either way, your call.