Skip to content

Commit

Permalink
update: added early return if ariaLabel is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
up1512001 committed Nov 13, 2024
1 parent aa023dd commit 256a980
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
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, ariaLabel, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link

Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/aria-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const ARIA_LABEL_SCHEMA = {
export function addAttribute( settings ) {
// Allow blocks to specify their own attribute definition with default values if needed.
if ( settings?.attributes?.ariaLabel?.type ) {
console.log( 'The ariaLabel', settings.attributes.ariaLabel );
return settings;
}
if ( hasBlockSupport( settings, 'ariaLabel' ) ) {
Expand Down
4 changes: 0 additions & 4 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
},
"ariaLabel": {
"type": "string",
"default": ""
}
},
"providesContext": {
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ private static function get_navigation_name( $attributes ) {

$navigation_name = $attributes['ariaLabel'] ?? '';

if ( ! empty( $navigation_name ) ) {
return $navigation_name;
}

// Load the navigation post.
if ( array_key_exists( 'ref', $attributes ) ) {
$navigation_post = get_post( $attributes['ref'] );
Expand Down Expand Up @@ -559,7 +563,6 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
*/
private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) {
$nav_menu_name = static::get_unique_navigation_name( $attributes );
$aria_label = ( ! empty( $attributes['ariaLabel'] ) ) ? $attributes['ariaLabel'] : $nav_menu_name;
$is_interactive = static::is_interactive( $attributes, $inner_blocks );
$is_responsive_menu = static::is_responsive( $attributes );
$style = static::get_styles( $attributes );
Expand All @@ -568,7 +571,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks )
array(
'class' => $class,
'style' => $style,
'aria-label' => $aria_label,
'aria-label' => $nav_menu_name,
)
);

Expand Down
3 changes: 1 addition & 2 deletions test/integration/fixtures/blocks/core__navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"overlayMenu": "mobile",
"icon": "handle",
"hasIcon": true,
"maxNestingLevel": 5,
"ariaLabel": ""
"maxNestingLevel": 5
},
"innerBlocks": []
}
Expand Down

0 comments on commit 256a980

Please sign in to comment.