Skip to content

Commit

Permalink
update xychart Tooltip to pass zIndex prop to useTooltipInPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
kangaechigai committed Sep 20, 2021
1 parent 7ad9260 commit 34abd9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/visx-xychart/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type TooltipProps<Datum extends object> = {
*/
resizeObserverPolyfill?: UseTooltipPortalOptions['polyfill'];
} & Omit<BaseTooltipProps, 'left' | 'top' | 'children'> &
Pick<UseTooltipPortalOptions, 'debounce' | 'detectBounds' | 'scroll'>;
Pick<UseTooltipPortalOptions, 'debounce' | 'detectBounds' | 'scroll' | 'zIndex'>;

const INVISIBLE_STYLES: React.CSSProperties = {
position: 'absolute',
Expand Down Expand Up @@ -122,6 +122,7 @@ function TooltipInner<Datum extends object>({
snapTooltipToDatumX = false,
snapTooltipToDatumY = false,
verticalCrosshairStyle,
zIndex,
...tooltipProps
}: TooltipProps<Datum>) {
const { colorScale, theme, innerHeight, innerWidth, margin, xScale, yScale, dataRegistry } =
Expand All @@ -132,6 +133,7 @@ function TooltipInner<Datum extends object>({
detectBounds,
polyfill: resizeObserverPolyfill,
scroll,
zIndex,
});

// To correctly position itself in a Portal, the tooltip must know its container bounds
Expand Down
9 changes: 9 additions & 0 deletions packages/visx-xychart/test/components/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,13 @@ describe('<Tooltip />', () => {
});
expect(container?.parentNode?.querySelectorAll('div.visx-tooltip-glyph')).toHaveLength(2);
});

it("should pass zIndex prop to Portal", () => {
const { container } = setup({
props: { zIndex: 123 },
context: { tooltipOpen: true },
});
const zIndex = container?.parentNode?.querySelector('div.visx-tooltip')?.parentElement?.style.zIndex;
expect(zIndex).toBe("123");
});
});

0 comments on commit 34abd9d

Please sign in to comment.