Skip to content

Commit

Permalink
feature: created text control to specify other navigation accessible …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
up1512001 committed Nov 12, 2024
1 parent d2bc9ea commit b73c187
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
},
"accessibleMenuName": {
"type": "string",
"default": ""
}
},
"providesContext": {
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,10 @@ function Navigation( {
<InspectorControls group="advanced">
{ hasResolvedCanUserUpdateNavigationMenu &&
canUserUpdateNavigationMenu && (
<NavigationMenuNameControl />
<NavigationMenuNameControl
attributes={ attributes }
setAttributes={ setAttributes }
/>
) }
{ hasResolvedCanUserDeleteNavigationMenu &&
canUserDeleteNavigationMenu && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Menu name' ) }
value={ title }
onChange={ updateTitle }
/>
<>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Menu name' ) }
value={ title }
onChange={ updateTitle }
/>
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label={ __( 'Accessible menu name' ) }
value={ accessibleMenuName }
onChange={ ( newAccessibleMenuName ) => {
setAttributes( {
accessibleMenuName: newAccessibleMenuName,
} );
} }
/>
</>
);
}
15 changes: 8 additions & 7 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
);

Expand Down

0 comments on commit b73c187

Please sign in to comment.