@lumx/react 3.20.1-alpha.8 → 3.21.0
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 +20 -13
- package/_internal/index.js.map +1 -1
- package/index.d.ts +60 -33
- package/index.js +2937 -3090
- package/index.js.map +1 -1
- package/package.json +5 -9
- package/src/components/alert-dialog/AlertDialog.stories.tsx +1 -1
- package/src/components/alert-dialog/AlertDialog.test.tsx +2 -0
- package/src/components/autocomplete/Autocomplete.stories.tsx +1 -1
- package/src/components/autocomplete/Autocomplete.test.tsx +2 -0
- 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 +2 -0
- 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 +1 -1
- package/src/components/button/IconButton.test.tsx +2 -0
- package/src/components/button/IconButton.tsx +2 -0
- package/src/components/checkbox/Checkbox.test.tsx +2 -0
- package/src/components/chip/Chip.stories.tsx +2 -0
- package/src/components/chip/Chip.test.tsx +2 -0
- 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 +2 -0
- package/src/components/date-picker/DatePicker.tsx +1 -1
- package/src/components/date-picker/DatePickerControlled.test.tsx +2 -0
- package/src/components/date-picker/DatePickerField.test.tsx +2 -0
- package/src/components/dialog/Dialog.test.tsx +2 -0
- 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.tsx +1 -1
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +2 -0
- 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.test.tsx +2 -0
- package/src/components/icon/Icon.tsx +120 -7
- 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 +2 -0
- 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 +2 -0
- package/src/components/link/Link.tsx +2 -0
- 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 +2 -0
- 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 +1 -0
- package/src/components/message/Message.tsx +1 -1
- package/src/components/mosaic/Mosaic.test.tsx +2 -0
- 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 +1 -1
- package/src/components/navigation/NavigationSection.test.tsx +2 -0
- package/src/components/navigation/NavigationSection.tsx +1 -1
- package/src/components/notification/Notification.test.tsx +2 -0
- 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 +1 -0
- 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 +2 -0
- 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 +2 -0
- package/src/components/select/Select.tsx +1 -1
- package/src/components/select/SelectMultiple.stories.tsx +1 -1
- package/src/components/select/SelectMultiple.test.tsx +2 -0
- 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 +2 -0
- package/src/components/side-navigation/SideNavigationItem.tsx +1 -1
- 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 +2 -0
- 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 +2 -0
- 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 +2 -0
- 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/RawInputText.stories.tsx +18 -0
- package/src/components/text-field/RawInputText.test.tsx +58 -0
- package/src/components/text-field/RawInputText.tsx +56 -0
- package/src/components/text-field/RawInputTextarea.stories.tsx +22 -0
- package/src/components/text-field/RawInputTextarea.test.tsx +63 -0
- package/src/components/text-field/RawInputTextarea.tsx +68 -0
- package/src/components/text-field/TextField.test.tsx +11 -2
- package/src/components/text-field/TextField.tsx +40 -210
- package/src/components/text-field/constants.ts +16 -0
- package/src/components/text-field/index.ts +3 -1
- package/src/components/text-field/useFitRowsToContent.ts +42 -0
- package/src/components/thumbnail/Thumbnail.test.tsx +2 -0
- package/src/components/toolbar/Toolbar.tsx +1 -1
- package/src/components/tooltip/Tooltip.stories.tsx +1 -2
- package/src/components/tooltip/Tooltip.test.tsx +1 -1
- package/src/components/uploader/Uploader.test.tsx +2 -0
- package/src/components/user-block/UserBlock.stories.tsx +2 -0
- package/src/components/user-block/UserBlock.test.tsx +2 -0
- 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/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 +1 -0
- package/src/utils/disabled/DisabledStateProvider.stories.tsx +2 -0
- package/src/utils/react/OnBeforeUnmount.tsx +1 -1
- package/src/utils/react/RawClickable.tsx +1 -1
- 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/utils/index.d.ts +7 -7
- package/utils/index.js +1 -1
|
@@ -3,7 +3,7 @@ import { List, ListItem, Select, Size, TextField } from '@lumx/react';
|
|
|
3
3
|
import { useBooleanState } from '@lumx/react/hooks/useBooleanState';
|
|
4
4
|
import noop from 'lodash/noop';
|
|
5
5
|
import range from 'lodash/range';
|
|
6
|
-
import { SyntheticEvent, useState } from 'react';
|
|
6
|
+
import React, { SyntheticEvent, useState } from 'react';
|
|
7
7
|
import { SelectVariant } from './constants';
|
|
8
8
|
|
|
9
9
|
export default {
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from '@lumx/react';
|
|
15
15
|
import { useBooleanState } from '@lumx/react/hooks/useBooleanState';
|
|
16
16
|
import noop from 'lodash/noop';
|
|
17
|
-
import { MouseEventHandler, SyntheticEvent, useRef, useState } from 'react';
|
|
17
|
+
import React, { MouseEventHandler, SyntheticEvent, useRef, useState } from 'react';
|
|
18
18
|
import { SelectVariant } from './constants';
|
|
19
19
|
|
|
20
20
|
export default { title: 'LumX components/select/Select Multiple' };
|
|
@@ -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';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { withValueOnChange } from '@lumx/react/stories/decorators/withValueOnChange';
|
|
2
|
+
import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
|
|
3
|
+
|
|
4
|
+
import { RawInputText } from './RawInputText';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'LumX components/text-field/RawInputText',
|
|
8
|
+
component: RawInputText,
|
|
9
|
+
decorators: [withValueOnChange(), withWrapper({ style: { border: '1px dashed red' } })],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Default = {};
|
|
13
|
+
|
|
14
|
+
export const WithPlaceholder = {
|
|
15
|
+
args: {
|
|
16
|
+
placeholder: 'Input placeholder',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
|
|
6
|
+
import { RawInputText, RawInputTextProps } from './RawInputText';
|
|
7
|
+
import { INPUT_NATIVE_CLASSNAME } from './constants';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
11
|
+
*/
|
|
12
|
+
const setup = (propsOverride: Partial<RawInputTextProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
|
|
13
|
+
const props: any = { ...propsOverride };
|
|
14
|
+
render(<RawInputText {...props} />, { wrapper });
|
|
15
|
+
const input = getByClassName(document.body, INPUT_NATIVE_CLASSNAME);
|
|
16
|
+
return { props, input };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe(`<${RawInputText.displayName}>`, () => {
|
|
20
|
+
describe('Props', () => {
|
|
21
|
+
it('should render default', () => {
|
|
22
|
+
const { input } = setup();
|
|
23
|
+
expect(input).toBeInTheDocument();
|
|
24
|
+
expect(input?.tagName).toBe('INPUT');
|
|
25
|
+
expect(input).toHaveAttribute('type', 'text');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should render with custom type', () => {
|
|
29
|
+
const { input } = setup({ type: 'number' });
|
|
30
|
+
expect(input).toHaveAttribute('type', 'number');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('Events', () => {
|
|
35
|
+
it('should call onChange with correct value when typing', async () => {
|
|
36
|
+
const onChange = vi.fn();
|
|
37
|
+
const name = 'inputName';
|
|
38
|
+
const { input } = setup({ onChange, name });
|
|
39
|
+
await userEvent.type(input as Element, 'hello');
|
|
40
|
+
expect(onChange).toHaveBeenCalledWith('h', name, expect.any(Object));
|
|
41
|
+
expect(onChange).toHaveBeenCalledWith('hello', name, expect.any(Object));
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Common tests suite.
|
|
46
|
+
commonTestsSuiteRTL(setup, {
|
|
47
|
+
baseClassName: INPUT_NATIVE_CLASSNAME,
|
|
48
|
+
forwardClassName: 'input',
|
|
49
|
+
forwardAttributes: 'input',
|
|
50
|
+
forwardRef: 'input',
|
|
51
|
+
applyTheme: {
|
|
52
|
+
affects: [{ element: 'input' }],
|
|
53
|
+
viaProp: true,
|
|
54
|
+
viaContext: true,
|
|
55
|
+
defaultTheme: 'light',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { ComponentProps, ChangeEventHandler, SyntheticEvent, useRef, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
|
|
5
|
+
import { Theme, useTheme } from '@lumx/react';
|
|
6
|
+
|
|
7
|
+
import { forwardRef } from '@lumx/react/utils/react/forwardRef';
|
|
8
|
+
import { useMergeRefs } from '@lumx/react/utils/react/mergeRefs';
|
|
9
|
+
import { HasClassName, HasTheme } from '@lumx/react/utils/type';
|
|
10
|
+
import { handleBasicClasses } from '@lumx/core/js/utils';
|
|
11
|
+
|
|
12
|
+
import { INPUT_NATIVE_CLASSNAME } from './constants';
|
|
13
|
+
|
|
14
|
+
type NativeInputProps = Omit<ComponentProps<'input'>, 'value' | 'onChange'>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Defines the props of the component.
|
|
18
|
+
*/
|
|
19
|
+
export interface RawInputTextProps extends NativeInputProps, HasTheme, HasClassName {
|
|
20
|
+
value?: string;
|
|
21
|
+
onChange?: (value: string, name?: string, event?: SyntheticEvent) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Component default props.
|
|
25
|
+
*/
|
|
26
|
+
export const DEFAULT_PROPS: Partial<RawInputTextProps> = {
|
|
27
|
+
type: 'text',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Raw input text component
|
|
32
|
+
* (input element without any decoration)
|
|
33
|
+
*/
|
|
34
|
+
export const RawInputText = forwardRef<RawInputTextProps, HTMLInputElement>((props, ref) => {
|
|
35
|
+
const defaultTheme = useTheme() || Theme.light;
|
|
36
|
+
const { className, theme = defaultTheme, value, onChange, type = DEFAULT_PROPS.type, ...forwardedProps } = props;
|
|
37
|
+
const textareaRef = useRef<HTMLInputElement>(null);
|
|
38
|
+
|
|
39
|
+
const handleChange: ChangeEventHandler<HTMLInputElement> = useCallback(
|
|
40
|
+
(evt) => {
|
|
41
|
+
onChange?.(evt.target.value, evt.target.name, evt);
|
|
42
|
+
},
|
|
43
|
+
[onChange],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<input
|
|
48
|
+
{...forwardedProps}
|
|
49
|
+
type={type}
|
|
50
|
+
ref={useMergeRefs(ref, textareaRef)}
|
|
51
|
+
className={classNames(className, handleBasicClasses({ prefix: INPUT_NATIVE_CLASSNAME, theme }))}
|
|
52
|
+
onChange={handleChange}
|
|
53
|
+
value={value}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { withValueOnChange } from '@lumx/react/stories/decorators/withValueOnChange';
|
|
2
|
+
import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
|
|
3
|
+
|
|
4
|
+
import { RawInputTextarea } from './RawInputTextarea';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'LumX components/text-field/RawInputTextarea',
|
|
8
|
+
component: RawInputTextarea,
|
|
9
|
+
decorators: [withValueOnChange(), withWrapper({ style: { border: '1px dashed red' } })],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const Default = {};
|
|
13
|
+
|
|
14
|
+
export const WithMinimumRows = {
|
|
15
|
+
args: { minimumRows: 3 },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const WithPlaceholder = {
|
|
19
|
+
args: {
|
|
20
|
+
placeholder: 'Input placeholder',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { getByClassName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
|
|
6
|
+
import { RawInputTextarea, RawInputTextareaProps, DEFAULT_PROPS } from './RawInputTextarea';
|
|
7
|
+
import { INPUT_NATIVE_CLASSNAME } from './constants';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
11
|
+
*/
|
|
12
|
+
const setup = (propsOverride: Partial<RawInputTextareaProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
|
|
13
|
+
const props: any = { ...propsOverride };
|
|
14
|
+
render(<RawInputTextarea {...props} />, { wrapper });
|
|
15
|
+
const textarea = getByClassName(document.body, INPUT_NATIVE_CLASSNAME);
|
|
16
|
+
return { props, textarea };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe(`<${RawInputTextarea.displayName}>`, () => {
|
|
20
|
+
describe('Props', () => {
|
|
21
|
+
it('should render default', () => {
|
|
22
|
+
const { textarea } = setup();
|
|
23
|
+
expect(textarea).toBeInTheDocument();
|
|
24
|
+
expect(textarea?.tagName).toBe('TEXTAREA');
|
|
25
|
+
expect(textarea).toHaveAttribute('rows', String(DEFAULT_PROPS.minimumRows));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should render with custom minimumRows', () => {
|
|
29
|
+
const { textarea } = setup({ minimumRows: 5 });
|
|
30
|
+
expect(textarea).toHaveAttribute('rows', '5');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should render with placeholder', () => {
|
|
34
|
+
const { textarea } = setup({ placeholder: 'Test placeholder' });
|
|
35
|
+
expect(textarea).toHaveAttribute('placeholder', 'Test placeholder');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('Events', () => {
|
|
40
|
+
it('should call onChange with correct value when typing', async () => {
|
|
41
|
+
const onChange = vi.fn();
|
|
42
|
+
const name = 'textareaName';
|
|
43
|
+
const { textarea } = setup({ onChange, name });
|
|
44
|
+
await userEvent.type(textarea as Element, 'hello');
|
|
45
|
+
expect(onChange).toHaveBeenCalledWith('h', name, expect.any(Object));
|
|
46
|
+
expect(onChange).toHaveBeenCalledWith('hello', name, expect.any(Object));
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Common tests suite.
|
|
51
|
+
commonTestsSuiteRTL(setup, {
|
|
52
|
+
baseClassName: INPUT_NATIVE_CLASSNAME,
|
|
53
|
+
forwardClassName: 'textarea',
|
|
54
|
+
forwardAttributes: 'textarea',
|
|
55
|
+
forwardRef: 'textarea',
|
|
56
|
+
applyTheme: {
|
|
57
|
+
affects: [{ element: 'textarea' }],
|
|
58
|
+
viaProp: true,
|
|
59
|
+
viaContext: true,
|
|
60
|
+
defaultTheme: 'light',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
});
|