@lumx/react 3.20.1-alpha.3 → 3.20.1-alpha.4
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/index.js.map +1 -1
- package/index.d.ts +34 -35
- package/index.js +215 -212
- package/index.js.map +1 -1
- package/package.json +12 -10
- package/src/components/alert-dialog/AlertDialog.stories.tsx +1 -1
- package/src/components/alert-dialog/AlertDialog.test.tsx +4 -3
- package/src/components/autocomplete/Autocomplete.stories.tsx +1 -1
- package/src/components/autocomplete/Autocomplete.test.tsx +5 -3
- package/src/components/autocomplete/Autocomplete.tsx +1 -1
- package/src/components/autocomplete/AutocompleteMultiple.stories.tsx +1 -1
- package/src/components/autocomplete/AutocompleteMultiple.test.tsx +2 -0
- package/src/components/autocomplete/AutocompleteMultiple.tsx +1 -1
- package/src/components/avatar/Avatar.stories.tsx +2 -0
- package/src/components/avatar/Avatar.test.tsx +2 -0
- package/src/components/avatar/Avatar.tsx +1 -1
- package/src/components/badge/Badge.stories.tsx +1 -0
- package/src/components/badge/Badge.test.tsx +2 -0
- package/src/components/badge/Badge.tsx +1 -1
- package/src/components/badge/BadgeWrapper.stories.tsx +1 -0
- package/src/components/badge/BadgeWrapper.test.tsx +2 -0
- package/src/components/badge/BadgeWrapper.tsx +1 -1
- package/src/components/button/Button.stories.tsx +1 -0
- package/src/components/button/Button.test.tsx +11 -9
- package/src/components/button/Button.tsx +2 -0
- package/src/components/button/ButtonGroup.stories.tsx +2 -0
- package/src/components/button/ButtonGroup.test.tsx +2 -0
- package/src/components/button/ButtonGroup.tsx +2 -0
- package/src/components/button/ButtonRoot.tsx +37 -7
- package/src/components/button/IconButton.test.tsx +2 -0
- package/src/components/button/IconButton.tsx +2 -0
- package/src/components/checkbox/Checkbox.test.tsx +5 -3
- package/src/components/chip/Chip.stories.tsx +2 -0
- package/src/components/chip/Chip.test.tsx +19 -19
- package/src/components/chip/Chip.tsx +1 -1
- package/src/components/chip/ChipGroup.stories.tsx +2 -0
- package/src/components/chip/ChipGroup.test.tsx +2 -0
- package/src/components/chip/ChipGroup.tsx +1 -1
- package/src/components/comment-block/CommentBlock.stories.tsx +1 -0
- package/src/components/comment-block/CommentBlock.test.tsx +1 -0
- package/src/components/comment-block/CommentBlock.tsx +1 -1
- package/src/components/date-picker/DatePicker.test.tsx +5 -3
- package/src/components/date-picker/DatePicker.tsx +1 -1
- package/src/components/date-picker/DatePickerControlled.test.tsx +8 -6
- package/src/components/date-picker/DatePickerField.test.tsx +5 -3
- package/src/components/dialog/Dialog.test.tsx +6 -4
- package/src/components/divider/Divider.test.tsx +2 -0
- package/src/components/divider/Divider.tsx +2 -0
- package/src/components/drag-handle/DragHandle.test.tsx +2 -0
- package/src/components/drag-handle/DragHandle.tsx +2 -0
- package/src/components/dropdown/Dropdown.stories.tsx +1 -1
- package/src/components/dropdown/Dropdown.test.tsx +3 -3
- package/src/components/dropdown/Dropdown.tsx +1 -1
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +7 -6
- package/src/components/flag/Flag.test.tsx +2 -0
- package/src/components/flag/Flag.tsx +2 -0
- package/src/components/flex-box/FlexBox.stories.tsx +2 -0
- package/src/components/flex-box/FlexBox.test.tsx +1 -0
- package/src/components/flex-box/FlexBox.tsx +1 -1
- package/src/components/generic-block/GenericBlock.test.tsx +1 -1
- package/src/components/grid/Grid.tsx +2 -0
- package/src/components/grid/GridItem.tsx +2 -0
- package/src/components/grid-column/GridColumn.stories.tsx +1 -0
- package/src/components/grid-column/GridColumn.test.jsx +2 -0
- package/src/components/grid-column/GridColumn.tsx +1 -1
- package/src/components/heading/Heading.stories.tsx +1 -0
- package/src/components/heading/Heading.test.tsx +2 -0
- package/src/components/heading/Heading.tsx +2 -0
- package/src/components/heading/HeadingLevelProvider.tsx +1 -1
- package/src/components/icon/Icon.stories.tsx +4 -30
- package/src/components/icon/Icon.test.tsx +4 -85
- package/src/components/icon/Icon.tsx +2 -0
- package/src/components/image-block/ImageBlock.stories.tsx +2 -0
- package/src/components/image-block/ImageBlock.test.tsx +1 -0
- package/src/components/image-block/ImageBlock.tsx +1 -1
- package/src/components/image-block/ImageCaption.tsx +1 -1
- package/src/components/image-lightbox/ImageLightbox.stories.tsx +1 -0
- package/src/components/image-lightbox/ImageLightbox.test.tsx +9 -11
- package/src/components/image-lightbox/types.ts +2 -0
- package/src/components/inline-list/InlineList.stories.tsx +1 -0
- package/src/components/inline-list/InlineList.test.tsx +2 -0
- package/src/components/inline-list/InlineList.tsx +1 -1
- package/src/components/input-helper/InputHelper.test.tsx +2 -0
- package/src/components/input-helper/InputHelper.tsx +1 -1
- package/src/components/input-label/InputLabel.stories.tsx +2 -0
- package/src/components/input-label/InputLabel.test.tsx +2 -0
- package/src/components/input-label/InputLabel.tsx +1 -1
- package/src/components/lightbox/Lightbox.test.tsx +2 -0
- package/src/components/lightbox/Lightbox.tsx +1 -1
- package/src/components/link/Link.stories.tsx +1 -0
- package/src/components/link/Link.test.tsx +13 -13
- package/src/components/link/Link.tsx +22 -9
- package/src/components/link-preview/LinkPreview.test.tsx +2 -0
- package/src/components/link-preview/LinkPreview.tsx +2 -0
- package/src/components/list/List.stories.tsx +1 -1
- package/src/components/list/List.test.tsx +2 -0
- package/src/components/list/List.tsx +1 -1
- package/src/components/list/ListDivider.test.tsx +2 -0
- package/src/components/list/ListDivider.tsx +2 -0
- package/src/components/list/ListItem.test.tsx +7 -5
- package/src/components/list/ListItem.tsx +1 -1
- package/src/components/list/ListSubheader.test.tsx +2 -0
- package/src/components/list/ListSubheader.tsx +1 -1
- package/src/components/message/Message.test.tsx +2 -1
- package/src/components/message/Message.tsx +1 -1
- package/src/components/mosaic/Mosaic.test.tsx +5 -3
- package/src/components/mosaic/Mosaic.tsx +1 -1
- package/src/components/navigation/Navigation.stories.tsx +2 -0
- package/src/components/navigation/Navigation.test.tsx +2 -0
- package/src/components/navigation/Navigation.tsx +2 -0
- package/src/components/navigation/NavigationItem.test.tsx +2 -0
- package/src/components/navigation/NavigationItem.tsx +11 -7
- package/src/components/navigation/NavigationSection.test.tsx +2 -0
- package/src/components/navigation/NavigationSection.tsx +4 -5
- package/src/components/notification/Notification.test.tsx +5 -4
- package/src/components/notification/Notification.tsx +1 -1
- package/src/components/popover/Popover.test.tsx +2 -0
- package/src/components/popover/Popover.tsx +1 -1
- package/src/components/popover/usePopoverStyle.tsx +1 -1
- package/src/components/popover-dialog/PopoverDialog.test.tsx +2 -1
- package/src/components/popover-dialog/PopoverDialog.tsx +2 -0
- package/src/components/post-block/PostBlock.test.tsx +2 -0
- package/src/components/post-block/PostBlock.tsx +1 -1
- package/src/components/progress/Progress.tsx +2 -0
- package/src/components/progress/ProgressCircular.stories.tsx +1 -0
- package/src/components/progress/ProgressCircular.test.tsx +2 -0
- package/src/components/progress/ProgressCircular.tsx +2 -0
- package/src/components/progress/ProgressLinear.test.tsx +2 -0
- package/src/components/progress/ProgressLinear.tsx +2 -0
- package/src/components/progress-tracker/ProgressTracker.stories.tsx +1 -1
- package/src/components/progress-tracker/ProgressTracker.test.tsx +2 -0
- package/src/components/progress-tracker/ProgressTrackerProvider.test.tsx +2 -0
- package/src/components/progress-tracker/ProgressTrackerProvider.tsx +1 -1
- package/src/components/progress-tracker/ProgressTrackerStep.test.tsx +2 -0
- package/src/components/progress-tracker/ProgressTrackerStep.tsx +1 -1
- package/src/components/progress-tracker/ProgressTrackerStepPanel.test.tsx +2 -0
- package/src/components/progress-tracker/ProgressTrackerStepPanel.tsx +2 -0
- package/src/components/radio-button/RadioButton.test.tsx +5 -3
- package/src/components/radio-button/RadioButton.tsx +1 -1
- package/src/components/radio-button/RadioGroup.stories.tsx +1 -1
- package/src/components/radio-button/RadioGroup.test.tsx +2 -0
- package/src/components/radio-button/RadioGroup.tsx +1 -1
- package/src/components/select/Select.stories.tsx +1 -1
- package/src/components/select/Select.test.tsx +9 -8
- package/src/components/select/Select.tsx +1 -1
- package/src/components/select/SelectMultiple.stories.tsx +1 -1
- package/src/components/select/SelectMultiple.test.tsx +7 -5
- package/src/components/select/SelectMultiple.tsx +1 -1
- package/src/components/select/WithSelectContext.tsx +1 -1
- package/src/components/select/constants.ts +1 -1
- package/src/components/side-navigation/SideNavigation.test.tsx +2 -0
- package/src/components/side-navigation/SideNavigation.tsx +1 -1
- package/src/components/side-navigation/SideNavigationItem.test.tsx +4 -2
- package/src/components/side-navigation/SideNavigationItem.tsx +28 -23
- package/src/components/skeleton/SkeletonCircle.test.tsx +2 -0
- package/src/components/skeleton/SkeletonCircle.tsx +2 -0
- package/src/components/skeleton/SkeletonRectangle.test.tsx +2 -0
- package/src/components/skeleton/SkeletonRectangle.tsx +2 -0
- package/src/components/skeleton/SkeletonTypography.stories.tsx +2 -0
- package/src/components/skeleton/SkeletonTypography.test.tsx +2 -0
- package/src/components/skeleton/SkeletonTypography.tsx +1 -1
- package/src/components/slider/Slider.test.tsx +3 -1
- package/src/components/slider/Slider.tsx +1 -1
- package/src/components/slideshow/Slideshow.stories.tsx +1 -0
- package/src/components/slideshow/Slideshow.test.tsx +2 -0
- package/src/components/slideshow/SlideshowControls.stories.tsx +2 -0
- package/src/components/slideshow/SlideshowItem.tsx +2 -0
- package/src/components/slideshow/useSlideFocusManagement.tsx +1 -1
- package/src/components/switch/Switch.test.tsx +7 -5
- package/src/components/switch/Switch.tsx +1 -1
- package/src/components/table/Table.test.tsx +2 -0
- package/src/components/table/Table.tsx +2 -0
- package/src/components/table/TableBody.test.tsx +2 -0
- package/src/components/table/TableBody.tsx +2 -0
- package/src/components/table/TableCell.test.tsx +3 -1
- package/src/components/table/TableCell.tsx +2 -0
- package/src/components/table/TableHeader.test.tsx +2 -0
- package/src/components/table/TableHeader.tsx +2 -0
- package/src/components/table/TableRow.test.tsx +2 -0
- package/src/components/table/TableRow.tsx +2 -0
- package/src/components/tabs/Tab.test.tsx +2 -0
- package/src/components/tabs/Tab.tsx +1 -1
- package/src/components/tabs/TabList.test.tsx +2 -0
- package/src/components/tabs/TabPanel.test.tsx +2 -0
- package/src/components/tabs/TabPanel.tsx +2 -0
- package/src/components/tabs/TabProvider.test.tsx +2 -0
- package/src/components/tabs/TabProvider.tsx +1 -1
- package/src/components/tabs/Tabs.stories.tsx +1 -1
- package/src/components/text/Text.stories.tsx +1 -1
- package/src/components/text/Text.test.tsx +2 -0
- package/src/components/text/Text.tsx +2 -0
- package/src/components/text-field/TextField.test.tsx +10 -9
- package/src/components/text-field/TextField.tsx +1 -1
- package/src/components/thumbnail/Thumbnail.test.tsx +7 -29
- package/src/components/thumbnail/Thumbnail.tsx +11 -11
- package/src/components/toolbar/Toolbar.tsx +1 -1
- package/src/components/tooltip/Tooltip.stories.tsx +1 -2
- package/src/components/tooltip/Tooltip.test.tsx +8 -14
- package/src/components/uploader/Uploader.test.tsx +4 -2
- package/src/components/user-block/UserBlock.stories.tsx +2 -0
- package/src/components/user-block/UserBlock.test.tsx +3 -1
- package/src/hooks/useId.test.tsx +1 -0
- package/src/hooks/useInfiniteScroll.tsx +1 -1
- package/src/hooks/usePreviousValue.ts +1 -0
- package/src/stories/decorators/withChromaticForceScreenSize.tsx +1 -0
- package/src/stories/decorators/withNestedProps.tsx +1 -0
- package/src/stories/decorators/withThemedBackground.tsx +2 -0
- package/src/stories/decorators/withWrapper.tsx +2 -0
- package/src/stories/utils/CustomLink.tsx +1 -0
- package/src/testing/utils/ThemeSentinel.tsx +1 -0
- package/src/untypped-modules.d.ts +0 -4
- package/src/utils/ClickAwayProvider/ClickAwayProvider.stories.jsx +1 -1
- package/src/utils/ClickAwayProvider/ClickAwayProvider.tsx +1 -1
- package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +1 -1
- package/src/utils/Portal/Portal.test.tsx +1 -0
- package/src/utils/Portal/PortalProvider.stories.jsx +1 -0
- package/src/utils/Portal/PortalProvider.test.tsx +2 -1
- package/src/utils/date/getYearDisplayName.test.ts +1 -1
- package/src/utils/disabled/DisabledStateProvider.stories.tsx +2 -0
- package/src/utils/disabled/useDisableStateProps.test.tsx +2 -2
- package/src/utils/react/OnBeforeUnmount.tsx +1 -1
- package/src/utils/react/renderButtonOrLink.tsx +16 -0
- package/src/utils/react/skipRender.tsx +2 -2
- package/src/utils/react/wrapChildrenIconWithSpaces.test.tsx +1 -1
- package/src/utils/type/HasPolymorphicAs.ts +2 -0
- package/src/utils/type/index.ts +0 -1
- package/utils/index.d.ts +6 -6
- package/src/utils/react/RawClickable.test.tsx +0 -153
- package/src/utils/react/RawClickable.tsx +0 -65
- package/src/utils/type/HasRequiredLinkHref.ts +0 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
2
4
|
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
3
5
|
import { render, screen, within } from '@testing-library/react';
|
|
@@ -40,7 +42,7 @@ describe(`<${TableCell.displayName}>`, () => {
|
|
|
40
42
|
|
|
41
43
|
it('should render header variant clickable', async () => {
|
|
42
44
|
const content = 'Content';
|
|
43
|
-
const onHeaderClick =
|
|
45
|
+
const onHeaderClick = jest.fn();
|
|
44
46
|
const { tableCell } = setup({ children: content, variant: 'head', onHeaderClick });
|
|
45
47
|
|
|
46
48
|
const headerButton = within(tableCell).getByRole('button', { name: content });
|
|
@@ -8,7 +8,7 @@ import { toFlattenProps } from '@lumx/react/stories/utils/toFlattenProps';
|
|
|
8
8
|
import { withCategory } from '@lumx/react/stories/utils/withCategory';
|
|
9
9
|
import get from 'lodash/get';
|
|
10
10
|
import times from 'lodash/times';
|
|
11
|
-
import { useState } from 'react';
|
|
11
|
+
import React, { useState } from 'react';
|
|
12
12
|
|
|
13
13
|
export default {
|
|
14
14
|
title: 'LumX components/tabs',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ALL_TYPOGRAPHY, allTypographyArgType } from '@lumx/react/stories/controls/typography';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
|
|
3
|
-
import { ALL_TYPOGRAPHY, allTypographyArgType } from '@lumx/react/stories/controls/typography';
|
|
4
4
|
import { colorArgType, colorVariantArgType } from '@lumx/react/stories/controls/color';
|
|
5
5
|
import { textElementArgType } from '@lumx/react/stories/controls/element';
|
|
6
6
|
import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
2
3
|
import camelCase from 'lodash/camelCase';
|
|
3
4
|
|
|
4
5
|
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
@@ -19,7 +20,7 @@ import { TextField, TextFieldProps } from './TextField';
|
|
|
19
20
|
|
|
20
21
|
const CLASSNAME = TextField.className as string;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
jest.mock('@lumx/react/utils/browser/isFocusVisible');
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
@@ -48,7 +49,7 @@ const setup = (propsOverride: Partial<TextFieldProps> = {}, { wrapper }: SetupRe
|
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
describe(`<${TextField.displayName}>`, () => {
|
|
51
|
-
(isFocusVisible as Mock).mockReturnValue(false);
|
|
52
|
+
(isFocusVisible as jest.Mock).mockReturnValue(false);
|
|
52
53
|
|
|
53
54
|
describe('Render', () => {
|
|
54
55
|
it('should render defaults', () => {
|
|
@@ -179,7 +180,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
179
180
|
|
|
180
181
|
describe('Events', () => {
|
|
181
182
|
it('should trigger `onChange` when text field is changed', async () => {
|
|
182
|
-
const onChange =
|
|
183
|
+
const onChange = jest.fn();
|
|
183
184
|
const { inputNative } = setup({ value: '', name: 'name', onChange });
|
|
184
185
|
|
|
185
186
|
await userEvent.tab();
|
|
@@ -191,7 +192,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
191
192
|
});
|
|
192
193
|
|
|
193
194
|
it('should trigger `onChange` with empty value when text field is cleared', async () => {
|
|
194
|
-
const onChange =
|
|
195
|
+
const onChange = jest.fn();
|
|
195
196
|
const { clearButton } = setup({
|
|
196
197
|
value: 'initial value',
|
|
197
198
|
name: 'name',
|
|
@@ -207,8 +208,8 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
207
208
|
});
|
|
208
209
|
|
|
209
210
|
it('should trigger `onChange` with empty value and `onClear` when text field is cleared', async () => {
|
|
210
|
-
const onChange =
|
|
211
|
-
const onClear =
|
|
211
|
+
const onChange = jest.fn();
|
|
212
|
+
const onClear = jest.fn();
|
|
212
213
|
const { clearButton } = setup({
|
|
213
214
|
value: 'initial value',
|
|
214
215
|
name: 'name',
|
|
@@ -228,7 +229,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
228
229
|
|
|
229
230
|
describe('Disabled state', () => {
|
|
230
231
|
it('should render with "isDisabled"', async () => {
|
|
231
|
-
const onChange =
|
|
232
|
+
const onChange = jest.fn();
|
|
232
233
|
const { element, inputNative } = setup({
|
|
233
234
|
label: 'Label',
|
|
234
235
|
isDisabled: true,
|
|
@@ -254,7 +255,7 @@ describe(`<${TextField.displayName}>`, () => {
|
|
|
254
255
|
});
|
|
255
256
|
|
|
256
257
|
it('should render with "aria-disabled"', async () => {
|
|
257
|
-
const onChange =
|
|
258
|
+
const onChange = jest.fn();
|
|
258
259
|
const { element, inputNative } = setup({
|
|
259
260
|
label: 'Label',
|
|
260
261
|
'aria-disabled': true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode, Ref, RefObject, SyntheticEvent, useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { ReactNode, Ref, RefObject, SyntheticEvent, useEffect, useRef, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import get from 'lodash/get';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { DisabledStateProvider } from '@lumx/react/utils';
|
|
2
4
|
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
3
5
|
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
4
|
-
import { fireEvent, render
|
|
6
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
5
7
|
import { Thumbnail, ThumbnailProps } from './Thumbnail';
|
|
6
8
|
|
|
7
9
|
const CLASSNAME = Thumbnail.className as string;
|
|
@@ -26,20 +28,9 @@ describe(`<${Thumbnail.displayName}>`, () => {
|
|
|
26
28
|
},
|
|
27
29
|
});
|
|
28
30
|
|
|
29
|
-
describe('
|
|
30
|
-
it('should
|
|
31
|
-
const onClick =
|
|
32
|
-
const { thumbnail } = setup({ onClick, alt: 'Name' });
|
|
33
|
-
const button = screen.getByRole('button', { name: 'Name' });
|
|
34
|
-
expect(button).toBe(thumbnail);
|
|
35
|
-
expect(button).toHaveAttribute('type', 'button');
|
|
36
|
-
|
|
37
|
-
fireEvent.click(thumbnail as HTMLElement);
|
|
38
|
-
expect(onClick).toHaveBeenCalled();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should not render button in disabled context', () => {
|
|
42
|
-
const onClick = vi.fn();
|
|
31
|
+
describe('disabled state', () => {
|
|
32
|
+
it('should not be clickable when disabled from context', () => {
|
|
33
|
+
const onClick = jest.fn();
|
|
43
34
|
const { thumbnail, container } = setup(
|
|
44
35
|
{ onClick, 'aria-label': 'thumbnail' },
|
|
45
36
|
{
|
|
@@ -56,21 +47,8 @@ describe(`<${Thumbnail.displayName}>`, () => {
|
|
|
56
47
|
fireEvent.click(thumbnail as HTMLElement);
|
|
57
48
|
expect(onClick).not.toHaveBeenCalled();
|
|
58
49
|
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('clickable link', () => {
|
|
62
|
-
it('should render clickable link', async () => {
|
|
63
|
-
const onClick = vi.fn((evt: any) => evt.preventDefault());
|
|
64
|
-
const { thumbnail } = setup({ linkProps: { href: '#' }, onClick, alt: 'Name' });
|
|
65
|
-
const link = screen.getByRole('link');
|
|
66
|
-
expect(link).toBe(thumbnail);
|
|
67
|
-
expect(link).toHaveAttribute('href', '#');
|
|
68
|
-
|
|
69
|
-
fireEvent.click(thumbnail as HTMLElement);
|
|
70
|
-
expect(onClick).toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
50
|
|
|
73
|
-
it('should
|
|
51
|
+
it('should have no href when disabled from context', () => {
|
|
74
52
|
const { container, thumbnail } = setup(
|
|
75
53
|
{ linkAs: 'a', linkProps: { href: '#' }, 'aria-label': 'thumbnail' },
|
|
76
54
|
{
|
|
@@ -22,7 +22,6 @@ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
|
|
|
22
22
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
23
23
|
|
|
24
24
|
import { useDisableStateProps } from '@lumx/react/utils/disabled';
|
|
25
|
-
import { RawClickable } from '@lumx/react/utils/react/RawClickable';
|
|
26
25
|
import { FocusPoint, ThumbnailSize, ThumbnailVariant } from './types';
|
|
27
26
|
|
|
28
27
|
type ImgHTMLProps = ImgHTMLAttributes<HTMLImageElement>;
|
|
@@ -101,7 +100,7 @@ const DEFAULT_PROPS: Partial<ThumbnailProps> = {
|
|
|
101
100
|
* @return React element.
|
|
102
101
|
*/
|
|
103
102
|
export const Thumbnail = forwardRef<ThumbnailProps>((props, ref) => {
|
|
104
|
-
const { isAnyDisabled, otherProps
|
|
103
|
+
const { isAnyDisabled, otherProps } = useDisableStateProps(props);
|
|
105
104
|
const defaultTheme = useTheme() || Theme.light;
|
|
106
105
|
const {
|
|
107
106
|
align,
|
|
@@ -152,17 +151,18 @@ export const Thumbnail = forwardRef<ThumbnailProps>((props, ref) => {
|
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
const isLink = Boolean(linkProps?.href || linkAs);
|
|
155
|
-
const
|
|
154
|
+
const isButton = !!forwardedProps.onClick;
|
|
155
|
+
const isClickable = !isAnyDisabled && (isButton || isLink);
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
let Wrapper: any = 'div';
|
|
158
158
|
const wrapperProps = { ...forwardedProps };
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
if (!isAnyDisabled && isLink) {
|
|
160
|
+
Wrapper = linkAs || 'a';
|
|
161
|
+
Object.assign(wrapperProps, linkProps);
|
|
162
|
+
} else if (!isAnyDisabled && isButton) {
|
|
163
|
+
Wrapper = 'button';
|
|
164
|
+
wrapperProps.type = forwardedProps.type || 'button';
|
|
165
|
+
wrapperProps['aria-label'] = forwardedProps['aria-label'] || alt;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
// If we have a loading placeholder image that is really loaded (complete)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
|
|
3
1
|
import { Button, Dialog, Dropdown, Placement, Tooltip } from '@lumx/react';
|
|
2
|
+
import React, { useState } from 'react';
|
|
4
3
|
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
5
4
|
import { withChromaticForceScreenSize } from '@lumx/react/stories/decorators/withChromaticForceScreenSize';
|
|
6
5
|
import { ARIA_LINK_MODES } from '@lumx/react/components/tooltip/constants';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { MockInstance } from 'vitest';
|
|
4
3
|
import { Button } from '@lumx/react';
|
|
5
4
|
import { screen, render } from '@testing-library/react';
|
|
6
5
|
import { queryAllByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -13,18 +12,13 @@ import { Tooltip, TooltipProps } from './Tooltip';
|
|
|
13
12
|
|
|
14
13
|
const CLASSNAME = Tooltip.className as string;
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
jest.mock('@lumx/react/utils/browser/isFocusVisible');
|
|
16
|
+
jest.mock('@lumx/react/hooks/useId', () => ({ useId: () => ':r1:' }));
|
|
18
17
|
// Skip delays
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
TOOLTIP_HOVER_DELAY: { open: 0, close: 0 },
|
|
24
|
-
VISUALLY_HIDDEN: actual.VISUALLY_HIDDEN,
|
|
25
|
-
CSS_PREFIX: actual.CSS_PREFIX,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
18
|
+
jest.mock('@lumx/react/constants', () => ({
|
|
19
|
+
...jest.requireActual('@lumx/react/constants'),
|
|
20
|
+
TOOLTIP_HOVER_DELAY: { open: 0, close: 0 },
|
|
21
|
+
}));
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
24
|
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
@@ -352,7 +346,7 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
352
346
|
});
|
|
353
347
|
|
|
354
348
|
it('should activate on anchor focus visible and close on escape', async () => {
|
|
355
|
-
(isFocusVisible as
|
|
349
|
+
(isFocusVisible as jest.Mock).mockReturnValue(true);
|
|
356
350
|
let { tooltip } = await setup({
|
|
357
351
|
label: 'Tooltip label',
|
|
358
352
|
children: <Button>Anchor</Button>,
|
|
@@ -387,7 +381,7 @@ describe(`<${Tooltip.displayName}>`, () => {
|
|
|
387
381
|
});
|
|
388
382
|
|
|
389
383
|
it('should not activate on anchor focus if not visible', async () => {
|
|
390
|
-
(isFocusVisible as
|
|
384
|
+
(isFocusVisible as jest.Mock).mockReturnValue(false);
|
|
391
385
|
let { tooltip } = await setup({
|
|
392
386
|
label: 'Tooltip label',
|
|
393
387
|
children: <Button>Anchor</Button>,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
2
4
|
|
|
3
5
|
import { render, screen } from '@testing-library/react';
|
|
@@ -87,9 +89,9 @@ describe(`<${Uploader.displayName}>`, () => {
|
|
|
87
89
|
${'button'} | ${{}}
|
|
88
90
|
${'button isDisabled '} | ${{ isDisabled: true }}
|
|
89
91
|
${'button aria-disabled'} | ${{ 'aria-disabled': true }}
|
|
90
|
-
${'file input '} | ${{ fileInputProps: { onChange:
|
|
92
|
+
${'file input '} | ${{ fileInputProps: { onChange: jest.fn() } }}
|
|
91
93
|
`('Events $name', ({ props }) => {
|
|
92
|
-
const onClick =
|
|
94
|
+
const onClick = jest.fn();
|
|
93
95
|
beforeEach(() => onClick.mockClear());
|
|
94
96
|
const assertClick = () => {
|
|
95
97
|
if (props.isDisabled || props['aria-disabled']) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
2
4
|
import { mdiMenuDown, mdiStar } from '@lumx/icons';
|
|
3
5
|
import { Badge, ColorPalette, Icon, IconButton, Link, Orientation, Size, Text } from '@lumx/react';
|
|
4
6
|
import { CustomLink } from '@lumx/react/stories/utils/CustomLink';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
2
4
|
import { render, within, screen } from '@testing-library/react';
|
|
3
5
|
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -34,7 +36,7 @@ describe(`<${UserBlock.displayName}>`, () => {
|
|
|
34
36
|
});
|
|
35
37
|
|
|
36
38
|
it('should render button', async () => {
|
|
37
|
-
const onClick =
|
|
39
|
+
const onClick = jest.fn();
|
|
38
40
|
const { name, thumbnail } = setup({
|
|
39
41
|
onClick,
|
|
40
42
|
name: 'John Doe',
|
package/src/hooks/useId.test.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
3
|
-
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
4
4
|
import { Button } from '@lumx/react';
|
|
5
5
|
import { ClickAwayProvider } from '@lumx/react/utils/ClickAwayProvider';
|
|
6
6
|
import { initDemoShadowDOMPortal } from '@lumx/react/stories/utils/initDemoShadowDOMPortal';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';
|
|
1
|
+
import React, { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { ClickAwayParameters, useClickAway } from '@lumx/react/hooks/useClickAway';
|
|
3
3
|
|
|
4
4
|
interface ContextValue {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { render, screen } from '@testing-library/react';
|
|
2
3
|
import { PortalInit, PortalProvider } from './PortalProvider';
|
|
3
4
|
import { Portal } from './Portal';
|
|
@@ -29,7 +30,7 @@ describe('PortalProvider', () => {
|
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
it('should call teardown on unmount', () => {
|
|
32
|
-
const teardownMock =
|
|
33
|
+
const teardownMock = jest.fn();
|
|
33
34
|
const portalContainer = document.createElement('div');
|
|
34
35
|
portalContainer.id = PORTAL_CONTAINER_ID;
|
|
35
36
|
document.body.appendChild(portalContainer);
|
|
@@ -4,7 +4,7 @@ describe(getYearDisplayName, () => {
|
|
|
4
4
|
beforeEach(() => {
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
6
|
// @ts-ignore
|
|
7
|
-
|
|
7
|
+
jest.spyOn(Intl, 'DisplayNames').mockImplementation(() => ({
|
|
8
8
|
resolvedOptions: () => ({
|
|
9
9
|
fallback: 'code',
|
|
10
10
|
locale: 'fr',
|
|
@@ -59,14 +59,14 @@ describe(useDisableStateProps.name, () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it('should forward onClick when not disabled', () => {
|
|
62
|
-
const onClick =
|
|
62
|
+
const onClick = jest.fn();
|
|
63
63
|
const { element } = setup({ onClick });
|
|
64
64
|
fireEvent.click(element);
|
|
65
65
|
expect(onClick).toHaveBeenCalled();
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it('should not forward onClick when disabled', () => {
|
|
69
|
-
const onClick =
|
|
69
|
+
const onClick = jest.fn();
|
|
70
70
|
const { element } = setup({ disabled: true, onClick });
|
|
71
71
|
fireEvent.click(element);
|
|
72
72
|
expect(onClick).not.toHaveBeenCalled();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import { renderLink } from './renderLink';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
linkAs?: any;
|
|
6
|
+
href?: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Render <button> HTML component, fallbacks to `<a>` when a `href` is provided or a custom component with `linkAs`.
|
|
11
|
+
*/
|
|
12
|
+
export const renderButtonOrLink = <P extends Props>(props: P, ...children: ReactNode[]): ReactElement => {
|
|
13
|
+
const { linkAs, href, ...forwardedProps } = props;
|
|
14
|
+
if (linkAs || href) return renderLink(props, ...children);
|
|
15
|
+
return React.createElement('button', { type: 'button', ...forwardedProps }, ...children);
|
|
16
|
+
};
|