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-209 Search result not notified by screen reader #1867

Merged
merged 2 commits into from
Oct 21, 2020
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
- Search result not notified by screen reader. [#1867](https://github.com/bigcommerce/cornerstone/pull/1867)
- Add aria label with price to Product List Item. [#1878](https://github.com/bigcommerce/cornerstone/pull/1878)
- Fixed comparing Products on 'Account - Recently Viewed' page. [#1877](https://github.com/bigcommerce/cornerstone/pull/1877)
- Remove layout shifts to improve CLS indicator from Lighthouse performance report. [#1869](https://github.com/bigcommerce/cornerstone/pull/1869)
Expand Down
21 changes: 21 additions & 0 deletions assets/js/theme/global/quick-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ export default function () {
}

$quickSearchResults.html(response);
const $quickSearchResultsCurrent = $quickSearchResults.filter(':visible');

const $noResultsMessage = $quickSearchResultsCurrent.find('.quickSearchMessage');
if ($noResultsMessage.length) {
$noResultsMessage.attr({
role: 'status',
'aria-live': 'polite',
});
} else {
const $quickSearchAriaMessage = $quickSearchResultsCurrent.next();
$quickSearchAriaMessage.addClass('u-hidden');

const predefinedText = $quickSearchAriaMessage.data('search-aria-message-predefined-text');
const itemsFoundCount = $quickSearchResultsCurrent.find('.product').length;

$quickSearchAriaMessage.text(`${itemsFoundCount} ${predefinedText} ${searchQuery}`);

setTimeout(() => {
$quickSearchAriaMessage.removeClass('u-hidden');
}, 100);
}
});
}, 200);

Expand Down
4 changes: 4 additions & 0 deletions assets/js/theme/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export default class Search extends CatalogPage {
$searchForm.append(input);
}
});

setTimeout(() => {
$('[data-search-aria-message]').removeClass('u-hidden');
}, 100);
BC-tymurbiedukhin marked this conversation as resolved.
Show resolved Hide resolved
}

loadTreeNodes(node, cb) {
Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@
"form_button_text": "Search",
"count": "{ count, plural, one {# result} other {# results} } for '{ search_query }'",
"quick_count": "{ count, plural, one {# product result} other {# product results} } for '{ search_query }'",
"quick_count_live": "product results for",
"product_count": "Products ({count})",
"content_count": "News & Information ({count})"
},
Expand Down
2 changes: 1 addition & 1 deletion templates/components/common/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<div class="dropdown-menu" id="cart-preview-dropdown" data-dropdown-content aria-hidden="true"></div>
</li>
</ul>
<div class="dropdown dropdown--quickSearch" id="quickSearch" aria-hidden="true" tabindex="-1" data-prevent-quick-search-close>
<div class="dropdown dropdown--quickSearch" id="quickSearch" aria-hidden="true" data-prevent-quick-search-close>
{{> components/common/quick-search name='nav-quick-search'}}
</div>
</nav>
5 changes: 5 additions & 0 deletions templates/components/common/quick-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@
</fieldset>
</form>
<section class="quickSearchResults" data-bind="html: results"></section>
<p role="status"
aria-live="polite"
class="aria-description--hidden"
data-search-aria-message-predefined-text="{{{lang 'search.results.quick_count_live'}}}"
></p>
</div>
8 changes: 8 additions & 0 deletions templates/pages/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ <h5 class="suggestion-title">{{lang 'forms.search.suggestions.title'}}</h5>
</div>
{{/if}}

<p role="status"
aria-live="polite"
class="quickSearchResultsAriaMessage aria-description--hidden u-hidden"
data-search-aria-message
>
{{{lang 'search.results.count' count=result_count search_query=(sanitize forms.search.query)}}}
</p>

<div role="tabpanel" id="search-results-content" aria-labelledby="search-results-content-count" {{#if forms.search.section '!=' 'content'}}class="u-hidden"{{/if}}>
{{> components/search/content-listing}}
</div>
Expand Down