Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TooltipWithBounds positioning #828

Merged
merged 5 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)`,
heyanurag marked this conversation as resolved.
Show resolved Hide resolved
...(!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