Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prevent iOS <= 14 from blowing up when reading scroll margin or padding #26

Merged
merged 2 commits into from
Aug 23, 2024
Merged
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
5 changes: 3 additions & 2 deletions src/use-snap-carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ const _getOffsetRect = (el: Element) => {
// https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding
const getScrollPaddingUsedValue = (el: HTMLElement, pos: 'left' | 'top') => {
const style = window.getComputedStyle(el);
const scrollPadding = style.getPropertyValue(`scroll-padding-${pos}`);
const scrollPadding =
style.getPropertyValue(`scroll-padding-${pos}`) || '0px';
if (scrollPadding === 'auto') {
return 0;
}
Expand All @@ -284,7 +285,7 @@ const getScrollPaddingUsedValue = (el: HTMLElement, pos: 'left' | 'top') => {
// https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin
const getScrollMarginUsedValue = (el: HTMLElement, pos: 'left' | 'top') => {
const style = window.getComputedStyle(el);
const scrollMargin = style.getPropertyValue(`scroll-margin-${pos}`);
const scrollMargin = style.getPropertyValue(`scroll-margin-${pos}`) || '0px';
// https://developer.mozilla.org/en-US/docs/Web/CSS/length
// https://www.w3.org/TR/css3-values/#length-value
const invalidMsg = `Unsupported scroll margin value, expected <length> value, received ${scrollMargin}`;
Expand Down
Loading