diff --git a/packages/visx-tooltip/src/tooltips/Tooltip.tsx b/packages/visx-tooltip/src/tooltips/Tooltip.tsx index 71f9445a2..b26209dce 100644 --- a/packages/visx-tooltip/src/tooltips/Tooltip.tsx +++ b/packages/visx-tooltip/src/tooltips/Tooltip.tsx @@ -2,13 +2,32 @@ import React from 'react'; import cx from 'classnames'; export type TooltipProps = { + /** Tooltip content. */ + children?: React.ReactNode; + /** Optional className to apply to the Tooltip in addition to `visx-tooltip`. */ + className?: string; + /** The `left` position of the Tooltip. */ left?: number; - top?: number; + /** Offset the `left` position of the Tooltip by this margin. */ offsetLeft?: number; + /** Offset the `top` position of the Tooltip by this margin. */ offsetTop?: number; - className?: string; + /** Styles to apply, unless `unstyled=true`. */ style?: React.CSSProperties; - children?: React.ReactNode; + /** The `top` position of the Tooltip. */ + top?: number; + /** + * Applies position: 'absolute' for tooltips to correctly position themselves + * when `unstyled=true`. In a future major release this will be the default behavior. + */ + applyPositionStyle?: boolean; + /** + * Whether to omit applying any style, except `left` / `top`. + * In most cases if this is `true` a developer must do one of the following + * for positioning to work correctly: + * - set `applyPositionStyle=true` + * - create a CSS selector like: `.visx-tooltip { position: 'absolute' }` + */ unstyled?: boolean; }; @@ -33,17 +52,16 @@ export default function Tooltip({ style = defaultStyles, children, unstyled = false, + applyPositionStyle = false, ...restProps }: TooltipProps & React.HTMLProps) { return (
& WithBoundingRectsProps; function TooltipWithBounds({ + children, + getRects, left: initialLeft = 0, - top: initialTop = 0, offsetLeft = 10, offsetTop = 10, - children, - rect: ownBounds, parentRect: parentBounds, - getRects, + rect: ownBounds, style = defaultStyles, + top: initialTop = 0, unstyled = false, ...otherProps }: TooltipWithBoundsProps) { @@ -44,12 +41,12 @@ function TooltipWithBounds({ return ( {children} diff --git a/packages/visx-tooltip/test/TooltipWithBounds.test.tsx b/packages/visx-tooltip/test/TooltipWithBounds.test.tsx index b7eaa53c7..ce7767f14 100644 --- a/packages/visx-tooltip/test/TooltipWithBounds.test.tsx +++ b/packages/visx-tooltip/test/TooltipWithBounds.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import React from 'react'; import { shallow } from 'enzyme'; import { TooltipWithBounds, defaultStyles } from '../src'; @@ -21,11 +22,7 @@ describe('', () => { const wrapper = shallow(Hello, { disableLifecycleMethods: true, }).dive(); - const styles = wrapper - .find('Tooltip') - .dive() - .find('.visx-tooltip') - .props().style as any; + const styles = wrapper.find('Tooltip').props().style as any; Object.keys(defaultStyles).forEach(key => { expect(styles[key]).toBeUndefined(); });