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-184 Options on change modal need focus border #1839

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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

- Options on change modal need focus border. [#1839](https://github.com/bigcommerce/cornerstone/pull/1839)

## Draft
- Product cards should link to products. [#1842](https://github.com/bigcommerce/cornerstone/pull/1842)
- Sort By dropdowns need visual focus border. [#1833](https://github.com/bigcommerce/cornerstone/pull/1833)
Expand Down
4 changes: 3 additions & 1 deletion assets/js/theme/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'lodash';
import giftCertCheck from './common/gift-certificate-validator';
import utils from '@bigcommerce/stencil-utils';
import ShippingEstimator from './cart/shipping-estimator';
import { defaultModal } from './global/modal';
import { defaultModal, modalTypes } from './global/modal';
import swal from './global/sweet-alert';

export default class Cart extends PageManager {
Expand Down Expand Up @@ -137,6 +137,8 @@ export default class Cart extends PageManager {
modal.updateContent(response.content);

this.bindGiftWrappingForm();

modal.setupFocusableElements(modalTypes.CART_CHANGE_PRODUCT);
});

utils.hooks.on('product-option-change', (event, currentTarget) => {
Expand Down
14 changes: 10 additions & 4 deletions assets/js/theme/global/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SizeClasses = {
export const modalTypes = {
QUICK_VIEW: 'forQuickView',
PRODUCT_DETAILS: 'forProductDetails',
CART_CHANGE_PRODUCT: 'forCartChangeProduct',
WRITE_REVIEW: 'forWriteReview',
};

Expand All @@ -33,9 +34,10 @@ const focusableElements = {
[modalTypes.PRODUCT_DETAILS]: () => (
$('#previewModal').find(allTabbableElementsSelector)
),
[modalTypes.CART_CHANGE_PRODUCT]: () => (
$('#modal').find(allTabbableElementsSelector)
[modalTypes.WRITE_REVIEW]: () => (
$('#modal-review-form')
.find(allTabbableElementsSelector)
$('#modal-review-form').find(allTabbableElementsSelector)
),
};

Expand Down Expand Up @@ -241,14 +243,18 @@ export class Modal {
if (!isTab) return;

const $modalTabbableCollection = focusableElements[modalType]();
const lastCollectionIdx = $modalTabbableCollection.length - 1;
const modalTabbableCollectionLength = $modalTabbableCollection.length;

if (modalTabbableCollectionLength < 1) return;

const lastCollectionIdx = modalTabbableCollectionLength - 1;
const $firstTabbable = $modalTabbableCollection.get(0);
const $lastTabbable = $modalTabbableCollection.get(lastCollectionIdx);

$modalTabbableCollection.each((index, element) => {
const $element = $(element);

if ($modalTabbableCollection.length === 1) {
if (modalTabbableCollectionLength === 1) {
$element.addClass(`${firstTabbableClass} ${lastTabbableClass}`);
return false;
}
Expand Down