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(TDOPS-5671): fix tooltip display when empty title #4999

Merged
merged 3 commits into from
Nov 21, 2023
Merged
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
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 && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no title, you will have a prop 'aria-describedby': safeId on the element, but no tooltip.
Not great for accessibility.

<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>
)}
</>
);
};
Loading