]> source.dussan.org Git - sonarqube.git/commitdiff
Do not render empty tooltips
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 22 May 2018 15:01:56 +0000 (17:01 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 24 May 2018 18:20:48 +0000 (20:20 +0200)
server/sonar-web/src/main/js/components/controls/Tooltip.tsx
server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx
server/sonar-web/src/main/js/components/controls/__tests__/__snapshots__/Tooltip-test.tsx.snap

index 14dfa11da66ad9682e0f1eb54575da2dc21d8416..17a017881b7524805cc0f4c04afdc02741cc271b 100644 (file)
@@ -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> {
index f0b1f65f86091d07ce05a08c2bcf7531318494c8..139a4c7b1be3a9055262c74186b764c03d099288 100644 (file)
@@ -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();
+});
index 4127f6e586e4f5086b995976bd9aa5e86f6b3b9d..6c0f293b850a3235746fa0a5394bc0017701350b 100644 (file)
@@ -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