Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aria-label attribute to navigation block only when it is open #54816

Merged
merged 5 commits into from
Oct 10, 2023
Merged
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
1 change: 0 additions & 1 deletion packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,6 @@ function Navigation( {
<ResponsiveWrapper
id={ clientId }
onToggle={ setResponsiveMenuVisibility }
label={ __( 'Menu' ) }
hasIcon={ hasIcon }
icon={ icon }
isOpen={ isResponsiveMenuOpen }
Expand Down
25 changes: 19 additions & 6 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,22 @@ function render_block_core_navigation( $attributes, $content, $block ) {
$responsive_dialog_directives = '';
$close_button_directives = '';
if ( $should_load_view_script ) {
$nav_element_context = wp_json_encode(
array(
'core' => array(
'navigation' => array(
'overlayOpenedBy' => array(),
'type' => 'overlay',
'roleAttribute' => '',
'ariaLabel' => __( 'Menu' ),
),
),
),
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
);
$nav_element_directives = '
data-wp-interactive
data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\'
data-wp-context=\'' . $nav_element_context . '\'
';
$open_button_directives = '
data-wp-on--click="actions.core.navigation.openMenuOnClick"
Expand All @@ -714,6 +727,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
';
$responsive_dialog_directives = '
data-wp-bind--aria-modal="selectors.core.navigation.ariaModal"
data-wp-bind--aria-label="selectors.core.navigation.ariaLabel"
data-wp-bind--role="selectors.core.navigation.roleAttribute"
data-wp-effect="effects.core.navigation.focusFirstElement"
';
Expand All @@ -723,11 +737,11 @@ function render_block_core_navigation( $attributes, $content, $block ) {
}

$responsive_container_markup = sprintf(
'<button aria-haspopup="true" %3$s class="%6$s" %11$s>%9$s</button>
<div class="%5$s" style="%7$s" id="%1$s" %12$s>
'<button aria-haspopup="true" %3$s class="%6$s" %10$s>%8$s</button>
<div class="%5$s" style="%7$s" id="%1$s" %11$s>
<div class="wp-block-navigation__responsive-close" tabindex="-1">
<div class="wp-block-navigation__responsive-dialog" aria-label="%8$s" %13$s>
<button %4$s class="wp-block-navigation__responsive-container-close" %14$s>%10$s</button>
<div class="wp-block-navigation__responsive-dialog" %12$s>
<button %4$s class="wp-block-navigation__responsive-container-close" %13$s>%9$s</button>
<div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
%2$s
</div>
Expand All @@ -741,7 +755,6 @@ function render_block_core_navigation( $attributes, $content, $block ) {
esc_attr( implode( ' ', $responsive_container_classes ) ),
esc_attr( implode( ' ', $open_button_classes ) ),
esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) ),
__( 'Menu' ),
$toggle_button_content,
$toggle_close_button_content,
$open_button_directives,
Expand Down
7 changes: 7 additions & 0 deletions packages/block-library/src/navigation/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ wpStore( {
? 'true'
: null;
},
ariaLabel: ( store ) => {
const { context, selectors } = store;
return context.core.navigation.type === 'overlay' &&
selectors.core.navigation.isMenuOpen( store )
? context.core.navigation.ariaLabel
: null;
},
isMenuOpen: ( { context } ) =>
// The menu is opened if either `click`, `hover` or `focus` is true.
Object.values(
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function render_block_core_query( $attributes, $content, $block ) {
'loadedText' => __( 'Page Loaded.' ),
),
),
)
),
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
)
);
$content = $p->get_updated_html();
Expand Down
Loading