primitives icon indicating copy to clipboard operation
primitives copied to clipboard

Scrolling issue - Select on sticky header make unwanted page scroll up

Open zecka opened this issue 1 year ago • 5 comments

Bug report

Current Behavior

Page scroll up when open or close radix-ui/react-select inside a sticky header. Maybe because the select component is focused on open/close

Expected behavior

Global page scroll doesn't change when open/close a select compoment

Reproducible example

https://codesandbox.io/s/scrolling-issue-select-on-sticky-header-sr5fgz?file=/src/App.tsx

In my project i have this issue on select open. I dont find a way to reproduce it on codesandbox, but on codesandbox i have this issue on close

On my project: radix-ui-select-focus-on-click On codesandbox: (https://codesandbox.io/s/scrolling-issue-select-on-sticky-header-sr5fgz?file=/src/App.tsx) radix-ui-select-Scroll-up

Suggested solution

Maybe provide a way to disable the focus onClick or use a focus without scrolling with something like

element.focus({ preventScroll: true });

Additional context

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-select 1.2.2
React react 18.2.0
Browser Chrome on windows 116.0.5845.111
Assistive tech
Node n/a
npm/yarn
Operating System

zecka avatar Aug 28 '23 09:08 zecka

Hello @zecka i had a similar issue on a project i worked on. what i did is put the Select.Content inside Select.Portal and it fixed the issue for me. I tested it on your code on codesandbox and it worked. Happy coding.

sbahaddi avatar Aug 30 '23 15:08 sbahaddi

I had an issue where if <body> had height: 100vh; set, opening the select causes the jump to top. Very curious as to why it's happening.

nguyen-michael avatar Oct 25 '23 15:10 nguyen-michael

I had an issue where if <body> had height: 100vh; set, opening the select causes the jump to top. Very curious as to why it's happening.

I can confirm that i have same issue in NextJS when set:

body > div { @apply flex min-h-svh flex-col; }

then select content jumps to top and became not visible, as a temporry workaround i use avoidCollisions={false} but i'm looking for solution as well

k-zakhariy avatar Apr 22 '24 15:04 k-zakhariy

Was this issue fixed in some way?

ann0nip avatar Jun 24 '24 23:06 ann0nip

Was this issue fixed in some way?

no it's still there...

rickyzhangca avatar Jul 31 '24 18:07 rickyzhangca