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

Navigation: Fix 'ariaLabel' block support #66943

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht
- **Category:** theme
- **Allowed Blocks:** core/navigation-link, core/search, core/social-links, core/page-list, core/spacer, core/home-link, core/site-title, core/site-logo, core/navigation-submenu, core/loginout, core/buttons
- **Supports:** align (full, wide), ariaLabel, inserter, interactivity, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~, ~~renaming~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor
- **Attributes:** __unstableLocation, accessibleMenuName, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link

Expand Down
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": {
up1512001 marked this conversation as resolved.
Show resolved Hide resolved
"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
Loading