Add aria label to the customer account block link (#46899)

This commit is contained in:
Sam Seay 2024-04-29 09:35:47 +08:00 committed by GitHub
parent f9a7ff04f0
commit 1e225f701f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 1 deletions

View File

@ -56,12 +56,20 @@ export const CustomerAccountBlock = ( {
} ): JSX.Element => {
const { displayStyle, iconStyle, iconClass } = attributes;
const ariaAttributes =
displayStyle === DisplayStyle.ICON_ONLY
? {
'aria-label': __( 'My Account', 'woocommerce' ),
}
: {};
return (
<a
href={ getSetting(
'dashboardUrl',
getSetting( 'wpLoginUrl', '/wp-login.php' )
) }
{ ...ariaAttributes }
>
<AccountIcon
iconStyle={ iconStyle }

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Add aria-label to customer account block link when in icon-only display mode.

View File

@ -122,10 +122,13 @@ class CustomerAccount extends AbstractBlock {
),
);
// Only provide aria-label if the display style is icon only.
$aria_label = self::ICON_ONLY === $attributes['displayStyle'] ? 'aria-label="' . esc_attr( $this->render_label() ) . '"' : '';
$label_markup = self::ICON_ONLY === $attributes['displayStyle'] ? '' : '<span class="label">' . wp_kses( $this->render_label(), array() ) . '</span>';
return "<div class='wp-block-woocommerce-customer-account " . esc_attr( $classes_and_styles['classes'] ) . "' style='" . esc_attr( $classes_and_styles['styles'] ) . "'>
<a href='" . esc_attr( $account_link ) . "'>
<a " . $aria_label . " href='" . esc_attr( $account_link ) . "'>
" . wp_kses( $this->render_icon( $attributes ), $allowed_svg ) . $label_markup . '
</a>
</div>';