-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 visual jitter in Combobox
component when using native scrollbar
#3190
Fix visual jitter in Combobox
component when using native scrollbar
#3190
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -1675,6 +1683,7 @@ function OptionsFn<TTag extends ElementType = typeof DEFAULT_OPTIONS_TAG>( | |||
'--button-width': useElementSize(data.buttonRef, true).width, | |||
} as CSSProperties, | |||
onWheel: handleWheel, | |||
onScroll: handleScroll, |
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.
Chose to use an onScroll
event as none of the other events would fire if the first thing we move our mouse into is the native scrollbar.
If you use the scrollbar, a `mousedown` and `pointerdown` event is fired before you start interacting with the scrollbar. If you use the `scroll` event, then the callback is fired while scrolling. To improve performance a bit more, we will set the activation trigger in the `mousedown` event because we only need to set it once. If you are done scrolling, we don't reset it (we didn't do that before either), but instead we rely on other events to override the trigger (e.g.: you start using the keyboard). The big benefit is that this now only calls the `setActivationTrigger` once, instead of `n` times with the same value.
This is a similar performance trick as before. We only need to set the activationTrigger once, so there is no need to keep calling this function for no reason.
86c8a82
to
4e34771
Compare
Combobox
when using native scrollbarCombobox
component when using native scrollbar
Hey! Thank you for this PR, I really appreciate it. I made some changes, here is a quick breakdown:
Thanks again for your initial work! |
Fixes #3189
Bug
The dropdown will jitter when using the native scrollbar before entering the dropdown list with your cursor or using the mouse wheel to scroll.
This is because the
ActivationTrigger
has not been set to pointer. As a result, scrollToIndex
is called while you are attempting to scroll, leading to the rubberband effect.How to Reproduce
If you are on macOS, go to System Settings and set Show Scroll Bars to Always.
It can be difficult to reproduce without this, as you must hover over the native scroll bar first avoid triggering any React events.
The bug on the Tailwind blog demo
tw-blog-scroll.mp4
Occasionally, React can render the scrolling quickly enough to make the rubberbanding non-visible, making it somewhat challenging to consistently reproduce on the blog post.
Reproducing on the Playground
Adding a 250ms artificial delay on the scrolling makes it much more obvious.
If you scroll with your mouse wheel or move your pointer inside the dropdown, the issue will resolve itself. The bug only occurs when you enter native scrollbar first and interact with it directly.
native-scroll-delay.mp4
A Fix
Adding a
onScroll
handler that ignores mobile and sets theActivationTrigger
to pointer.native-scroll-fix.mp4
Feel free to discard any or all of this fix or improve it further. If nothing else, this demonstrates how to reproduce it.