-
Notifications
You must be signed in to change notification settings - Fork 4.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
Dropdown remains fixed in place and doesn't scroll with parent container #4088
Comments
Hi - for info, I have explicitly tested this by installing v3.0.4 and v3.0.3, and I experience the same issue in both versions. Is it possible that the bug existed even before the commit that you have highlighted above? |
I think @mjb95 is right, as this is the behaviour of React Select in v2 also; menuPosition fixed & portal, both do not update the positioning of the Menu on scroll - so the menu is stuck. All the sanboxes here have menuPosition fixed, and portal, and nothing related to it was changed in that commit. The bug mentioned by @bladey is related to a workaround ( This sandbox demonstrates that bug it better: on opening the menu, the scroll stops working completely. @bladey I suggest we separate these issues, as This would only be solved if something like tether.js is pulled into the lib (which has been proposed before) #810 is directly related to this (and all others, except #3929), & has most of the problems/solutions related in one place - and IMO it is still not resolved. (see a hacky solution in this comment, which extends the Select class and uses react-tether + react-dimensions: #810 (comment)) |
Hi @bladey Could you please let us know if this would be prioritised and made available in next patch release please. |
@srinivasmerugu we'll get to it as soon as we can, any updates will be provided here. |
Hi, has any progress been made on this issue? |
Hi, anyone has any update on this? |
i see it happening in chrome 85. |
how much time it take to push this commit? |
EDIT: 🎉 I've archived the fork now that we've got some momentum in this repo and Jed is involved again. Sorry for the disturbance! |
Are you guys changing the |
@colin-oos How do you target a specific element? I have a div that I want to use as my target, how would I reference it? |
Same issue here, got a lot of modals with height bigger than my screen (added overflow: scroll) - when do you think it'll be fixed? |
You could use a React Ref or if you give your |
This seems like another one where the simplest fix is just to add I'm not sure why it's taken them so long to fix this, but it does seem like it will get fixed eventually. In the mean time, I think it should be fine to use fixed here the way it is. |
I'm not sure of your particular situation, but using The attribute never worked properly because it has never recalculated the position on page scroll. I made substantial progress on this task a few months before I got sidetracked by releasing Redux DevTools 3.0. I hope to get back to it soon and my estimate is still months, but not years (starting from October 2021). |
May I suggest taking a look at Floating UI instead of popper when implementing this? Also, awesome work you do here. 💪 I'll see if I can convince my org to sponsor you. |
Why does this issue not occur on the official website? https://react-select.com/home |
I was able to fix the issue using this commit !! closeMenuOnScroll={(e) => {
return e.target.contains(containerRef.current);
}} I was looking for solution involving refs and without assigning unique IDs to the container. Hope this helps someone! |
This issue only occurs when using portalling or fixed menu positioning. |
Hello, I've reviewed |
@andrew-aladev I doubt that's a realistic option, you'd have to consistently rerender at 60fps on top of everything else the browser is doing to avoid jitter, especially when considering many operating systems today use smooth scroll as default. |
I've added simple patch for 3.1.0 version, you can easily adapt it for any other version.
Sure, absolute menu has move using jumps. I've added a patch for this solution. If user wants smooth movement than it has to avoid absolute mode. Thank you. |
@Methuselah96 Could you please let us know if there is any plan of integrating popper for menu positioning as discussed here very long back for addressing scrolling issue with portal. |
The status remains the same as it was in my previous comments. I am hopeful it will be released by the end of the year. |
Unfortunately popper (like any other absolute solutions) won't help. Absolute solutions uses So it looks like the only one possible solution is |
thanks . it's helpful |
@Methuselah96 Thanks for the #5256 . Could you please let us know in which version of react-select it will accommodate. |
For me, simply adding the prop |
as a hack, I've done the following: const [open, setOpen] = useState(false);
const portalRef = useRef(document.getElementById('popover-root'));
const selectRef = useRef<SelectInstance<Item, false>>(null);
// ...
// Bug in library - Dropdown doesn't scroll with page if using a portal
// Remove this hack once the folling issue is closed:
// https://github.com/JedWatson/react-select/issues/4088
const hackToFixScrollingPosition = useCallback(() => {
const controllerEl = selectRef.current?.controlRef;
const menuEl = selectRef.current?.menuListRef;
const menuControllingEl = menuEl?.parentElement?.parentElement;
if (!controllerEl || !menuEl || !menuControllingEl) {
return;
}
const controllerBounding = controllerEl.getBoundingClientRect();
const menuBounding = menuEl.getBoundingClientRect() as DOMRect;
const shouldPositionOnTop = window.innerHeight - controllerBounding.bottom < menuBounding.height;
if (shouldPositionOnTop) {
menuControllingEl.style.top = controllerBounding.top - menuBounding.height - 5 + 'px';
} else {
menuControllingEl.style.top = controllerBounding.top + controllerBounding.height + 5 + 'px';
}
menuControllingEl.style.left = controllerBounding.left + 'px';
}, []);
useEffect(
function hackToFixScrollingPositionSubscriber() {
let el: HTMLElement | null | undefined = selectRef.current?.controlRef;
const listening: HTMLElement[] = [];
do {
if (el) { // ts pls
el.addEventListener('scroll', hackToFixScrollingPosition);
listening.push(el);
}
} while ((el = el?.parentElement));
return () => {
for (const el of listening) {
el?.removeEventListener('scroll', hackToFixScrollingPosition);
}
};
},
[hackToFixScrollingPosition],
);
useEffect(
function hackToFixScrollingPositionOnOpen() {
setTimeout(hackToFixScrollingPosition, 100);
},
[hackToFixScrollingPosition, open],
);
// ...
<Select
....
menuPortalTarget={portalRef.current}
ref={selectRef}
menuShouldScrollIntoView={false}
minMenuHeight={50}
onMenuClose={() => setOpen(false)}
onMenuOpen={() => setOpen(true)}
/> |
🎉🎉🎉 This has been fixed in Let me know if this addresses the issues experienced here. If there are more bugs to sort out related to menu positioning, please open new issues with CodeSandboxes using the latest version |
I have upgraded to 5.5.0 and haven't noticed any difference in this issue. Unless I include these three options, the selects collide with each other when stacked vertically:
The issue with using these three options, is that it wipes all the styling I have set, and I cannot figure out a way to override the css styling when it is attached to the body. |
@Dalton-Klein, if you're able to make a CodeSandbox repro of the bug, I'd be happy to take a look for you. |
I can confirm that the 5.5.0 release works excellent and is buttery smooth. Thank you very much for everyone involved for your effort, especially @Methuselah96, this is splendid. |
genius, works! |
@Methuselah96 I see that when a div has the select tag from react-select and when you try to scroll the div the drop down of the select appears above of the divsion when scroll is extended. Dropdown going above other elements when scrolling to the end of the div. Can you look into this. |
This issue is a round-up of multiple past issues documenting the same bug. Feel free to check out the linked issues below for more information. This issue is the source of truth going forward to investigate the issue, report findings, and implement a bug fix.
Issue:
Dropdown remains fixed in place and doesn't scroll with parent container.
The commit responsible for this issue is located here - 691a011
Version
v3.0.4
does not have this bug however the latest releasev3.1.0
does.Issues:
#4554
#4020
#4052
#3734
#4085
#3929
#3349
#3646
Examples:
https://codesandbox.io/s/react-select-v3-sandbox-forked-lgkms
https://codesandbox.io/s/compassionate-cookies-85j2n
https://codesandbox.io/s/react-select-v3-sandbox-kr5wf
https://codesandbox.io/s/festive-dirac-izf5y
https://codesandbox.io/s/react-codesandboxer-example-xy47y
If anyone would like to share any further information, please do so.
The text was updated successfully, but these errors were encountered: