Skip to content

Commit f166e93

Browse files
committed
feat(tooltip): use standard visually-hidden class in closeMode=hide
1 parent f1e7683 commit f166e93

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `ImageLightbox`: fix closing transition triggering multiple times.
1313

14+
### Changed
15+
16+
- `Tooltip`: use the standard class `visually-hidden` when closed and with `closeMode="hide"`.
17+
1418
## [3.9.2][] - 2024-10-04
1519

1620
### Fixed

packages/lumx-core/src/scss/components/tooltip/_index.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
border-radius: var(--lumx-border-radius);
1818
will-change: transform;
1919

20-
&--is-hidden {
21-
visibility: hidden;
22-
}
23-
2420
&__arrow {
2521
position: absolute;
2622
width: 0;

packages/lumx-react/src/components/date-picker/DatePickerControlled.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import React from 'react';
33
import { render, screen, waitFor } from '@testing-library/react';
44
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
55
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6-
76
import userEvent from '@testing-library/user-event';
7+
import { VISUALLY_HIDDEN } from '@lumx/react/constants';
8+
89
import { DatePickerControlled, DatePickerControlledProps } from './DatePickerControlled';
910
import { CLASSNAME } from './constants';
1011

@@ -39,7 +40,7 @@ const queries = {
3940
screen.getByRole('spinbutton', {
4041
name: /année/i,
4142
}),
42-
getAccessibleMonthYear: (container: HTMLElement) => getByClassName(container, 'visually-hidden'),
43+
getAccessibleMonthYear: (container: HTMLElement) => getByClassName(container, VISUALLY_HIDDEN),
4344
};
4445

4546
describe(`<${DatePickerControlled.displayName}>`, () => {

packages/lumx-react/src/components/date-picker/DatePickerControlled.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getYearDisplayName } from '@lumx/react/utils/date/getYearDisplayName';
1313
import { onEnterPressed } from '@lumx/react/utils/event';
1414
import { addMonthResetDay } from '@lumx/react/utils/date/addMonthResetDay';
1515
import { formatDayNumber } from '@lumx/react/utils/date/formatDayNumber';
16+
import { VISUALLY_HIDDEN } from '@lumx/react/constants';
1617
import { CLASSNAME } from './constants';
1718

1819
/**
@@ -147,7 +148,7 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
147148
}
148149
label={
149150
<>
150-
<span aria-live={labelAriaLive} className={onMonthChange ? 'visually-hidden' : ''} dir="auto">
151+
<span aria-live={labelAriaLive} className={onMonthChange ? VISUALLY_HIDDEN : ''} dir="auto">
151152
{monthYear}
152153
</span>
153154
{onMonthChange && (
@@ -222,7 +223,7 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
222223
onClick={() => onChange(date)}
223224
>
224225
<span aria-hidden>{formatDayNumber(locale, date)}</span>
225-
<span className="visually-hidden">
226+
<span className={VISUALLY_HIDDEN}>
226227
{date.toLocaleDateString(locale, {
227228
day: 'numeric',
228229
month: 'long',

packages/lumx-react/src/components/tooltip/Tooltip.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { screen, render } from '@testing-library/react';
55
import { queryAllByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
66
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
77
import userEvent from '@testing-library/user-event';
8-
98
import { isFocusVisible } from '@lumx/react/utils/isFocusVisible';
9+
import { VISUALLY_HIDDEN } from '@lumx/react/constants';
10+
1011
import { Tooltip, TooltipProps } from './Tooltip';
1112

1213
const CLASSNAME = Tooltip.className as string;
@@ -142,11 +143,11 @@ describe(`<${Tooltip.displayName}>`, () => {
142143
forceOpen: false,
143144
});
144145
expect(tooltip).toBeInTheDocument();
145-
expect(tooltip).toHaveClass('lumx-tooltip--is-hidden');
146+
expect(tooltip).toHaveClass(VISUALLY_HIDDEN);
146147

147148
const anchor = screen.getByRole('button', { name: 'Anchor' });
148149
await userEvent.hover(anchor);
149-
expect(tooltip).not.toHaveClass('lumx-tooltip--is-hidden');
150+
expect(tooltip).not.toHaveClass(VISUALLY_HIDDEN);
150151
});
151152
});
152153

packages/lumx-react/src/components/tooltip/Tooltip.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createPortal } from 'react-dom';
44

55
import classNames from 'classnames';
66

7-
import { DOCUMENT } from '@lumx/react/constants';
7+
import { DOCUMENT, VISUALLY_HIDDEN } from '@lumx/react/constants';
88
import { Comp, GenericProps, HasCloseMode } from '@lumx/react/utils/type';
99
import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
1010
import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
@@ -106,6 +106,7 @@ export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, re
106106
const { isOpen: isActivated, onPopperMount } = useTooltipOpen(delay, anchorElement);
107107
const isOpen = (isActivated || forceOpen) && !!label;
108108
const isMounted = !!label && (isOpen || closeMode === 'hide');
109+
const isHidden = !isOpen && closeMode === 'hide';
109110
const wrappedChildren = useInjectTooltipRef({
110111
children,
111112
setAnchorElement,
@@ -139,8 +140,8 @@ export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, re
139140
handleBasicClasses({
140141
prefix: CLASSNAME,
141142
position,
142-
hidden: !isOpen && closeMode === 'hide',
143143
}),
144+
isHidden && VISUALLY_HIDDEN,
144145
)}
145146
style={{ ...styles.popper, zIndex }}
146147
{...attributes.popper}

packages/lumx-react/src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ export const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
2020
* Check if we are running in a true browser
2121
*/
2222
export const IS_BROWSER = typeof navigator !== 'undefined' && !navigator.userAgent.includes('jsdom');
23+
24+
/**
25+
* Visually hidden a11y utility class name
26+
*/
27+
export const VISUALLY_HIDDEN = 'visually-hidden';

0 commit comments

Comments
 (0)