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

Add aria label to the customer account block link #46899

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: update

Add aria-label to customer account block link when in icon-only display mode.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ protected function render( $attributes, $content, $block ) {
),
);

// 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>';
Expand Down