-
Notifications
You must be signed in to change notification settings - Fork 123
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
How to stick popover with element that is not child of popover #28
Comments
+1 |
have the same issue |
If this is still relevant to anyone, I made a little wrapper which swaps the API around for this use case: const RefTarget = React.forwardRef(({ target }, ref) => {
if (typeof ref === 'function') ref(target); // Forward target to callback refs.
else ref.current = target; // Forward target to object refs.
return null; // Don't render anything.
});
const TargetedPopover = ({ targetElement, children, ...props }) =>
<Popover isOpen={true} content={children} {...props}>
<RefTarget target={targetElement} />
</Popover> Use it like this: const MyPage = () => {
const [target, setTarget] = useState(null); // Reference a DOM node however you like.
return (
<article>
<h1>Hi</h1>
<TargetedPopover targetElement={target}>This is the Popover content.</TargetedPopover>
<MyFancyComponent childRef={setTarget} />
</article>
);
} |
I'm not quite sure I understand what the issue here is. Here's a code sandbox demonstrating the ability to position a popover that doesn't follow the target when scrolling, using the |
The problem is that we do want to follow an element, but we don't want to nest it under
This demonstrates our problem, because our desired behaviour is that we create a popover that does follow some element that is already existing. Supporting something like a |
@BudgieInWA In that case, the wrapper you wrote above is a clever way to do this. I may try fiddling with some kind of It seemed like the trouble @hern12 was having involved a popover following its target element on scroll when they'd rather have it remain stationary. That's what I tried addressing in the sandbox. |
Ah, I had missed that. Thanks for the example, direct control like that does look powerful too. |
It's been a long time I forgot my problem lol. Anyway thank you so much for reply |
I use contentLocation and get client position from another element that it is not the child of popover component it shows correctly when open but if I scroll up or down it follows too how to fix this. Thank you
The text was updated successfully, but these errors were encountered: