Skip to content

Commit

Permalink
fix(storefront): BCTHEME-282 Fix aria-labels for collapsibleFactory e…
Browse files Browse the repository at this point in the history
…lements (#1868)
  • Loading branch information
BC-tymurbiedukhin committed Oct 21, 2020
1 parent c8c85b5 commit 4fceae0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
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

0 comments on commit 4fceae0

Please sign in to comment.