Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Ensure aria-label is showing correct value based on setting #9672

Merged
merged 2 commits into from
Jun 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions assets/js/blocks/mini-cart/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,31 @@ const MiniCartBlock = ( attributes: Props ): JSX.Element => {
parseInt( cartTotals.total_items_tax, 10 )
: parseInt( cartTotals.total_items, 10 );

const ariaLabel = sprintf(
/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
_n(
'%1$d item in cart, total price of %2$s',
'%1$d items in cart, total price of %2$s',
cartItemsCount,
'woo-gutenberg-products-block'
),
cartItemsCount,
formatPrice( subTotal, getCurrencyFromPriceResponse( cartTotals ) )
);
const ariaLabel = hasHiddenPrice
? sprintf(
/* translators: %1$d is the number of products in the cart. */
_n(
'%1$d item in cart',
'%1$d items in cart',
cartItemsCount,
'woo-gutenberg-products-block'
),
cartItemsCount
)
: sprintf(
/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
_n(
'%1$d item in cart, total price of %2$s',
'%1$d items in cart, total price of %2$s',
cartItemsCount,
'woo-gutenberg-products-block'
),
cartItemsCount,
formatPrice(
subTotal,
getCurrencyFromPriceResponse( cartTotals )
)
);

const colorStyle = {
backgroundColor: style?.color?.background,
Expand Down
49 changes: 33 additions & 16 deletions assets/js/blocks/mini-cart/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,47 @@ export const updateTotals = ( totals: [ string, number ] | undefined ) => {
return;
}
const [ amount, quantity ] = totals;
const miniCartButtons = document.querySelectorAll(
'.wc-block-mini-cart__button'
);
const miniCartBlocks = document.querySelectorAll( '.wc-block-mini-cart' );
const miniCartQuantities = document.querySelectorAll(
'.wc-block-mini-cart__badge'
);
const miniCartAmounts = document.querySelectorAll(
'.wc-block-mini-cart__amount'
);

miniCartButtons.forEach( ( miniCartButton ) => {
miniCartButton.setAttribute(
miniCartBlocks.forEach( ( miniCartBlock ) => {
if ( ! ( miniCartBlock instanceof HTMLElement ) ) {
return;
}

const miniCartButton = miniCartBlock.querySelector(
'.wc-block-mini-cart__button'
);

miniCartButton?.setAttribute(
'aria-label',
sprintf(
/* translators: %s number of products in cart. */
_n(
'%1$d item in cart, total price of %2$s',
'%1$d items in cart, total price of %2$s',
quantity,
'woo-gutenberg-products-block'
),
quantity,
amount
)
miniCartBlock.dataset.hasHiddenPrice
? sprintf(
/* translators: %s number of products in cart. */
_n(
'%1$d item in cart',
'%1$d items in cart',
quantity,
'woo-gutenberg-products-block'
),
quantity
)
: sprintf(
/* translators: %1$d is the number of products in the cart. %2$s is the cart total */
_n(
'%1$d item in cart, total price of %2$s',
'%1$d items in cart, total price of %2$s',
quantity,
'woo-gutenberg-products-block'
),
quantity,
amount
)
);
} );
miniCartQuantities.forEach( ( miniCartQuantity ) => {
Expand Down