-
Notifications
You must be signed in to change notification settings - Fork 564
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
Tooltip: Add containerRef to Portal #848
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 7bb8abd:
|
This fixes an issue we're having where tooltips aren't visible when our video player is in full-screen mode. Would really appreciate having this change available! |
Hi! Would love to get a review on this so we can ship soon! |
We understand why this change might be useful and necessary, but this library does not currently have full-time support, and we would like to consider the API a bit more before merging. Keep in mind that you can always patch this behavior in the meantime in your own project with https://www.npmjs.com/package/patch-package |
An alternative to consider is updating Reach to include - export { MOUSE_REST_TIMEOUT, LEAVE_TIMEOUT, Tooltip, TooltipPopup, useTooltip };
+ export { MOUSE_REST_TIMEOUT, LEAVE_TIMEOUT, Tooltip, TooltipPopup, useTooltip, TooltipContent };
Doing this, we'd open up access to adjust the portal directly in a developer's custom tooltip however desired without adjusting the Tooltip's API. Following the lead of the tooltip demos in the documentation using the lower level API, you could create something like this: import * as React from "react";
import { useTooltip, TooltipContent } from "@reach/tooltip";
import type { TooltipProps } from "@reach/tooltip";
import Portal from "@reach/portal";
import "@reach/tooltip/styles.css";
interface CustomTooltipProps extends TooltipProps {
containerRef?: React.RefObject<Node>;
}
function CustomTooltip({
children,
containerRef,
...props
}: CustomTooltipProps) {
const [trigger, tooltip] = useTooltip();
return (
<React.Fragment>
{React.cloneElement(children as any, trigger)}
{tooltip.isVisible && (
<Portal containerRef={containerRef}>
<TooltipContent {...tooltip} {...props} />
</Portal>
)}
</React.Fragment>
);
} |
I would like to see this added also to the "dialog" and "popover" (besides "tooltip") libraries in reach. It was actually the original intent for |
Hey @indiesquidge! I wanted to check back in to determine the best path forward. It sounds like @Warsaken agrees with this update. Would it be possible to have this PR considered for approval? |
@indiesquidge, is there an eta for when this PR will get shipped? Would be a great update. |
@gfohl Do you mind rebasing against the up-to-date branch? I've updated the repo structure a bit and moved examples into a separate |
On second thought, I'm going to close this for the same reason I closed #901 (comment). Instead of a prop, I'd encourage composition. We already provide low-level access to the tooltip internals via |
I have created an example of a custom tooltip implementation with a |
Add optional containerRef to Portal inside Tooltip.
Before
In full-screen, the reach-portal element existed but was not visible:
After
By adding the target container to the Portal, the tooltip is now visible in full-screen
yarn test
).yarn start
).This pull request: