@lumx/react 3.20.1-alpha.3 → 3.20.1-alpha.5
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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
TypographyTitleCustom,
|
|
11
11
|
GenericBlock,
|
|
12
12
|
} from '@lumx/react';
|
|
13
|
+
import React from 'react';
|
|
13
14
|
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
14
15
|
import { colorArgType, colorVariantArgType } from '@lumx/react/stories/controls/color';
|
|
15
16
|
import { iconArgType } from '@lumx/react/stories/controls/icons';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { ColorPalette, ColorVariant, Icon, Typography } from '@lumx/react';
|
|
2
4
|
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
3
5
|
import { getByClassName, queryAllByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -49,7 +51,7 @@ describe(`<${Link.displayName}>`, () => {
|
|
|
49
51
|
|
|
50
52
|
it('should render a button', () => {
|
|
51
53
|
const name = 'Link';
|
|
52
|
-
const onClick =
|
|
54
|
+
const onClick = jest.fn();
|
|
53
55
|
const { link } = setup({ onClick, children: name });
|
|
54
56
|
expect(link).toBe(screen.queryByRole('button', { name }));
|
|
55
57
|
});
|
|
@@ -73,7 +75,7 @@ describe(`<${Link.displayName}>`, () => {
|
|
|
73
75
|
|
|
74
76
|
describe('Disabled state', () => {
|
|
75
77
|
it('should render disabled button', async () => {
|
|
76
|
-
const onClick =
|
|
78
|
+
const onClick = jest.fn();
|
|
77
79
|
const { link } = setup({ children: 'Label', isDisabled: true, onClick });
|
|
78
80
|
expect(link).toHaveAttribute('disabled');
|
|
79
81
|
await userEvent.click(link);
|
|
@@ -81,28 +83,25 @@ describe(`<${Link.displayName}>`, () => {
|
|
|
81
83
|
});
|
|
82
84
|
|
|
83
85
|
it('should render disabled link', async () => {
|
|
84
|
-
const onClick =
|
|
86
|
+
const onClick = jest.fn();
|
|
85
87
|
const { link } = setup({ children: 'Label', isDisabled: true, href: 'https://example.com', onClick });
|
|
86
|
-
|
|
87
|
-
expect(
|
|
88
|
-
|
|
89
|
-
expect(link).toHaveAttribute('tabindex', '-1');
|
|
88
|
+
// Disabled link do not exist so we fallback to a button
|
|
89
|
+
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
90
|
+
expect(link).toHaveAttribute('disabled');
|
|
90
91
|
await userEvent.click(link);
|
|
91
92
|
expect(onClick).not.toHaveBeenCalled();
|
|
92
93
|
});
|
|
93
94
|
|
|
94
95
|
it('should render aria-disabled button', async () => {
|
|
95
|
-
const onClick =
|
|
96
|
+
const onClick = jest.fn();
|
|
96
97
|
const { link } = setup({ children: 'Label', 'aria-disabled': true, onClick });
|
|
97
|
-
expect(
|
|
98
|
-
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
99
|
-
expect(link).not.toHaveAttribute('tabindex');
|
|
98
|
+
expect(link).toHaveAttribute('aria-disabled');
|
|
100
99
|
await userEvent.click(link);
|
|
101
100
|
expect(onClick).not.toHaveBeenCalled();
|
|
102
101
|
});
|
|
103
102
|
|
|
104
103
|
it('should render aria-disabled link', async () => {
|
|
105
|
-
const onClick =
|
|
104
|
+
const onClick = jest.fn();
|
|
106
105
|
const { link } = setup({
|
|
107
106
|
children: 'Label',
|
|
108
107
|
'aria-disabled': true,
|
|
@@ -110,7 +109,8 @@ describe(`<${Link.displayName}>`, () => {
|
|
|
110
109
|
onClick,
|
|
111
110
|
});
|
|
112
111
|
expect(link).toHaveAccessibleName('Label');
|
|
113
|
-
|
|
112
|
+
// Disabled link do not exist so we fallback to a button
|
|
113
|
+
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
114
114
|
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
115
115
|
await userEvent.click(link);
|
|
116
116
|
expect(onClick).not.toHaveBeenCalled();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import classNames from 'classnames';
|
|
2
4
|
|
|
3
5
|
import { ColorVariant, ColorWithVariants, Icon, Typography } from '@lumx/react';
|
|
@@ -10,9 +12,8 @@ import {
|
|
|
10
12
|
} from '@lumx/core/js/utils/className';
|
|
11
13
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
12
14
|
import { wrapChildrenIconWithSpaces } from '@lumx/react/utils/react/wrapChildrenIconWithSpaces';
|
|
15
|
+
import { useDisableStateProps } from '@lumx/react/utils/disabled/useDisableStateProps';
|
|
13
16
|
import { HasAriaDisabled } from '@lumx/react/utils/type/HasAriaDisabled';
|
|
14
|
-
import { RawClickable } from '@lumx/react/utils/react/RawClickable';
|
|
15
|
-
import { useDisableStateProps } from '@lumx/react/utils/disabled';
|
|
16
17
|
|
|
17
18
|
type HTMLAnchorProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>;
|
|
18
19
|
|
|
@@ -66,26 +67,38 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
|
66
67
|
* @return React element.
|
|
67
68
|
*/
|
|
68
69
|
export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>((props, ref) => {
|
|
69
|
-
const { disabledStateProps, otherProps } = useDisableStateProps(props);
|
|
70
|
+
const { isAnyDisabled, disabledStateProps, otherProps } = useDisableStateProps(props);
|
|
70
71
|
const {
|
|
71
72
|
children,
|
|
72
73
|
className,
|
|
73
74
|
color: propColor,
|
|
74
75
|
colorVariant: propColorVariant,
|
|
76
|
+
href,
|
|
75
77
|
leftIcon,
|
|
78
|
+
linkAs,
|
|
76
79
|
rightIcon,
|
|
80
|
+
target,
|
|
77
81
|
typography,
|
|
78
|
-
linkAs,
|
|
79
82
|
...forwardedProps
|
|
80
83
|
} = otherProps;
|
|
81
84
|
const [color, colorVariant] = resolveColorWithVariants(propColor, propColorVariant);
|
|
82
85
|
|
|
86
|
+
const isLink = linkAs || href;
|
|
87
|
+
const Component = isLink && !isAnyDisabled ? linkAs || 'a' : 'button';
|
|
88
|
+
const baseProps: React.ComponentProps<typeof Component> = {};
|
|
89
|
+
if (Component === 'button') {
|
|
90
|
+
baseProps.type = 'button';
|
|
91
|
+
Object.assign(baseProps, disabledStateProps);
|
|
92
|
+
} else if (isLink) {
|
|
93
|
+
baseProps.href = href;
|
|
94
|
+
baseProps.target = target;
|
|
95
|
+
}
|
|
96
|
+
|
|
83
97
|
return (
|
|
84
|
-
<
|
|
85
|
-
ref={ref
|
|
86
|
-
as={linkAs || (forwardedProps.href ? 'a' : 'button')}
|
|
98
|
+
<Component
|
|
99
|
+
ref={ref}
|
|
87
100
|
{...forwardedProps}
|
|
88
|
-
{...
|
|
101
|
+
{...baseProps}
|
|
89
102
|
className={classNames(
|
|
90
103
|
className,
|
|
91
104
|
handleBasicClasses({ prefix: CLASSNAME, color, colorVariant, hasTypography: !!typography }),
|
|
@@ -99,7 +112,7 @@ export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>
|
|
|
99
112
|
{rightIcon && <Icon icon={rightIcon} className={`${CLASSNAME}__right-icon`} />}
|
|
100
113
|
</>,
|
|
101
114
|
)}
|
|
102
|
-
</
|
|
115
|
+
</Component>
|
|
103
116
|
);
|
|
104
117
|
});
|
|
105
118
|
Link.displayName = COMPONENT_NAME;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
2
4
|
import { render, screen } from '@testing-library/react';
|
|
3
5
|
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -27,7 +29,7 @@ describe(`<${ListItem.displayName}>`, () => {
|
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
it('should render as a button', () => {
|
|
30
|
-
setup({ children: 'Label', onItemSelected:
|
|
32
|
+
setup({ children: 'Label', onItemSelected: jest.fn() });
|
|
31
33
|
expect(screen.getByRole('button', { name: 'Label' })).toBeInTheDocument();
|
|
32
34
|
});
|
|
33
35
|
|
|
@@ -39,7 +41,7 @@ describe(`<${ListItem.displayName}>`, () => {
|
|
|
39
41
|
|
|
40
42
|
describe('Disabled state', () => {
|
|
41
43
|
it('should render disabled list item button', async () => {
|
|
42
|
-
const onItemSelected =
|
|
44
|
+
const onItemSelected = jest.fn();
|
|
43
45
|
const { link } = setup({ children: 'Label', isDisabled: true, onItemSelected });
|
|
44
46
|
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
45
47
|
// The `renderLink` util removes the onClick handler but `user-event` will also not fire events on disabled elements.
|
|
@@ -48,7 +50,7 @@ describe(`<${ListItem.displayName}>`, () => {
|
|
|
48
50
|
});
|
|
49
51
|
|
|
50
52
|
it('should render disabled list item link', async () => {
|
|
51
|
-
const onItemSelected =
|
|
53
|
+
const onItemSelected = jest.fn();
|
|
52
54
|
const { link } = setup({
|
|
53
55
|
children: 'Label',
|
|
54
56
|
isDisabled: true,
|
|
@@ -62,7 +64,7 @@ describe(`<${ListItem.displayName}>`, () => {
|
|
|
62
64
|
});
|
|
63
65
|
|
|
64
66
|
it('should render aria-disabled list item button', async () => {
|
|
65
|
-
const onItemSelected =
|
|
67
|
+
const onItemSelected = jest.fn();
|
|
66
68
|
const { link } = setup({ children: 'Label', 'aria-disabled': true, onItemSelected });
|
|
67
69
|
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
68
70
|
if (link) await userEvent.click(link);
|
|
@@ -70,7 +72,7 @@ describe(`<${ListItem.displayName}>`, () => {
|
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
it('should render aria-disabled list item link', async () => {
|
|
73
|
-
const onItemSelected =
|
|
75
|
+
const onItemSelected = jest.fn();
|
|
74
76
|
const { link } = setup({
|
|
75
77
|
children: 'Label',
|
|
76
78
|
'aria-disabled': true,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
|
|
2
2
|
import { Kind } from '@lumx/react';
|
|
3
3
|
|
|
4
|
+
import React from 'react';
|
|
4
5
|
import { queryByRole, render } from '@testing-library/react';
|
|
5
6
|
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
7
|
import { mdiAbTesting } from '@lumx/icons';
|
|
@@ -53,7 +54,7 @@ describe(`<${Message.displayName}>`, () => {
|
|
|
53
54
|
});
|
|
54
55
|
|
|
55
56
|
it('should render close button', async () => {
|
|
56
|
-
const onClick =
|
|
57
|
+
const onClick = jest.fn();
|
|
57
58
|
const { closeButton } = setup({
|
|
58
59
|
hasBackground: true,
|
|
59
60
|
kind: 'info',
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { Mosaic, MosaicProps } from '@lumx/react/components/mosaic/Mosaic';
|
|
2
4
|
import { render, screen, within } from '@testing-library/react';
|
|
3
5
|
import { getByClassName, queryAllByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -30,7 +32,7 @@ describe(`<${Mosaic.displayName}>`, () => {
|
|
|
30
32
|
expect(mosaic).toHaveClass(`${CLASSNAME}--has-${count}-thumbnail${count > 1 ? 's' : ''}`);
|
|
31
33
|
expect(thumbnails.length).toBe(count);
|
|
32
34
|
for (const thumbnail of thumbnails) {
|
|
33
|
-
expect(within(thumbnail).
|
|
35
|
+
expect(within(thumbnail).queryByRole('img')).toBeInTheDocument();
|
|
34
36
|
}
|
|
35
37
|
});
|
|
36
38
|
|
|
@@ -45,8 +47,8 @@ describe(`<${Mosaic.displayName}>`, () => {
|
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
it('should render clickable', async () => {
|
|
48
|
-
const onClick =
|
|
49
|
-
const onImageClick =
|
|
50
|
+
const onClick = jest.fn();
|
|
51
|
+
const onImageClick = jest.fn();
|
|
50
52
|
const { thumbnails } = setup({
|
|
51
53
|
thumbnails: generateThumbnails(6),
|
|
52
54
|
onImageClick,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { ElementType, ReactNode } from 'react';
|
|
1
|
+
import React, { ElementType, ReactNode } from 'react';
|
|
2
2
|
import { Icon, Placement, Size, Tooltip, Text } from '@lumx/react';
|
|
3
3
|
import { getRootClassName, handleBasicClasses } from '@lumx/core/js/utils/className';
|
|
4
|
-
import { ComponentRef, HasClassName, HasPolymorphicAs,
|
|
4
|
+
import { ComponentRef, HasClassName, HasPolymorphicAs, HasTheme } from '@lumx/react/utils/type';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { forwardRefPolymorphic } from '@lumx/react/utils/react/forwardRefPolymorphic';
|
|
7
7
|
import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
|
|
8
8
|
import { useOverflowTooltipLabel } from '@lumx/react/hooks/useOverflowTooltipLabel';
|
|
9
|
-
import { RawClickable } from '@lumx/react/utils/react/RawClickable';
|
|
10
9
|
|
|
11
10
|
type BaseNavigationItemProps = {
|
|
12
11
|
/** Icon (SVG path). */
|
|
@@ -17,6 +16,9 @@ type BaseNavigationItemProps = {
|
|
|
17
16
|
isCurrentPage?: boolean;
|
|
18
17
|
};
|
|
19
18
|
|
|
19
|
+
/** Make `href` required when `as` is `a` */
|
|
20
|
+
type RequiredLinkHref<E> = E extends 'a' ? { href: string } : Record<string, unknown>;
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Navigation item props
|
|
22
24
|
*/
|
|
@@ -24,7 +26,7 @@ export type NavigationItemProps<E extends ElementType = 'a'> = HasPolymorphicAs<
|
|
|
24
26
|
HasTheme &
|
|
25
27
|
HasClassName &
|
|
26
28
|
BaseNavigationItemProps &
|
|
27
|
-
|
|
29
|
+
RequiredLinkHref<E>;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Component display name.
|
|
@@ -42,6 +44,8 @@ export const NavigationItem = Object.assign(
|
|
|
42
44
|
const theme = useTheme();
|
|
43
45
|
const { tooltipLabel, labelRef } = useOverflowTooltipLabel(label);
|
|
44
46
|
|
|
47
|
+
const buttonProps = Element === 'button' ? { type: 'button' } : {};
|
|
48
|
+
|
|
45
49
|
return (
|
|
46
50
|
<li
|
|
47
51
|
className={classNames(
|
|
@@ -53,14 +57,14 @@ export const NavigationItem = Object.assign(
|
|
|
53
57
|
)}
|
|
54
58
|
>
|
|
55
59
|
<Tooltip label={tooltipLabel} placement={Placement.TOP}>
|
|
56
|
-
<
|
|
57
|
-
as={Element}
|
|
60
|
+
<Element
|
|
58
61
|
className={handleBasicClasses({
|
|
59
62
|
prefix: `${CLASSNAME}__link`,
|
|
60
63
|
isSelected: isCurrentPage,
|
|
61
64
|
})}
|
|
62
65
|
ref={ref as React.Ref<any>}
|
|
63
66
|
aria-current={isCurrentPage ? 'page' : undefined}
|
|
67
|
+
{...buttonProps}
|
|
64
68
|
{...forwardedProps}
|
|
65
69
|
>
|
|
66
70
|
{icon ? (
|
|
@@ -70,7 +74,7 @@ export const NavigationItem = Object.assign(
|
|
|
70
74
|
<Text as="span" truncate className={`${CLASSNAME}__label`} ref={labelRef}>
|
|
71
75
|
{label}
|
|
72
76
|
</Text>
|
|
73
|
-
</
|
|
77
|
+
</Element>
|
|
74
78
|
</Tooltip>
|
|
75
79
|
</li>
|
|
76
80
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, useState, useContext } from 'react';
|
|
1
|
+
import React, { useRef, useState, useContext } from 'react';
|
|
2
2
|
|
|
3
3
|
import { mdiChevronDown, mdiChevronUp } from '@lumx/icons';
|
|
4
4
|
import { Icon, Size, Text, Orientation, Popover, Placement, Theme } from '@lumx/react';
|
|
@@ -9,7 +9,6 @@ import { ThemeProvider, useTheme } from '@lumx/react/utils/theme/ThemeContext';
|
|
|
9
9
|
import { useId } from '@lumx/react/hooks/useId';
|
|
10
10
|
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
11
11
|
|
|
12
|
-
import { RawClickable } from '@lumx/react/utils/react/RawClickable';
|
|
13
12
|
import { CLASSNAME as ITEM_CLASSNAME } from './NavigationItem';
|
|
14
13
|
import { NavigationContext } from './context';
|
|
15
14
|
|
|
@@ -53,8 +52,7 @@ export const NavigationSection = forwardRef<NavigationSectionProps, HTMLLIElemen
|
|
|
53
52
|
)}
|
|
54
53
|
ref={ref}
|
|
55
54
|
>
|
|
56
|
-
<
|
|
57
|
-
as="button"
|
|
55
|
+
<button
|
|
58
56
|
{...forwardedProps}
|
|
59
57
|
aria-controls={sectionId}
|
|
60
58
|
aria-expanded={isOpen}
|
|
@@ -64,6 +62,7 @@ export const NavigationSection = forwardRef<NavigationSectionProps, HTMLLIElemen
|
|
|
64
62
|
setIsOpen(!isOpen);
|
|
65
63
|
event.stopPropagation();
|
|
66
64
|
}}
|
|
65
|
+
type="button"
|
|
67
66
|
>
|
|
68
67
|
{icon ? <Icon className={`${ITEM_CLASSNAME}__icon`} icon={icon} size={Size.xs} /> : null}
|
|
69
68
|
|
|
@@ -74,7 +73,7 @@ export const NavigationSection = forwardRef<NavigationSectionProps, HTMLLIElemen
|
|
|
74
73
|
className={classNames(`${ITEM_CLASSNAME}__icon`, `${CLASSNAME}__chevron`)}
|
|
75
74
|
icon={isOpen ? mdiChevronUp : mdiChevronDown}
|
|
76
75
|
/>
|
|
77
|
-
</
|
|
76
|
+
</button>
|
|
78
77
|
{isOpen &&
|
|
79
78
|
(isDropdown ? (
|
|
80
79
|
<Popover
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
1
3
|
import { Kind } from '@lumx/react';
|
|
2
4
|
import { render, within, screen } from '@testing-library/react';
|
|
3
5
|
import { queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
@@ -42,8 +44,8 @@ describe(`<${Notification.displayName}>`, () => {
|
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
it('should render content & action', async () => {
|
|
45
|
-
const onClick =
|
|
46
|
-
const onActionClick =
|
|
47
|
+
const onClick = jest.fn();
|
|
48
|
+
const onActionClick = jest.fn();
|
|
47
49
|
const content = 'Content';
|
|
48
50
|
const actionLabel = 'actionLabel';
|
|
49
51
|
const { notification, action, actionButton } = setup({ content, actionLabel, onClick, onActionClick });
|
|
@@ -79,9 +81,8 @@ describe(`<${Notification.displayName}>`, () => {
|
|
|
79
81
|
|
|
80
82
|
it('should forward styles', () => {
|
|
81
83
|
const { notification } = setup({ style: { color: 'red' } });
|
|
82
|
-
|
|
83
84
|
expect(notification).toBeInTheDocument();
|
|
84
|
-
expect(notification).toHaveStyle('color:
|
|
85
|
+
expect(notification).toHaveStyle('color: red');
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
// Common tests suite.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { render, screen, within } from '@testing-library/react';
|
|
2
3
|
import userEvent from '@testing-library/user-event';
|
|
3
4
|
|
|
@@ -5,7 +6,7 @@ import { Heading, HeadingLevelProvider } from '@lumx/react';
|
|
|
5
6
|
import { WithButtonTrigger, WithIconButtonTrigger } from './PopoverDialog.stories';
|
|
6
7
|
import { PopoverDialog } from './PopoverDialog';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
jest.mock('@lumx/react/utils/browser/isFocusVisible');
|
|
9
10
|
|
|
10
11
|
describe(`<${PopoverDialog.displayName}>`, () => {
|
|
11
12
|
it('should open and init focus', async () => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { ProgressCircular, ProgressCircularSize, Size, Text } from '@lumx/react';
|
|
2
3
|
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
3
4
|
import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
|