From c9a28447e2204a861505157db703688ee6a6e4d6 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 26 Sep 2023 10:25:21 +0200 Subject: [PATCH 1/5] Add `aria-label` only when is open --- packages/block-library/src/navigation/index.php | 12 ++++++------ packages/block-library/src/navigation/view.js | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index a07235b601abb..2edcd268d6fb2 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -698,7 +698,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { if ( $should_load_view_script ) { $nav_element_directives = ' data-wp-interactive - data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\' + data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "", "ariaLabel": "' . __( 'Menu' ) . '" } } }\' '; $open_button_directives = ' data-wp-on--click="actions.core.navigation.openMenuOnClick" @@ -714,6 +714,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" '; @@ -723,11 +724,11 @@ function render_block_core_navigation( $attributes, $content, $block ) { } $responsive_container_markup = sprintf( - ' -
+ ' +
-
- +
+
%2$s
@@ -741,7 +742,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, diff --git a/packages/block-library/src/navigation/view.js b/packages/block-library/src/navigation/view.js index 6a8e4979983b8..c0853b2814e2b 100644 --- a/packages/block-library/src/navigation/view.js +++ b/packages/block-library/src/navigation/view.js @@ -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( From c6b4038b6600f044d9104b46899ea1bfc11a7b3c Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Tue, 26 Sep 2023 10:25:43 +0200 Subject: [PATCH 2/5] Remove unnecessary `label` property in edit --- packages/block-library/src/navigation/edit/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index 483e8abaab24f..7dc77e7ddcdfb 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -875,7 +875,6 @@ function Navigation( { Date: Tue, 3 Oct 2023 17:09:32 +0200 Subject: [PATCH 3/5] Escape translation --- packages/block-library/src/navigation/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 2edcd268d6fb2..cba5d388fbc0e 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -698,7 +698,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { if ( $should_load_view_script ) { $nav_element_directives = ' data-wp-interactive - data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "", "ariaLabel": "' . __( 'Menu' ) . '" } } }\' + data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "", "ariaLabel": "' . esc_attr__( 'Menu' ) . '" } } }\' '; $open_button_directives = ' data-wp-on--click="actions.core.navigation.openMenuOnClick" From 2fce145da20b84188dfe0dd806e441aba050e89b Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Wed, 4 Oct 2023 16:30:48 +0200 Subject: [PATCH 4/5] Move navigation context to `wp_json_encode` --- packages/block-library/src/navigation/index.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index cba5d388fbc0e..3609fc98a5b2a 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -696,9 +696,21 @@ 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' ), + ), + ), + ) + ); $nav_element_directives = ' data-wp-interactive - data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "", "ariaLabel": "' . esc_attr__( 'Menu' ) . '" } } }\' + data-wp-context=\'' . $nav_element_context . '\' '; $open_button_directives = ' data-wp-on--click="actions.core.navigation.openMenuOnClick" From b8f157db67178e90befb2667fb68462d76fd2d35 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Fri, 6 Oct 2023 11:48:07 +0200 Subject: [PATCH 5/5] Add `wp_json_encode` flags --- packages/block-library/src/navigation/index.php | 3 ++- packages/block-library/src/query/index.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 3609fc98a5b2a..c4854fbc4b26d 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -706,7 +706,8 @@ function render_block_core_navigation( $attributes, $content, $block ) { 'ariaLabel' => __( 'Menu' ), ), ), - ) + ), + JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP ); $nav_element_directives = ' data-wp-interactive diff --git a/packages/block-library/src/query/index.php b/packages/block-library/src/query/index.php index c35bf2ba00af2..1b05e9c92c95e 100644 --- a/packages/block-library/src/query/index.php +++ b/packages/block-library/src/query/index.php @@ -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();