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.
|
$inner_blocks_html = ''; |
|
foreach ( $block->inner_blocks as $inner_block ) { |
|
$inner_blocks_html .= $inner_block->render(); |
|
} |
|
$has_submenu = ! empty( trim( $inner_blocks_html ) ); |
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.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
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-submenublock 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_htmlis never empty, and$has_submenuis alwaystrueregardless of visibility settings.gutenberg/packages/block-library/src/navigation-submenu/index.php
Lines 89 to 93 in 23f8409
Step-by-step reproduction instructions
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
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.