Skip to content

Commit

Permalink
fix TooltipWithBounds positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
heyanurag committed Oct 3, 2020
1 parent b73303e commit dde3480
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/visx-tooltip/src/tooltips/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ export default function Tooltip({
<div
className={cx('visx-tooltip', className)}
style={{
top: top == null || offsetTop == null ? top : top + offsetTop,
left: left == null || offsetLeft == null ? left : left + offsetLeft,
left: 0,
top: 0,
transform: `translate(${left == null || offsetLeft == null ? left : left + offsetLeft}px, ${
top == null || offsetTop == null ? top : top + offsetTop
}px)`,
...(!unstyled && style),
}}
{...restProps}
Expand Down
12 changes: 6 additions & 6 deletions packages/visx-tooltip/src/tooltips/TooltipWithBounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ function TooltipWithBounds({

return (
<Tooltip
style={{
top: 0,
left: 0,
transform: `translate(${left}px, ${top}px)`,
...(!unstyled && style),
}}
top={top}
left={left}
offsetTop={0}
offsetLeft={0}
style={style}
unstyled={unstyled}
{...otherProps}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion packages/visx-tooltip/test/TooltipWithBounds.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<TooltipWithBounds />', () => {
const wrapper = shallow(<TooltipWithBounds unstyled>Hello</TooltipWithBounds>, {
disableLifecycleMethods: true,
}).dive();
const styles = wrapper.find('Tooltip').props().style as any;
const styles = wrapper.find('Tooltip').dive().find('.visx-tooltip').props().style as any;
Object.keys(defaultStyles).forEach(key => {
expect(styles[key]).toBeUndefined();
});
Expand Down

0 comments on commit dde3480

Please sign in to comment.