From b73c187bde319bed0cf023c1fe3b86b4a8f23973 Mon Sep 17 00:00:00 2001 From: Utsav Patel Date: Tue, 12 Nov 2024 23:14:11 +0530 Subject: [PATCH] feature: created text control to specify other navigation accessible name --- .../block-library/src/navigation/block.json | 4 +++ .../src/navigation/edit/index.js | 5 ++- .../edit/navigation-menu-name-control.js | 34 ++++++++++++++----- .../block-library/src/navigation/index.php | 15 ++++---- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index c65e0c6224616e..6418cf3800882d 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -84,6 +84,10 @@ "templateLock": { "type": [ "string", "boolean" ], "enum": [ "all", "insert", "contentOnly", false ] + }, + "accessibleMenuName": { + "type": "string", + "default": "" } }, "providesContext": { diff --git a/packages/block-library/src/navigation/edit/index.js b/packages/block-library/src/navigation/edit/index.js index ae7dd60bd0c5ba..3b70927d24842a 100644 --- a/packages/block-library/src/navigation/edit/index.js +++ b/packages/block-library/src/navigation/edit/index.js @@ -870,7 +870,10 @@ function Navigation( { { hasResolvedCanUserUpdateNavigationMenu && canUserUpdateNavigationMenu && ( - + ) } { hasResolvedCanUserDeleteNavigationMenu && canUserDeleteNavigationMenu && ( diff --git a/packages/block-library/src/navigation/edit/navigation-menu-name-control.js b/packages/block-library/src/navigation/edit/navigation-menu-name-control.js index db895b0b644aac..3b3d5b23345d82 100644 --- a/packages/block-library/src/navigation/edit/navigation-menu-name-control.js +++ b/packages/block-library/src/navigation/edit/navigation-menu-name-control.js @@ -5,20 +5,38 @@ import { TextControl } from '@wordpress/components'; import { useEntityProp } from '@wordpress/core-data'; import { __ } from '@wordpress/i18n'; -export default function NavigationMenuNameControl() { +export default function NavigationMenuNameControl( { + attributes, + setAttributes, +} ) { const [ title, updateTitle ] = useEntityProp( 'postType', 'wp_navigation', 'title' ); + const { accessibleMenuName } = attributes; + return ( - + <> + + { + setAttributes( { + accessibleMenuName: newAccessibleMenuName, + } ); + } } + /> + ); } diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 9484ad13ed002a..2f012b2fbae565 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -558,16 +558,17 @@ private static function get_responsive_container_markup( $attributes, $inner_blo * @return string Returns the navigation block markup. */ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) { - $nav_menu_name = static::get_unique_navigation_name( $attributes ); - $is_interactive = static::is_interactive( $attributes, $inner_blocks ); - $is_responsive_menu = static::is_responsive( $attributes ); - $style = static::get_styles( $attributes ); - $class = static::get_classes( $attributes ); - $wrapper_attributes = get_block_wrapper_attributes( + $nav_menu_name = static::get_unique_navigation_name( $attributes ); + $accessible_menu_name = ( ! empty( $attributes['accessibleMenuName'] ) ) ? $attributes['accessibleMenuName'] : $nav_menu_name; + $is_interactive = static::is_interactive( $attributes, $inner_blocks ); + $is_responsive_menu = static::is_responsive( $attributes ); + $style = static::get_styles( $attributes ); + $class = static::get_classes( $attributes ); + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class, 'style' => $style, - 'aria-label' => $nav_menu_name, + 'aria-label' => $accessible_menu_name, ) );