Skip to content

Commit

Permalink
Do not render empty tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
gregaubert authored and SonarTech committed May 24, 2018
1 parent 4feaaa4 commit 4c9d0c7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/sonar-web/src/main/js/components/controls/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ function isMeasured(state: State): state is OwnState & Measurements {
}

export default function Tooltip(props: Props) {
// allows to pass `undefined` to `overlay` to avoid rendering a tooltip
// can useful in some cases to render the tooltip conditionally
return props.overlay !== undefined ? <TooltipInner {...props} /> : props.children;
// overlay is a ReactNode, so it can be `undefined` or `null`
// this allows to easily render a tooltip conditionally
// more generaly we avoid rendering empty tooltips
return props.overlay != null && props.overlay !== '' ? (
<TooltipInner {...props} />
) : (
props.children
);
}

export class TooltipInner extends React.Component<Props, State> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,20 @@ it('should not render tooltip without overlay', () => {
);
expect(wrapper.type()).toBe('div');
});

it('should not render empty tooltips', () => {
expect(
shallow(
<Tooltip overlay={undefined} visible={true}>
<div id="tooltip" />
</Tooltip>
)
).toMatchSnapshot();
expect(
shallow(
<Tooltip overlay="" visible={true}>
<div id="tooltip" />
</Tooltip>
)
).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should not render empty tooltips 1`] = `
<div
id="tooltip"
/>
`;

exports[`should not render empty tooltips 2`] = `
<div
id="tooltip"
/>
`;

exports[`should open & close 1`] = `
<React.Fragment>
<div
Expand Down

0 comments on commit 4c9d0c7

Please sign in to comment.