@lumx/react 3.9.2-alpha.0 → 3.9.2-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_internal/ClickAwayProvider.js +2 -2
- package/_internal/ClickAwayProvider.js.map +1 -1
- package/index.d.ts +7 -1
- package/index.js +1726 -1672
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/date-picker/DatePickerControlled.tsx +52 -30
- package/src/components/image-lightbox/ImageLightbox.test.tsx +8 -1
- package/src/components/image-lightbox/useImageLightbox.tsx +20 -13
- package/src/components/popover/Popover.tsx +2 -2
- package/src/components/popover/constants.ts +5 -0
- package/src/components/popover/usePopoverStyle.tsx +1 -10
- package/src/components/text-field/TextField.tsx +3 -1
- package/src/components/tooltip/Tooltip.stories.tsx +5 -0
- package/src/components/tooltip/Tooltip.test.tsx +178 -70
- package/src/components/tooltip/Tooltip.tsx +39 -10
- package/src/components/tooltip/constants.ts +8 -0
- package/src/components/tooltip/useInjectTooltipRef.tsx +27 -21
- package/src/components/tooltip/useTooltipOpen.tsx +6 -3
- package/src/constants.ts +5 -0
- package/src/hooks/usePopper.ts +9 -0
- package/src/stories/generated/TextField/Demos.stories.tsx +1 -0
- package/src/utils/type.ts +0 -1
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.9.2-alpha.
|
|
10
|
-
"@lumx/icons": "^3.9.2-alpha.
|
|
9
|
+
"@lumx/core": "^3.9.2-alpha.10",
|
|
10
|
+
"@lumx/icons": "^3.9.2-alpha.10",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"jest-environment-jsdom": "29.1.2",
|
|
58
58
|
"react": "^17.0.2",
|
|
59
59
|
"react-dom": "^17.0.2",
|
|
60
|
-
"rollup": "2.
|
|
60
|
+
"rollup": "2.79.2",
|
|
61
61
|
"rollup-plugin-analyzer": "^3.3.0",
|
|
62
62
|
"rollup-plugin-babel": "^4.4.0",
|
|
63
63
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"build:storybook": "storybook build"
|
|
111
111
|
},
|
|
112
112
|
"sideEffects": false,
|
|
113
|
-
"version": "3.9.2-alpha.
|
|
113
|
+
"version": "3.9.2-alpha.10"
|
|
114
114
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { KeyboardEventHandler, forwardRef } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import { DatePickerProps, Emphasis, FlexBox, IconButton, Text, TextField, Toolbar } from '@lumx/react';
|
|
3
|
+
import { DatePickerProps, Emphasis, FlexBox, IconButton, Text, TextField, TextFieldProps, Toolbar } from '@lumx/react';
|
|
4
4
|
import { mdiChevronLeft, mdiChevronRight } from '@lumx/icons';
|
|
5
5
|
import { Comp } from '@lumx/react/utils/type';
|
|
6
6
|
import { getMonthCalendar } from '@lumx/react/utils/date/getMonthCalendar';
|
|
@@ -61,36 +61,58 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
61
61
|
return getMonthCalendar(localeObj, selectedMonth, minDate, maxDate);
|
|
62
62
|
}, [locale, minDate, maxDate, selectedMonth]);
|
|
63
63
|
|
|
64
|
-
const selectedYear = selectedMonth.
|
|
65
|
-
const
|
|
66
|
-
const
|
|
64
|
+
const selectedYear = selectedMonth.getFullYear();
|
|
65
|
+
const formattedYear = selectedMonth.toLocaleDateString(locale, { year: 'numeric' }).slice(0, 4);
|
|
66
|
+
const [currentYear, setCurrentYear] = React.useState(String(selectedYear));
|
|
67
67
|
|
|
68
68
|
// Updates month offset when validating year. Adds or removes 12 months per year when updating year value.
|
|
69
|
-
const updateMonthOffset = React.useCallback(
|
|
70
|
-
|
|
71
|
-
const yearNumber =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
onMonthChange(addMonthResetDay(selectedMonth, offset));
|
|
69
|
+
const updateMonthOffset = React.useCallback(
|
|
70
|
+
(newYearValue: string) => {
|
|
71
|
+
const yearNumber = Number(newYearValue);
|
|
72
|
+
if (yearNumber < 0 && yearNumber >= 9999) {
|
|
73
|
+
return;
|
|
75
74
|
}
|
|
76
|
-
}
|
|
77
|
-
}, [isYearValid, selectedMonth, textFieldYearValue, onMonthChange]);
|
|
78
75
|
|
|
79
|
-
|
|
76
|
+
const previousYearNumber = selectedMonth.getFullYear();
|
|
77
|
+
const offset = (yearNumber - previousYearNumber) * 12;
|
|
78
|
+
onMonthChange?.(addMonthResetDay(selectedMonth, offset));
|
|
79
|
+
},
|
|
80
|
+
[selectedMonth, onMonthChange],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const onYearChange = React.useCallback<TextFieldProps['onChange']>(
|
|
84
|
+
(newYearValue, _, event) => {
|
|
85
|
+
setCurrentYear(newYearValue);
|
|
80
86
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
// Detect if change is coming from the spin up/down arrows
|
|
88
|
+
const inputType = (event?.nativeEvent as any)?.inputType;
|
|
89
|
+
if (
|
|
90
|
+
// Chrome/Safari
|
|
91
|
+
!inputType ||
|
|
92
|
+
// Firefox
|
|
93
|
+
inputType === 'insertReplacementText'
|
|
94
|
+
) {
|
|
95
|
+
updateMonthOffset(newYearValue);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
84
98
|
[updateMonthOffset],
|
|
85
99
|
);
|
|
86
100
|
|
|
87
|
-
|
|
101
|
+
const updateYear = React.useCallback(() => {
|
|
102
|
+
updateMonthOffset(currentYear);
|
|
103
|
+
}, [updateMonthOffset, currentYear]);
|
|
104
|
+
|
|
105
|
+
const updateYearOnEnterPressed: KeyboardEventHandler = React.useMemo(
|
|
106
|
+
() => onEnterPressed(updateYear),
|
|
107
|
+
[updateYear],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const monthYear = selectedMonth.toLocaleDateString(locale, { year: 'numeric', month: 'long' });
|
|
111
|
+
|
|
112
|
+
// Update current year when selected year changes
|
|
88
113
|
React.useEffect(() => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
93
|
-
}, [selectedMonth]);
|
|
114
|
+
setCurrentYear(String(selectedYear));
|
|
115
|
+
}, [selectedYear]);
|
|
94
116
|
|
|
95
117
|
const prevSelectedMonth = usePreviousValue(selectedMonth);
|
|
96
118
|
const monthHasChanged = prevSelectedMonth && !isSameDay(selectedMonth, prevSelectedMonth);
|
|
@@ -101,7 +123,7 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
101
123
|
if (monthHasChanged) setLabelAriaLive('polite');
|
|
102
124
|
}, [monthHasChanged]);
|
|
103
125
|
|
|
104
|
-
const
|
|
126
|
+
const yearLabel = getYearDisplayName(locale);
|
|
105
127
|
|
|
106
128
|
return (
|
|
107
129
|
<div ref={ref} className={`${CLASSNAME}`}>
|
|
@@ -137,21 +159,21 @@ export const DatePickerControlled: Comp<DatePickerControlledProps, HTMLDivElemen
|
|
|
137
159
|
vAlign="center"
|
|
138
160
|
dir="auto"
|
|
139
161
|
>
|
|
140
|
-
{RegExp(`(.*)(${
|
|
162
|
+
{RegExp(`(.*)(${formattedYear})(.*)`)
|
|
141
163
|
.exec(monthYear)
|
|
142
164
|
?.slice(1)
|
|
143
165
|
.filter((part) => part !== '')
|
|
144
166
|
.map((part) =>
|
|
145
|
-
part ===
|
|
167
|
+
part === formattedYear ? (
|
|
146
168
|
<TextField
|
|
147
|
-
value={
|
|
148
|
-
aria-label={
|
|
149
|
-
onChange={
|
|
169
|
+
value={currentYear}
|
|
170
|
+
aria-label={yearLabel}
|
|
171
|
+
onChange={onYearChange}
|
|
150
172
|
type="number"
|
|
151
173
|
max={9999}
|
|
152
174
|
min={0}
|
|
153
|
-
onBlur={
|
|
154
|
-
onKeyPress={
|
|
175
|
+
onBlur={updateYear}
|
|
176
|
+
onKeyPress={updateYearOnEnterPressed}
|
|
155
177
|
key="year"
|
|
156
178
|
className={`${CLASSNAME}__year`}
|
|
157
179
|
/>
|
|
@@ -145,11 +145,18 @@ describe(`<${ImageLightbox.displayName}>`, () => {
|
|
|
145
145
|
|
|
146
146
|
// Focus moved to the close button
|
|
147
147
|
const imageLightbox = queries.getImageLightbox();
|
|
148
|
-
|
|
148
|
+
const closeButton = queries.queryCloseButton(imageLightbox);
|
|
149
|
+
expect(closeButton).toHaveFocus();
|
|
150
|
+
const tooltip = screen.getByRole('tooltip', { name: 'Close' });
|
|
151
|
+
expect(tooltip).toBeInTheDocument();
|
|
149
152
|
|
|
150
153
|
// Image lightbox opened on the correct image
|
|
151
154
|
expect(queries.queryImage(imageLightbox, 'Image 2')).toBeInTheDocument();
|
|
152
155
|
|
|
156
|
+
// Close tooltip
|
|
157
|
+
await userEvent.keyboard('{escape}');
|
|
158
|
+
expect(tooltip).not.toBeInTheDocument();
|
|
159
|
+
|
|
153
160
|
// Close on escape
|
|
154
161
|
await userEvent.keyboard('{escape}');
|
|
155
162
|
expect(imageLightbox).not.toBeInTheDocument();
|
|
@@ -41,13 +41,12 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
41
41
|
const propsRef = React.useRef(props);
|
|
42
42
|
|
|
43
43
|
React.useEffect(() => {
|
|
44
|
-
|
|
45
|
-
if (newProps?.images) {
|
|
46
|
-
newProps.images = newProps.images.map((image) => ({ imgRef: React.createRef(), ...image }));
|
|
47
|
-
}
|
|
48
|
-
propsRef.current = newProps;
|
|
44
|
+
propsRef.current = props;
|
|
49
45
|
}, [props]);
|
|
50
46
|
|
|
47
|
+
// Keep reference for each image elements
|
|
48
|
+
const imageRefsRef = React.useRef<Array<React.RefObject<HTMLImageElement>>>([]);
|
|
49
|
+
|
|
51
50
|
const currentImageRef = React.useRef<HTMLImageElement>(null);
|
|
52
51
|
const [imageLightboxProps, setImageLightboxProps] = React.useState(
|
|
53
52
|
() => ({ ...EMPTY_PROPS, ...props }) as ManagedProps & P,
|
|
@@ -61,8 +60,8 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
61
60
|
if (!currentImage) {
|
|
62
61
|
return;
|
|
63
62
|
}
|
|
64
|
-
const currentIndex =
|
|
65
|
-
(
|
|
63
|
+
const currentIndex = imageRefsRef.current.findIndex(
|
|
64
|
+
(imageRef) => imageRef.current === currentImage,
|
|
66
65
|
) as number;
|
|
67
66
|
|
|
68
67
|
await startViewTransition({
|
|
@@ -83,12 +82,20 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
83
82
|
// If we find an image inside the trigger, animate it in transition with the opening image
|
|
84
83
|
const triggerImage = triggerImageRefs[activeImageIndex as any]?.current || findImage(triggerElement);
|
|
85
84
|
|
|
86
|
-
// Inject
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
// Inject refs to improve transition and loading style
|
|
86
|
+
const images = propsRef.current?.images?.map((image, idx) => {
|
|
87
|
+
// Get or create image reference
|
|
88
|
+
let imgRef = imageRefsRef.current[idx];
|
|
89
|
+
if (!imgRef) {
|
|
90
|
+
imgRef = React.createRef();
|
|
91
|
+
imageRefsRef.current[idx] = imgRef;
|
|
90
92
|
}
|
|
91
|
-
|
|
93
|
+
|
|
94
|
+
// Try to use the trigger image as the loading placeholder
|
|
95
|
+
const loadingPlaceholderImageRef =
|
|
96
|
+
triggerImage && idx === activeImageIndex ? { current: triggerImage } : undefined;
|
|
97
|
+
|
|
98
|
+
return { loadingPlaceholderImageRef, ...image, imgRef };
|
|
92
99
|
});
|
|
93
100
|
|
|
94
101
|
await startViewTransition({
|
|
@@ -104,7 +111,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
104
111
|
close();
|
|
105
112
|
prevProps?.onClose?.();
|
|
106
113
|
},
|
|
107
|
-
images
|
|
114
|
+
images,
|
|
108
115
|
activeImageIndex: activeImageIndex || 0,
|
|
109
116
|
}));
|
|
110
117
|
},
|
|
@@ -15,7 +15,7 @@ import { skipRender } from '@lumx/react/utils/skipRender';
|
|
|
15
15
|
|
|
16
16
|
import { useRestoreFocusOnClose } from './useRestoreFocusOnClose';
|
|
17
17
|
import { usePopoverStyle } from './usePopoverStyle';
|
|
18
|
-
import { Elevation, FitAnchorWidth, Offset, Placement } from './constants';
|
|
18
|
+
import { Elevation, FitAnchorWidth, Offset, Placement, POPOVER_ZINDEX } from './constants';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Defines the props of the component.
|
|
@@ -88,7 +88,7 @@ const DEFAULT_PROPS: Partial<PopoverProps> = {
|
|
|
88
88
|
placement: Placement.AUTO,
|
|
89
89
|
focusAnchorOnClose: true,
|
|
90
90
|
usePortal: true,
|
|
91
|
-
zIndex:
|
|
91
|
+
zIndex: POPOVER_ZINDEX,
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
/** Method to render the popover inside a portal if usePortal is true */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { usePopper } from 'react-popper';
|
|
3
2
|
import memoize from 'lodash/memoize';
|
|
4
3
|
import { detectOverflow } from '@popperjs/core';
|
|
5
4
|
|
|
6
5
|
import { DOCUMENT, WINDOW } from '@lumx/react/constants';
|
|
7
6
|
import { PopoverProps } from '@lumx/react/components/popover/Popover';
|
|
7
|
+
import { usePopper } from '@lumx/react/hooks/usePopper';
|
|
8
8
|
import { ARROW_SIZE, FitAnchorWidth, Placement } from './constants';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -104,12 +104,6 @@ export function usePopoverStyle({
|
|
|
104
104
|
}: Options): Output {
|
|
105
105
|
const [popperElement, setPopperElement] = useState<null | HTMLElement>(null);
|
|
106
106
|
|
|
107
|
-
if (navigator.userAgent.includes('jsdom')) {
|
|
108
|
-
// Skip all logic; we don't need popover positioning in jsdom.
|
|
109
|
-
return { styles: {}, attributes: {}, isPositioned: true, popperElement, setPopperElement };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
113
107
|
const [arrowElement, setArrowElement] = useState<null | HTMLElement>(null);
|
|
114
108
|
|
|
115
109
|
const actualOffset: [number, number] = [offset?.along ?? 0, (offset?.away ?? 0) + (hasArrow ? ARROW_SIZE : 0)];
|
|
@@ -142,16 +136,13 @@ export function usePopoverStyle({
|
|
|
142
136
|
);
|
|
143
137
|
}
|
|
144
138
|
|
|
145
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
146
139
|
const { styles, attributes, state, update } = usePopper(anchorRef.current, popperElement, { placement, modifiers });
|
|
147
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
148
140
|
useEffect(() => {
|
|
149
141
|
update?.();
|
|
150
142
|
}, [children, update]);
|
|
151
143
|
|
|
152
144
|
const position = state?.placement ?? placement;
|
|
153
145
|
|
|
154
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
155
146
|
const popoverStyle = useMemo(() => {
|
|
156
147
|
const newStyles = { ...style, ...styles.popper, zIndex };
|
|
157
148
|
|
|
@@ -68,6 +68,8 @@ export interface TextFieldProps extends GenericProps, HasTheme {
|
|
|
68
68
|
placeholder?: string;
|
|
69
69
|
/** Reference to the wrapper. */
|
|
70
70
|
textFieldRef?: Ref<HTMLDivElement>;
|
|
71
|
+
/** Native input type (only when `multiline` is disabled). */
|
|
72
|
+
type?: React.ComponentProps<'input'>['type'];
|
|
71
73
|
/** Value. */
|
|
72
74
|
value?: string;
|
|
73
75
|
/** On blur callback. */
|
|
@@ -160,7 +162,7 @@ interface InputNativeProps {
|
|
|
160
162
|
maxLength?: number;
|
|
161
163
|
placeholder?: string;
|
|
162
164
|
rows: number;
|
|
163
|
-
type:
|
|
165
|
+
type: TextFieldProps['type'];
|
|
164
166
|
name?: string;
|
|
165
167
|
value?: string;
|
|
166
168
|
setFocus(focus: boolean): void;
|
|
@@ -2,8 +2,10 @@ import { Button, Dialog, Dropdown, Placement, Tooltip } from '@lumx/react';
|
|
|
2
2
|
import React, { useState } from 'react';
|
|
3
3
|
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
4
4
|
import { withChromaticForceScreenSize } from '@lumx/react/stories/decorators/withChromaticForceScreenSize';
|
|
5
|
+
import { ARIA_LINK_MODES } from '@lumx/react/components/tooltip/constants';
|
|
5
6
|
|
|
6
7
|
const placements = [Placement.TOP, Placement.BOTTOM, Placement.RIGHT, Placement.LEFT];
|
|
8
|
+
const CLOSE_MODES = ['hide', 'unmount'];
|
|
7
9
|
|
|
8
10
|
export default {
|
|
9
11
|
title: 'LumX components/tooltip/Tooltip',
|
|
@@ -11,6 +13,9 @@ export default {
|
|
|
11
13
|
args: Tooltip.defaultProps,
|
|
12
14
|
argTypes: {
|
|
13
15
|
placement: getSelectArgType(placements),
|
|
16
|
+
children: { control: false },
|
|
17
|
+
closeMode: { control: { type: 'inline-radio' }, options: CLOSE_MODES },
|
|
18
|
+
ariaLinkMode: { control: { type: 'inline-radio' }, options: ARIA_LINK_MODES },
|
|
14
19
|
},
|
|
15
20
|
decorators: [
|
|
16
21
|
// Force minimum chromatic screen size to make sure the dialog appears in view.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { Button
|
|
4
|
-
import { screen, render
|
|
3
|
+
import { Button } from '@lumx/react';
|
|
4
|
+
import { screen, render } from '@testing-library/react';
|
|
5
5
|
import { queryAllByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
6
|
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
7
7
|
import userEvent from '@testing-library/user-event';
|
|
@@ -48,27 +48,20 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
48
48
|
forceOpen: true,
|
|
49
49
|
});
|
|
50
50
|
expect(tooltip).toBeInTheDocument();
|
|
51
|
+
// Default placement
|
|
52
|
+
expect(tooltip).toHaveAttribute('data-popper-placement', 'bottom');
|
|
51
53
|
expect(anchorWrapper).toBeInTheDocument();
|
|
52
|
-
expect(anchorWrapper).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
it('should
|
|
56
|
-
const {
|
|
56
|
+
it('should render with custom placement', async () => {
|
|
57
|
+
const { tooltip } = await setup({
|
|
57
58
|
label: 'Tooltip label',
|
|
58
59
|
children: 'Anchor',
|
|
59
|
-
forceOpen:
|
|
60
|
-
|
|
61
|
-
expect(anchorWrapper).not.toHaveAttribute('aria-describedby');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should not wrap Button and not add aria-describedby when closed', async () => {
|
|
65
|
-
await setup({
|
|
66
|
-
label: 'Tooltip label',
|
|
67
|
-
children: <Button>Anchor</Button>,
|
|
68
|
-
forceOpen: false,
|
|
60
|
+
forceOpen: true,
|
|
61
|
+
placement: 'top',
|
|
69
62
|
});
|
|
70
|
-
|
|
71
|
-
expect(
|
|
63
|
+
// Custom placement
|
|
64
|
+
expect(tooltip).toHaveAttribute('data-popper-placement', 'top');
|
|
72
65
|
});
|
|
73
66
|
|
|
74
67
|
it('should not wrap Button', async () => {
|
|
@@ -83,35 +76,6 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
83
76
|
expect(button).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
84
77
|
});
|
|
85
78
|
|
|
86
|
-
it('should not add aria-describedby if button label is the same as tooltip label', async () => {
|
|
87
|
-
const label = 'Tooltip label';
|
|
88
|
-
render(<IconButton label={label} tooltipProps={{ forceOpen: true }} />);
|
|
89
|
-
const tooltip = screen.queryByRole('tooltip', { name: label });
|
|
90
|
-
expect(tooltip).toBeInTheDocument();
|
|
91
|
-
const button = screen.queryByRole('button', { name: label });
|
|
92
|
-
expect(button).not.toHaveAttribute('aria-describedby');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should keep anchor aria-describedby if button label is the same as tooltip label', async () => {
|
|
96
|
-
const label = 'Tooltip label';
|
|
97
|
-
render(<IconButton label={label} aria-describedby=":header-1:" tooltipProps={{ forceOpen: true }} />);
|
|
98
|
-
const tooltip = screen.queryByRole('tooltip', { name: label });
|
|
99
|
-
expect(tooltip).toBeInTheDocument();
|
|
100
|
-
const button = screen.queryByRole('button', { name: label });
|
|
101
|
-
expect(button).toHaveAttribute('aria-describedby', ':header-1:');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should concat aria-describedby if already exists', async () => {
|
|
105
|
-
const { tooltip } = await setup({
|
|
106
|
-
label: 'Tooltip label',
|
|
107
|
-
children: <Button aria-describedby=":header-1:">Anchor</Button>,
|
|
108
|
-
forceOpen: true,
|
|
109
|
-
});
|
|
110
|
-
expect(tooltip).toBeInTheDocument();
|
|
111
|
-
const button = screen.queryByRole('button', { name: 'Anchor' });
|
|
112
|
-
expect(button).toHaveAttribute('aria-describedby', `:header-1: ${tooltip?.id}`);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
79
|
it('should wrap disabled Button', async () => {
|
|
116
80
|
const { tooltip, anchorWrapper } = await setup({
|
|
117
81
|
label: 'Tooltip label',
|
|
@@ -159,18 +123,166 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
159
123
|
expect(ref.current === element).toBe(true);
|
|
160
124
|
});
|
|
161
125
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
126
|
+
describe('closeMode="hide"', () => {
|
|
127
|
+
it('should not render with empty label', async () => {
|
|
128
|
+
const { tooltip, anchorWrapper } = await setup({
|
|
129
|
+
label: undefined,
|
|
130
|
+
forceOpen: true,
|
|
131
|
+
closeMode: 'hide',
|
|
132
|
+
});
|
|
133
|
+
expect(tooltip).not.toBeInTheDocument();
|
|
134
|
+
expect(anchorWrapper).not.toBeInTheDocument();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should render hidden', async () => {
|
|
138
|
+
const { tooltip } = await setup({
|
|
139
|
+
label: 'Tooltip label',
|
|
140
|
+
children: <Button>Anchor</Button>,
|
|
141
|
+
closeMode: 'hide',
|
|
142
|
+
forceOpen: false,
|
|
143
|
+
});
|
|
144
|
+
expect(tooltip).toBeInTheDocument();
|
|
145
|
+
expect(tooltip).toHaveClass('lumx-tooltip--is-hidden');
|
|
146
|
+
|
|
147
|
+
const anchor = screen.getByRole('button', { name: 'Anchor' });
|
|
148
|
+
await userEvent.hover(anchor);
|
|
149
|
+
expect(tooltip).not.toHaveClass('lumx-tooltip--is-hidden');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('ariaLinkMode="aria-describedby"', () => {
|
|
154
|
+
it('should add aria-describedby on anchor on open', async () => {
|
|
155
|
+
await setup({
|
|
156
|
+
label: 'Tooltip label',
|
|
157
|
+
forceOpen: false,
|
|
158
|
+
children: <Button aria-describedby=":description1:">Anchor</Button>,
|
|
159
|
+
});
|
|
160
|
+
const anchor = screen.getByRole('button', { name: 'Anchor' });
|
|
161
|
+
expect(anchor).toHaveAttribute('aria-describedby', ':description1:');
|
|
162
|
+
|
|
163
|
+
await userEvent.hover(anchor);
|
|
164
|
+
const tooltip = screen.queryByRole('tooltip');
|
|
165
|
+
expect(anchor).toHaveAttribute('aria-describedby', `:description1: ${tooltip?.id}`);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should always add aria-describedby on anchor with closeMode="hide"', async () => {
|
|
169
|
+
const { tooltip } = await setup({
|
|
170
|
+
label: 'Tooltip label',
|
|
171
|
+
forceOpen: false,
|
|
172
|
+
children: <Button aria-describedby=":description1:">Anchor</Button>,
|
|
173
|
+
closeMode: 'hide',
|
|
174
|
+
});
|
|
175
|
+
const anchor = screen.getByRole('button', { name: 'Anchor' });
|
|
176
|
+
expect(anchor).toHaveAttribute('aria-describedby', `:description1: ${tooltip?.id}`);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('should skip aria-describedby if anchor has label', async () => {
|
|
180
|
+
const { tooltip } = await setup({
|
|
181
|
+
label: 'Tooltip label',
|
|
182
|
+
forceOpen: true,
|
|
183
|
+
children: (
|
|
184
|
+
<Button aria-describedby=":description1:" aria-label="Tooltip label">
|
|
185
|
+
Anchor
|
|
186
|
+
</Button>
|
|
187
|
+
),
|
|
188
|
+
});
|
|
189
|
+
expect(tooltip).toBeInTheDocument();
|
|
190
|
+
expect(screen.getByRole('button')).toHaveAttribute('aria-describedby', `:description1:`);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should add aria-describedby on anchor wrapper on open', async () => {
|
|
194
|
+
const { anchorWrapper } = await setup({
|
|
195
|
+
label: 'Tooltip label',
|
|
196
|
+
forceOpen: false,
|
|
197
|
+
children: 'Anchor',
|
|
198
|
+
});
|
|
199
|
+
expect(anchorWrapper).not.toHaveAttribute('aria-describedby');
|
|
200
|
+
|
|
201
|
+
await userEvent.hover(anchorWrapper as any);
|
|
202
|
+
const tooltip = screen.queryByRole('tooltip');
|
|
203
|
+
expect(anchorWrapper).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should always add aria-describedby on anchor wrapper with closeMode="hide"', async () => {
|
|
207
|
+
const { tooltip, anchorWrapper } = await setup({
|
|
208
|
+
label: 'Tooltip label',
|
|
209
|
+
forceOpen: false,
|
|
210
|
+
children: 'Anchor',
|
|
211
|
+
closeMode: 'hide',
|
|
212
|
+
});
|
|
213
|
+
expect(anchorWrapper).toHaveAttribute('aria-describedby', `${tooltip?.id}`);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('ariaLinkMode="aria-labelledby"', () => {
|
|
218
|
+
it('should add aria-labelledby on anchor on open', async () => {
|
|
219
|
+
await setup({
|
|
220
|
+
label: 'Tooltip label',
|
|
221
|
+
forceOpen: false,
|
|
222
|
+
children: <Button aria-labelledby=":label1:">Anchor</Button>,
|
|
223
|
+
ariaLinkMode: 'aria-labelledby',
|
|
224
|
+
});
|
|
225
|
+
const anchor = screen.getByRole('button', { name: 'Anchor' });
|
|
226
|
+
expect(anchor).toHaveAttribute('aria-labelledby', ':label1:');
|
|
227
|
+
|
|
228
|
+
await userEvent.hover(anchor);
|
|
229
|
+
const tooltip = screen.queryByRole('tooltip');
|
|
230
|
+
expect(anchor).toHaveAttribute('aria-labelledby', `:label1: ${tooltip?.id}`);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should always add aria-labelledby on anchor with closeMode="hide"', async () => {
|
|
234
|
+
const label = 'Tooltip label';
|
|
235
|
+
const { tooltip } = await setup({
|
|
236
|
+
label,
|
|
237
|
+
forceOpen: false,
|
|
238
|
+
children: <Button aria-labelledby=":label1:">Anchor</Button>,
|
|
239
|
+
ariaLinkMode: 'aria-labelledby',
|
|
240
|
+
closeMode: 'hide',
|
|
241
|
+
});
|
|
242
|
+
const anchor = screen.queryByRole('button', { name: label });
|
|
243
|
+
expect(anchor).toBeInTheDocument();
|
|
244
|
+
expect(anchor).toHaveAttribute('aria-labelledby', `:label1: ${tooltip?.id}`);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('should skip aria-labelledby if anchor has label', async () => {
|
|
248
|
+
const { tooltip } = await setup({
|
|
249
|
+
label: 'Tooltip label',
|
|
250
|
+
forceOpen: true,
|
|
251
|
+
children: (
|
|
252
|
+
<Button aria-labelledby=":label1:" aria-label="Tooltip label">
|
|
253
|
+
Anchor
|
|
254
|
+
</Button>
|
|
255
|
+
),
|
|
256
|
+
ariaLinkMode: 'aria-labelledby',
|
|
257
|
+
});
|
|
258
|
+
expect(tooltip).toBeInTheDocument();
|
|
259
|
+
expect(screen.getByRole('button')).toHaveAttribute('aria-labelledby', `:label1:`);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should add aria-labelledby on anchor wrapper on open', async () => {
|
|
263
|
+
const { anchorWrapper } = await setup({
|
|
264
|
+
label: 'Tooltip label',
|
|
265
|
+
forceOpen: false,
|
|
266
|
+
children: 'Anchor',
|
|
267
|
+
ariaLinkMode: 'aria-labelledby',
|
|
268
|
+
});
|
|
269
|
+
expect(anchorWrapper).not.toHaveAttribute('aria-labelledby');
|
|
270
|
+
|
|
271
|
+
await userEvent.hover(anchorWrapper as any);
|
|
272
|
+
const tooltip = screen.queryByRole('tooltip');
|
|
273
|
+
expect(anchorWrapper).toHaveAttribute('aria-labelledby', tooltip?.id);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it('should always add aria-labelledby on anchor wrapper with closeMode="hide"', async () => {
|
|
277
|
+
const { tooltip, anchorWrapper } = await setup({
|
|
278
|
+
label: 'Tooltip label',
|
|
279
|
+
forceOpen: false,
|
|
280
|
+
children: 'Anchor',
|
|
281
|
+
ariaLinkMode: 'aria-labelledby',
|
|
282
|
+
closeMode: 'hide',
|
|
283
|
+
});
|
|
284
|
+
expect(anchorWrapper).toHaveAttribute('aria-labelledby', `${tooltip?.id}`);
|
|
167
285
|
});
|
|
168
|
-
screen.logTestingPlaygroundURL()
|
|
169
|
-
expect(tooltip).toBeInTheDocument();
|
|
170
|
-
expect(anchorWrapper).toBeInTheDocument();
|
|
171
|
-
expect(anchorWrapper).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
172
|
-
const button = screen.queryByRole('button', { name: 'Anchor' });
|
|
173
|
-
expect(button?.parentElement).toBe(anchorWrapper);
|
|
174
286
|
});
|
|
175
287
|
});
|
|
176
288
|
|
|
@@ -191,15 +303,13 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
191
303
|
// Tooltip opened
|
|
192
304
|
tooltip = await screen.findByRole('tooltip', { name: 'Tooltip label' });
|
|
193
305
|
expect(tooltip).toBeInTheDocument();
|
|
194
|
-
expect(button).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
195
306
|
|
|
196
307
|
// Un-hover anchor button
|
|
197
|
-
userEvent.unhover(button);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
});
|
|
308
|
+
await userEvent.unhover(button);
|
|
309
|
+
|
|
310
|
+
expect(button).not.toHaveFocus();
|
|
311
|
+
// Tooltip closed
|
|
312
|
+
expect(tooltip).not.toBeInTheDocument();
|
|
203
313
|
});
|
|
204
314
|
|
|
205
315
|
it('should activate on hover anchor and then tooltip', async () => {
|
|
@@ -226,12 +336,10 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
226
336
|
expect(button).toHaveAttribute('aria-describedby', tooltip?.id);
|
|
227
337
|
|
|
228
338
|
// Un-hover tooltip
|
|
229
|
-
userEvent.unhover(tooltip);
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
expect(tooltip).not.toBeInTheDocument();
|
|
234
|
-
});
|
|
339
|
+
await userEvent.unhover(tooltip);
|
|
340
|
+
expect(button).not.toHaveFocus();
|
|
341
|
+
// Tooltip closed
|
|
342
|
+
expect(tooltip).not.toBeInTheDocument();
|
|
235
343
|
});
|
|
236
344
|
|
|
237
345
|
it('should activate on anchor focus visible and close on escape', async () => {
|