-
Notifications
You must be signed in to change notification settings - Fork 723
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
new(vx-tooltip): add useTooltipInPortal #756
Conversation
<TooltipWrapper> | ||
<TooltipComponent | ||
key={Math.random()} // needed for bounds to update correctly | ||
left={(tooltipLeft ?? 0) + (detectBounds ? 0 : 10)} |
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.
noting that we got to remove this conditional 10
by making the Tooltip
APIs consistent.
LGTM. I recently started using Should we consider using I know we just added support for a import React from 'react';
import useMeasure, { Options, RectReadOnly } from 'react-use-measure';
type MeasureProps = Options & {
children: (bounds: RectReadOnly) => React.ReactNode;
viewport?: boolean;
};
function Measure(props: MeasureProps) {
const { children, viewport, ...options } = props;
let [ref, bounds] = useMeasure({ debounce: 300, ...options });
if (viewport) {
// See note about scrolling position: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
bounds = {
...bounds,
left: bounds.left + window.scrollX,
top: bounds.top + window.scrollY,
x: bounds.x + window.scrollX,
y: bounds.y + window.scrollY
};
}
return <div ref={ref}>{children(bounds)}</div>;
}
export default Measure; |
yeah I think updating |
gonna merge this into the parent branch (not master) |
💥 Breaking Changes
🚀 Enhancements
📝 Documentation
This PR is into #755 and
userTooltipInPortal
hook to addresses the issue ofPortal
not being easy to use by lib consumers. Notes:react-use-measure
dependency for the robust bounds logicreact-use-measure
relies onResizeObserver
. rather than adding the polyfill here like we do in@vx/responsive
, I'm opting to just expose theuseMeasure
polyfill injection system. So, users can add it themselves towindow
or pass it in directly to the hook. I've noted this in theReadme
.tooltip
demo added in new(vx-tooltip): add Portal + demo #755 to use this hook instead ofPortal
+react-use-measure
vx-tooltip
Readme to includeuseTooltipInPortal
andPortal
barstack
example to useuseTooltipInPortal
as a validation point withinsvg
soffsetLeft/Top
toTooltipProps
, makingTooltipProps === TooltipWithBoundsProps
. This simplifies type checking in the newuseTooltipInPortal
, and is a breaking change forTooltip
as it will add10px
of padding to theTooltip
left/top.Using
userTooltipInPortal
TODO
react-use-measure
dep invx-demo
@hshoff @kristw @ktmud @techniq