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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tooltip): correct positioning when unstyled is applied #831

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 7 additions & 3 deletions packages/visx-tooltip/src/tooltips/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export type TooltipProps = {
};

export const defaultStyles: React.CSSProperties = {
position: 'absolute',
backgroundColor: 'white',
color: '#666666',
padding: '.3rem .5rem',
Expand All @@ -39,8 +38,13 @@ 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,
// these styles are needed for correct positioning, regardless of styles
position: 'absolute',
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
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