-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Cart drawer #1544
Merged
Merged
Cart drawer #1544
Changes from 53 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
ff4d096
Cart drawer
tyleralsbury 17ea609
Added cart behaviours
tyleralsbury 81dc58b
in progress - animations
tyleralsbury af20a9e
temp
tyleralsbury 578619f
Behaviour improvements
tyleralsbury 6ebb15f
temp
tyleralsbury 6fe5bf4
Empty state
tyleralsbury 9066c52
Merge branch 'main' into cart-drawer
ludoboludo 74a3548
add new general settings and move old ones, also start updating the e…
ludoboludo fbfac65
add cart note to drawer and add conditionals to enable either notific…
ludoboludo 815045e
change the DOM structure
ludoboludo d9c02af
fix layout
ludoboludo 0aef289
adjust styling to match the cart page structure
ludoboludo cec56ce
tweaks
ludoboludo 2f6e16d
fix cart bubble not updating quantity when adding/removing
ludoboludo 8ee6791
remove comment
ludoboludo 940ae0c
Fix animation on cart when adding to cart. Adjust font size on empty …
ludoboludo 4f84c99
add dynamic checkout buttons and proper styling for them
ludoboludo 133bd60
deal with dynamic checkout buttons in drawer and moving CSS into its …
ludoboludo 2d73b1c
a11y fixes, load js asset only once, fix spacing in drawer
ludoboludo 7fddfbf
fix asset loading when drawer is disabled and show dynamic checkout b…
ludoboludo 6e4ca26
white space and console log removal
ludoboludo 7a1fe97
fixes duplicate ID and close button position as well as focus when cl…
ludoboludo 2f4d1eb
remove dynamic checkout setting and leave them on by default
ludoboludo 8844b6a
address some UX feedback, more to come
ludoboludo b1aba03
tweak button classes and fix trapFocus target
ludoboludo b1050bb
some small a11y fixes
ludoboludo a17f2aa
Visual tweaks, spacing and a11y fix for the cart note and duplicate IDs
ludoboludo 72aca93
fix overflow on chrome
ludoboludo c5e3c65
UX fixes and cart note class fix
ludoboludo e2d8347
add a11y fixes for cart table
ludoboludo a4ea68e
trying to fix focus trap
ludoboludo dce7ff9
fix focus trap for good. Hopefully.
ludoboludo 801043b
keep cart icon in header as link
ludoboludo c45b0a9
add aria-haspopup on submit button only via JS
ludoboludo e0d6897
remove dynamic checkout from drawer
ludoboludo 4e0774e
fix last a11y stuff
ludoboludo e65b016
fix Olivia's feedback
ludoboludo 552e46c
a11y tweaks
ludoboludo bf2271d
Update 2 translation files
translation-platform[bot] ca5df79
Update 17 translation files
translation-platform[bot] 751f1bc
Update 13 translation files
translation-platform[bot] 4990c0d
change elements used for price totals
ludoboludo 8933b67
fix spacing for discounted prices
ludoboludo fa0792d
address some of Lucas' comments
ludoboludo cd00038
fix language key
ludoboludo 19f52de
Update 6 translation files
translation-platform[bot] 07a9cda
move asset loading in header
ludoboludo 9387bf9
styling edit
ludoboludo df12fcd
Update 1 translation file
translation-platform[bot] e293d24
Edit IDs and remove repeated JS
ludoboludo be5058a
move a11y string to theme.liquid
ludoboludo 451e021
move cart drawer item JS
ludoboludo cd72d83
set back top value to 0 and remove console log
ludoboludo 7fff7d5
Cart type = page (#1638)
ludoboludo 26cdf47
Update 11 translation files
translation-platform[bot] 2754934
adjust close button color for iOS
ludoboludo 0ad8202
fix focus on quick add when closing drawer
ludoboludo 12ee9d1
fix table header layout on mobile
ludoboludo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
class CartDrawer extends HTMLElement { | ||
constructor() { | ||
super(); | ||
|
||
this.addEventListener('keyup', (evt) => evt.code === 'Escape' && this.close()); | ||
this.querySelector('#CartDrawer-Overlay').addEventListener('click', this.close.bind(this)); | ||
this.setHeaderCartIconAccessibility(); | ||
} | ||
|
||
setHeaderCartIconAccessibility() { | ||
const cartLink = document.querySelector('#cart-icon-bubble'); | ||
cartLink.setAttribute('role', 'button'); | ||
cartLink.setAttribute('aria-haspopup', 'dialog'); | ||
cartLink.addEventListener('click', (event) => { | ||
event.preventDefault(); | ||
this.open(cartLink) | ||
}); | ||
cartLink.addEventListener('keydown', (event) => { | ||
ludoboludo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (event.code.toUpperCase() === 'SPACE') { | ||
event.preventDefault(); | ||
this.open(cartLink); | ||
} | ||
}); | ||
} | ||
|
||
open(triggeredBy) { | ||
if (triggeredBy) this.setActiveElement(triggeredBy); | ||
const cartDrawerNote = this.querySelector('[id^="Details-"] summary'); | ||
if (cartDrawerNote && !cartDrawerNote.hasAttribute('role')) this.setSummaryAccessibility(cartDrawerNote); | ||
// here the animation doesn't seem to always get triggered. A timeout seem to help | ||
setTimeout(() => {this.classList.add('animate', 'active')}); | ||
|
||
this.addEventListener('transitionend', () => { | ||
const containerToTrapFocusOn = this.classList.contains('is-empty') ? this.querySelector('.drawer__inner-empty') : document.getElementById('CartDrawer'); | ||
const focusElement = this.querySelector('.drawer__inner') || this.querySelector('.drawer__close'); | ||
trapFocus(containerToTrapFocusOn, focusElement); | ||
}, { once: true }); | ||
|
||
document.body.classList.add('overflow-hidden'); | ||
} | ||
|
||
close() { | ||
this.classList.remove('active'); | ||
removeTrapFocus(this.activeElement); | ||
document.body.classList.remove('overflow-hidden'); | ||
} | ||
|
||
setSummaryAccessibility(cartDrawerNote) { | ||
cartDrawerNote.setAttribute('role', 'button'); | ||
cartDrawerNote.setAttribute('aria-expanded', 'false'); | ||
|
||
if(cartDrawerNote.nextElementSibling.getAttribute('id')) { | ||
ludoboludo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cartDrawerNote.setAttribute('aria-controls', cartDrawerNote.nextElementSibling.id); | ||
} | ||
|
||
cartDrawerNote.addEventListener('click', (event) => { | ||
event.currentTarget.setAttribute('aria-expanded', !event.currentTarget.closest('details').hasAttribute('open')); | ||
}); | ||
|
||
cartDrawerNote.parentElement.addEventListener('keyup', onKeyUpEscape); | ||
} | ||
|
||
renderContents(parsedState) { | ||
this.querySelector('.drawer__inner').classList.contains('is-empty') && this.querySelector('.drawer__inner').classList.remove('is-empty'); | ||
this.productId = parsedState.id; | ||
this.getSectionsToRender().forEach((section => { | ||
const sectionElement = section.selector ? document.querySelector(section.selector) : document.getElementById(section.id); | ||
sectionElement.innerHTML = | ||
this.getSectionInnerHTML(parsedState.sections[section.id], section.selector); | ||
})); | ||
|
||
setTimeout(() => { | ||
this.querySelector('#CartDrawer-Overlay').addEventListener('click', this.close.bind(this)); | ||
this.open(); | ||
}); | ||
} | ||
|
||
getSectionInnerHTML(html, selector = '.shopify-section') { | ||
return new DOMParser() | ||
.parseFromString(html, 'text/html') | ||
.querySelector(selector).innerHTML; | ||
} | ||
|
||
getSectionsToRender() { | ||
return [ | ||
{ | ||
id: 'cart-drawer', | ||
selector: '#CartDrawer' | ||
}, | ||
{ | ||
id: 'cart-icon-bubble' | ||
} | ||
]; | ||
} | ||
|
||
getSectionDOM(html, selector = '.shopify-section') { | ||
return new DOMParser() | ||
.parseFromString(html, 'text/html') | ||
.querySelector(selector); | ||
} | ||
|
||
setActiveElement(element) { | ||
this.activeElement = element; | ||
} | ||
} | ||
|
||
customElements.define('cart-drawer', CartDrawer); | ||
|
||
class CartDrawerItems extends CartItems { | ||
getSectionsToRender() { | ||
return [ | ||
{ | ||
id: 'CartDrawer', | ||
section: 'cart-drawer', | ||
selector: '.drawer__inner' | ||
}, | ||
{ | ||
id: 'cart-icon-bubble', | ||
section: 'cart-icon-bubble', | ||
selector: '.shopify-section' | ||
} | ||
]; | ||
} | ||
} | ||
|
||
customElements.define('cart-drawer-items', CartDrawerItems); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just flagging that this is related to #1612. We'll need to replace it:
once that PR is merged.
No need to change anything yet