-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storefront): BCTHEME-122 Add labels to swatches (#1761)
- Loading branch information
1 parent
3c76310
commit ad952be
Showing
20 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const ariaKeyCodes = { | ||
RETURN: 13, | ||
SPACE: 32, | ||
LEFT: 37, | ||
UP: 38, | ||
RIGHT: 39, | ||
DOWN: 40, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as initRadioOptions } from './radioOptions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { ariaKeyCodes } from './constants'; | ||
|
||
const setCheckedRadioItem = (itemCollection, itemIdx) => { | ||
itemCollection.each((idx, item) => { | ||
const $item = $(item); | ||
if (idx !== itemIdx) { | ||
$item.attr('aria-checked', false).prop('checked', false); | ||
return; | ||
} | ||
|
||
$item.attr('aria-checked', true).prop('checked', true).focus(); | ||
}); | ||
}; | ||
|
||
const calculateTargetItemPosition = (lastItemIdx, currentIdx) => { | ||
switch (true) { | ||
case currentIdx > lastItemIdx: return 0; | ||
case currentIdx < 0: return lastItemIdx; | ||
default: return currentIdx; | ||
} | ||
}; | ||
|
||
const handleItemKeyDown = itemCollection => e => { | ||
const { keyCode } = e; | ||
const itemIdx = itemCollection.index(e.currentTarget); | ||
const lastCollectionItemIdx = itemCollection.length - 1; | ||
|
||
if (Object.values(ariaKeyCodes).includes(keyCode)) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
|
||
switch (keyCode) { | ||
case ariaKeyCodes.RETURN: | ||
case ariaKeyCodes.SPACE: { | ||
setCheckedRadioItem(itemCollection, itemIdx); | ||
break; | ||
} | ||
case ariaKeyCodes.LEFT: | ||
case ariaKeyCodes.UP: { | ||
const prevItemIdx = calculateTargetItemPosition(lastCollectionItemIdx, itemIdx - 1); | ||
itemCollection.get(prevItemIdx).focus(); | ||
break; | ||
} | ||
case ariaKeyCodes.RIGHT: | ||
case ariaKeyCodes.DOWN: { | ||
const nextItemIdx = calculateTargetItemPosition(lastCollectionItemIdx, itemIdx + 1); | ||
itemCollection.get(nextItemIdx).focus(); | ||
break; | ||
} | ||
|
||
default: break; | ||
} | ||
}; | ||
|
||
export default ($container, itemSelector) => { | ||
const $itemCollection = $container.find(itemSelector); | ||
|
||
$container.on('keydown', itemSelector, handleItemKeyDown($itemCollection)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
assets/js/theme/common/form-utils.js → assets/js/theme/common/utils/form-utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters