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-282 Fix aria-labels for collapsibleFactory e… #1868

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
- Fix aria-labels for collapsibleFactory elements. [#1868](https://github.com/bigcommerce/cornerstone/pull/1868)
- Fixed social icons click behaviour after quick view modal reopening. [#1874](https://github.com/bigcommerce/cornerstone/pull/1874)
- Fixed Special Characters rendering under Wishlists. [#1873](https://github.com/bigcommerce/cornerstone/pull/1873)
- Cornerstone quick view. [#1857](https://github.com/bigcommerce/cornerstone/pull/1857)
Expand Down
28 changes: 17 additions & 11 deletions assets/js/theme/common/collapsible.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ export class Collapsible {

// Assign DOM attributes
this.$target.attr('aria-hidden', this.isCollapsed);
this.$toggle.attr('aria-controls', $target.attr('id')).attr('aria-expanded', this.isOpen);

if (!this.$toggle.attr('aria-label')) {
this.$toggle.attr('aria-label', $toggle.text().trim());
}
this.$toggle
.attr('aria-label', this._getToggleAriaLabelText($toggle))
.attr('aria-controls', $target.attr('id'))
.attr('aria-expanded', this.isOpen);

// Listen
this.bindEvents();
Expand Down Expand Up @@ -113,6 +112,13 @@ export class Collapsible {
return this._disabled;
}

_getToggleAriaLabelText($toggle) {
const $textToggleChildren = $toggle.children().filter((__, child) => $(child).text().trim());
const $ariaLabelTarget = $textToggleChildren.length ? $textToggleChildren.first() : $toggle;

return $($ariaLabelTarget).text().trim();
}

open({ notify = true } = {}) {
this.$toggle
.addClass(this.openClassName)
Expand Down Expand Up @@ -203,12 +209,12 @@ export class Collapsible {
* Convenience method for constructing Collapsible instance
*
* @param {string} [selector]
* @param {Object} [options]
* @param {Object} [options.$context]
* @param {Object} [options.disabledBreakpoint]
* @param {Object} [options.disabledState]
* @param {Object} [options.enabledState]
* @param {Object} [options.openClassName]
* @param {Object} [overrideOptions]
* @param {Object} [overrideOptions.$context]
* @param {Object} [overrideOptions.disabledBreakpoint]
* @param {Object} [overrideOptions.disabledState]
* @param {Object} [overrideOptions.enabledState]
* @param {Object} [overrideOptions.openClassName]
* @return {Array} array of Collapsible instances
*
* @example
Expand Down