Skip to content

Commit

Permalink
fix TooltipWithBounds positioning (#828)
Browse files Browse the repository at this point in the history
* remove line unstyled={unstyled} in TooltipWithBounds.tsx

* fix TooltipWithBounds positioning

* corrections for failing tests

* pass tests

Co-authored-by: Chris Williams <williaster@users.noreply.github.com>

* fix(Tooltip): add unit to translateY

Co-authored-by: Chris Williams <williaster@users.noreply.github.com>
  • Loading branch information
heyanurag and williaster authored Oct 7, 2020
1 parent e6abc6b commit 0dc7dec
Show file tree
Hide file tree
Showing 3 changed files with 15 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 ?? 0 : left + offsetLeft
}px, ${top == null || offsetTop == null ? top ?? 0 : top + offsetTop}px)`,
...(!unstyled && style),
}}
{...restProps}
Expand Down
11 changes: 5 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,11 @@ 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}
>
Expand Down
6 changes: 5 additions & 1 deletion packages/visx-tooltip/test/TooltipWithBounds.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ 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 0dc7dec

Please sign in to comment.