Skip to content

Commit

Permalink
fix(TDOPS-5671): fix tooltip display when empty title (#4999)
Browse files Browse the repository at this point in the history
* fix(TDOPS-5671): fix tooltip display when empty title

* changeset

* improve accessibility
  • Loading branch information
Gbacc authored Nov 21, 2023
1 parent e798efb commit f43609c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-kings-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/design-system': patch
---

TDOPS-5671 - Fix Design System tooltip display in case of empty value
13 changes: 13 additions & 0 deletions packages/design-system/src/components/Tooltip/Tooltip.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable testing-library/prefer-screen-queries */

/* eslint-disable testing-library/await-async-queries */
import { Tooltip } from './Tooltip';

Expand All @@ -16,6 +17,18 @@ context('<Tooltip />', () => {
cy.findByTestId('my.tooltip').should('be.visible');
});

it('should not show a tooltip when empty title', () => {
cy.mount(
<Tooltip title="" data-testid="my.tooltip">
<button>button</button>
</Tooltip>,
);

cy.findByTestId('my.tooltip').should('not.exist');
cy.get('button').click();
cy.findByTestId('my.tooltip').should('not.exist');
});

it('Should be able to override baseId', () => {
const tooltipBaseId = 'base-id';
cy.mount(
Expand Down
30 changes: 16 additions & 14 deletions packages/design-system/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,25 @@ export const Tooltip = ({ id, children, title, placement = 'top', ...rest }: Too
children,
{
...getReferenceProps(),
'aria-describedby': safeId,
...(title && { 'aria-describedby': safeId }),
},
floating.refs.setReference,
)}
<FloatingPortal>
<div
{...getFloatingProps()}
id={safeId}
ref={floating.refs.setFloating}
className={styles.container}
style={{ display: isOpen ? 'block' : 'none', ...floating.floatingStyles }}
{...rest}
>
<FloatingArrow ref={arrowRef} context={floating.context} />
{title}
</div>
</FloatingPortal>
{!!title && (
<FloatingPortal>
<div
{...getFloatingProps()}
id={safeId}
ref={floating.refs.setFloating}
className={styles.container}
style={{ display: isOpen ? 'block' : 'none', ...floating.floatingStyles }}
{...rest}
>
<FloatingArrow ref={arrowRef} context={floating.context} />
{title}
</div>
</FloatingPortal>
)}
</>
);
};

0 comments on commit f43609c

Please sign in to comment.