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

fix(storefront): BCTHEME-368 fix announcement for shop by price filter selection #1966

Merged
merged 2 commits into from
Feb 2, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Fixed filtered selection not announced by screen reader. [#1966](https://github.com/bigcommerce/cornerstone/pull/1966)

## 5.1.0 (01-26-2021)
- Updated Cornerstone theme and respected variants to meet the verticals/industries documented in BCTHEME-387
Expand Down
33 changes: 21 additions & 12 deletions assets/js/theme/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ export default class Category extends CatalogPage {
this.validationDictionary = createTranslationDictionary(context);
}

onReady() {
$('[data-button-type="add-cart"]').on('click', (e) => {
$(e.currentTarget).next().attr({
role: 'status',
'aria-live': 'polite',
});
setLiveRegionAttributes($element, roleType, ariaLiveStatus) {
$element.attr({
role: roleType,
'aria-live': ariaLiveStatus,
});
}

makeShopByPriceFilterAccessible() {
if (!$('[data-shop-by-price]').length) return;

if ($('.navList-action').hasClass('is-active')) {
$('a.navList-action.is-active').focus();
}

$('a.navList-action').on('click', () => this.setLiveRegionAttributes($('span.price-filter-message'), 'status', 'assertive'));
}

onReady() {
$('[data-button-type="add-cart"]').on('click', (e) => this.setLiveRegionAttributes($(e.currentTarget).next(), 'status', 'polite'));

this.makeShopByPriceFilterAccessible();

compareProducts(this.context.urls);

Expand All @@ -27,12 +41,7 @@ export default class Category extends CatalogPage {
hooks.on('sortBy-submitted', this.onSortBySubmit);
}

$('a.reset-btn').on('click', () => {
$('span.reset-message').attr({
role: 'status',
'aria-live': 'polite',
});
});
$('a.reset-btn').on('click', () => this.setLiveRegionsAttributes($('span.reset-message'), 'status', 'polite'));

this.ariaNotifyNoProducts();
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@
"label": "Categories",
"shop_by_price": "Shop By Price",
"shop_by_price_range_aria": "Price range from {from} to {to}",
"filter_price_range": "Price range:",
"add_cart_announcement": "The item has been added",
"reset": "Reset",
"filter_reset_announcement": "The filter has been reset",
"filter_select_announcement": "The filter has been applied",
"view_all": {
"name": "All {category}"
}
Expand Down
9 changes: 4 additions & 5 deletions templates/components/category/shop-by-price.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
{{#and theme_settings.shop_by_price_visibility shop_by_price}}
<div class="sidebarBlock">
<h2 class="sidebarBlock-heading">{{lang 'category.shop_by_price'}}</h2>
<h2 class="sidebarBlock-heading" data-shop-by-price>{{lang 'category.shop_by_price'}}</h2>
<ul class="navList">
{{#each shop_by_price}}
<li class="navList-item">
<a
{{#if selected }}
class="navList-action is-active"
role="status"
aria-live="polite"
aria-live="assertive"
{{else}}
class="navList-action"
{{/if}}
href="{{url}}"
title="{{low.formatted}} - {{high.formatted}}"
aria-label="{{{lang 'category.shop_by_price_range_aria' from=low.formatted to=high.formatted}}}"
>
{{low.formatted}} - {{high.formatted}}
{{lang 'category.filter_price_range'}} {{low.formatted}} - {{high.formatted}}
</a>
<span class="price-filter-message aria-description--hidden">{{lang 'category.filter_select_announcement'}}</span>
</li>
{{/each}}

Expand Down