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

isScrollBehaviorSupported returns false positive in Safari, causing polyfill to fail #139

Open
madeleineostoja opened this issue Aug 15, 2022 · 7 comments

Comments

@madeleineostoja
Copy link

Safari now supports scroll-behavior: smooth in CSS, but not elem.scrollIntoView({ behavior: 'smooth' }), causing this polfyfill to incorrectly not be applied.

I'm not sure of a feature check you could do, other than just adding a navigator check for Safari specifically in addition to the current CSS prop check. Feels hacky, but right now the polyfill is broken out of the box for the majority use-case

@madeleineostoja madeleineostoja changed the title isScrollBehaviorSupported returns false positive in Safari isScrollBehaviorSupported returns false positive in Safari, causing polyfill to fail Aug 15, 2022
@madeleineostoja
Copy link
Author

madeleineostoja commented Aug 15, 2022

FWIW I'm using detect-browser as a workaround for now, might be worth documenting if nothing else:

import { detect } from 'detect-browser';
import { elementScrollIntoViewPolyfill } from 'seamless-scroll-polyfill';

const browser = detect();
elementScrollIntoViewPolyfill({
  forcePolyfill: browser?.name === 'safari' || browser?.name === 'ios'
});

@magic-akari
Copy link
Owner

This was a situation I hadn't thought of and Safari surprised me.
Which version of Safari is it?

@madeleineostoja
Copy link
Author

@magic-akari
Copy link
Owner

Just test it with Safari on iOS 15.6.
And the elem.scrollIntoView({ behavior: 'smooth' }) is native supported.

@madeleineostoja
Copy link
Author

madeleineostoja commented Aug 16, 2022

Huh I guess caniuse is out of date. I can confirm that the latest version of desktop safari is definitely an issue though. And I would assume that anything prior to iOS 15.6 is still an issue, which is still the majority in usage

@midanirachdi
Copy link

@magic-akari @madeleineostoja
the fix in this case would be to add overflow: auto to the container and hide the scrollbar (in case you don't want a scrollbar) like so ::-webkit-scrollbar { display: none; } as stated here iamdustan#177 (comment)

@madeleineostoja
Copy link
Author

Weird!

Can confirm that explicitly setting the overflow to scroll or auto (amounts to same thing if there's overflow) fixes this in safari. For my use-case I'm using JS to 'scroll' elements in a container I don't want users to scroll, so I just hijacked the wheel event to achieve that behaviour.

This gotcha should probably be documented and then the issue can be closed out

@magic-akari magic-akari pinned this issue Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants