Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ export default function ResponsiveWrapper( {
'wp-block-navigation__responsive-container-open',
{ 'always-shown': isHiddenByDefault }
);
const plainMenuClasses = classnames( 'wp-block-navigation__plain-menu', {
'always-shown': isHiddenByDefault,
} );

const modalId = `${ id }-modal`;

const dialogProps = {
className: 'wp-block-navigation__responsive-dialog',
'aria-labelledby': `${ modalId }-title`,
...( isOpen && { role: 'dialog', 'aria-modal': true } ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're adding these attributes dynamically only when the modal is open, do we still need the separate set of markup for when the nav is not in overlay mode? For the front end, could we toggle them in the view script instead?

};

return (
<>
{ ! isOpen && (
<Button
aria-haspopup="true"
aria-expanded={ isOpen }
aria-label={ __( 'Open menu' ) }
aria-label={ __( 'Open navigation menu' ) }
className={ openButtonClasses }
onClick={ () => onToggle( true ) }
>
Expand All @@ -64,6 +72,8 @@ export default function ResponsiveWrapper( {
</Button>
) }

<div className={ plainMenuClasses }>{ children }</div>

<div
className={ responsiveContainerClasses }
style={ styles }
Expand All @@ -73,12 +83,7 @@ export default function ResponsiveWrapper( {
className="wp-block-navigation__responsive-close"
tabIndex="-1"
>
<div
className="wp-block-navigation__responsive-dialog"
role="dialog"
aria-modal="true"
aria-labelledby={ `${ modalId }-title` }
>
<div { ...dialogProps }>
<Button
className="wp-block-navigation__responsive-container-close"
aria-label={ __( 'Close menu' ) }
Expand Down
16 changes: 11 additions & 5 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,17 @@ function render_block_core_navigation( $attributes, $content, $block ) {
'wp-block-navigation__responsive-container-open',
$is_hidden_by_default ? 'always-shown' : '',
);
$plain_menu_classes = array(
'wp-block-navigation__plain-menu',
$is_hidden_by_default ? 'always-shown' : '',
);

$responsive_container_markup = sprintf(
'<button aria-expanded="false" aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="modal-%1$s"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg></button>
'<button aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="modal-%1$s"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg></button>
<div class="%8$s">%2$s</div>
<div class="%5$s" style="%7$s" id="modal-%1$s">
<div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
<div class="wp-block-navigation__responsive-dialog" role="dialog" aria-modal="true" aria-labelledby="modal-%1$s-title" >
<div class="wp-block-navigation__responsive-dialog" role="dialog" aria-modal="true" aria-label="Navigation Menu" >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text change is missing the translation function.

<button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg></button>
<div class="wp-block-navigation__responsive-container-content" id="modal-%1$s-content">
%2$s
Expand All @@ -541,11 +546,12 @@ function render_block_core_navigation( $attributes, $content, $block ) {
</div>',
$modal_unique_id,
$inner_blocks_html,
__( 'Open menu' ), // Open button label.
__( 'Close menu' ), // Close button label.
__( 'Open navigation menu' ), // Open button label.
__( 'Close navigation menu' ), // Close button label.
implode( ' ', $responsive_container_classes ),
implode( ' ', $open_button_classes ),
$colors['overlay_inline_styles']
$colors['overlay_inline_styles'],
implode( ' ', $plain_menu_classes )
);

return sprintf(
Expand Down
25 changes: 20 additions & 5 deletions packages/block-library/src/navigation/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ button.wp-block-navigation-item__content {

.wp-block-navigation__responsive-container-content {
display: flex;
flex-wrap: var(--layout-wrap, wrap);
flex-direction: var(--layout-direction, initial);
justify-content: var(--layout-justify, initial);
align-items: var(--layout-align, initial);
}

// If the responsive wrapper is present but overlay is not open,
Expand Down Expand Up @@ -511,7 +507,6 @@ button.wp-block-navigation-item__content {
@include break-small() {
&:not(.hidden-by-default) {
&:not(.is-menu-open) {
display: block;
width: 100%;
position: relative;
z-index: auto;
Expand Down Expand Up @@ -570,6 +565,26 @@ button.wp-block-navigation-item__content {
}
}

// Show/hide the basic non-modal menu when set to "Mobile".
.wp-block-navigation__plain-menu {
display: none;

&:not(.always-shown) {
@include break-small {
display: flex;
}
}
}

// Both the modal inner container, and the plain menu, should inherit layout properties.
.wp-block-navigation__plain-menu,
.wp-block-navigation__responsive-container .wp-block-navigation__responsive-container-content {
flex-wrap: var(--layout-wrap, wrap);
flex-direction: var(--layout-direction, initial);
justify-content: var(--layout-justify, initial);
align-items: var(--layout-align, initial);
}

// Button to close the menus.
.wp-block-navigation__responsive-container-close {
position: absolute;
Expand Down