Skip to content

Commit

Permalink
feat(cornerstone):BCTHEME-201: add expanded/collapsed state on add-in…
Browse files Browse the repository at this point in the history
…fo button (#1844)

Co-authored-by: BC-tymurbiedukhin <66319629+BC-tymurbiedukhin@users.noreply.github.com>
  • Loading branch information
bc-alexsaiannyi and BC-tymurbiedukhin authored Oct 2, 2020
1 parent 7b6fb33 commit 717782f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 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
- Add collapsed/expanded state announcement by screen reader to add-info button within shipping estimator. [#1844](https://github.com/bigcommerce/cornerstone/pull/1844)
- Fixed empty cart notification not announced by screen reader. [#1846](https://github.com/bigcommerce/cornerstone/pull/1846)
- Product carousel with related products - arrows not working. [#1828](https://github.com/bigcommerce/cornerstone/pull/1828)
- Fixed contrast on buttons border color in compliance with AA standard [#1817](https://github.com/bigcommerce/cornerstone/pull/1817)
Expand Down
34 changes: 20 additions & 14 deletions assets/js/theme/cart/shipping-estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import stateCountry from '../common/state-country';
import nod from '../common/nod';
import utils from '@bigcommerce/stencil-utils';
import { Validators } from '../common/utils/form-utils';
import collapsibleFactory from '../common/collapsible';
import swal from '../global/sweet-alert';

export default class ShippingEstimator {
constructor($element) {
this.$element = $element;

this.$state = $('[data-field-type="State"]', this.$element);
this.isEstimatorFormOpened = false;
this.initFormValidation();
this.bindStateCountryChange();
this.bindEstimatorEvents();
Expand Down Expand Up @@ -133,10 +135,26 @@ export default class ShippingEstimator {
});
}

toggleEstimatorFormState(toggleButton, buttonSelector, $toggleContainer) {
const changeAttributesOnToggle = (selectorToActivate) => {
$(toggleButton).attr('aria-labelledby', selectorToActivate);
$(buttonSelector).text($(`#${selectorToActivate}`).text());
};

if (!this.isEstimatorFormOpened) {
changeAttributesOnToggle('estimator-close');
$toggleContainer.removeClass('u-hidden');
} else {
changeAttributesOnToggle('estimator-add');
$toggleContainer.addClass('u-hidden');
}
this.isEstimatorFormOpened = !this.isEstimatorFormOpened;
}

bindEstimatorEvents() {
const $estimatorContainer = $('.shipping-estimator');
const $estimatorForm = $('.estimator-form');

collapsibleFactory();
$estimatorForm.on('submit', event => {
const params = {
country_id: $('[name="shipping-country"]', $estimatorForm).val(),
Expand Down Expand Up @@ -165,19 +183,7 @@ export default class ShippingEstimator {

$('.shipping-estimate-show').on('click', event => {
event.preventDefault();

$(event.currentTarget).hide();
$estimatorContainer.removeClass('u-hiddenVisually');
$('.shipping-estimate-hide').show();
});


$('.shipping-estimate-hide').on('click', event => {
event.preventDefault();

$estimatorContainer.addClass('u-hiddenVisually');
$('.shipping-estimate-show').show();
$('.shipping-estimate-hide').hide();
this.toggleEstimatorFormState(event.currentTarget, '.shipping-estimate-show__btn-name', $estimatorContainer);
});
}
}
3 changes: 1 addition & 2 deletions assets/scss/components/stencil/cart/_cart.scss
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ $cart-item-label-offset: $cart-thumbnail-maxWidth + $cart-item-sp
.coupon-code-add,
.coupon-code-cancel,
.shipping-estimate-show,
.shipping-estimate-hide,
.gift-certificate-add,
.gift-certificate-cancel {
color: stencilColor("color-textSecondary");
Expand All @@ -444,7 +443,7 @@ $cart-item-label-offset: $cart-thumbnail-maxWidth + $cart-item-sp
}

.coupon-code-cancel,
.shipping-estimate-hide {
.shipping-estimate-show[aria-expanded="true"] {
font-style: italic;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
},
"shipping_estimator": {
"add_info": "Add Info",
"cancel": "Cancel",
"select_a_country": "Country",
"select_a_state": "State/province",
"estimate_shipping": "Estimate Shipping",
Expand Down
9 changes: 6 additions & 3 deletions templates/components/cart/shipping-estimator.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
</div>
{{else}}
<div class="cart-total-value">
<button class="shipping-estimate-show">{{lang 'cart.shipping_estimator.add_info'}}</button>
<button class="shipping-estimate-hide" style="display: none;">Cancel</button>
<button data-collapsible="add-shipping" class="shipping-estimate-show" aria-labelledby="estimator-add">
<span class="shipping-estimate-show__btn-name">{{lang 'cart.shipping_estimator.add_info'}}</span>
<span id="estimator-add" class="u-hidden">{{lang 'cart.shipping_estimator.add_info'}}</span>
<span id="estimator-close" class="u-hidden">{{lang 'cart.shipping_estimator.cancel'}}</span>
</button>
</div>
{{/if}}

<div class="shipping-estimator u-hiddenVisually">
<div id="add-shipping" class="shipping-estimator u-hidden">
<form class="form estimator-form" data-shipping-estimator>
<dl>
<dt class="estimator-form-label">
Expand Down

0 comments on commit 717782f

Please sign in to comment.