@onewelcome/react-lib-components 0.2.0 → 0.2.3
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/dist/Breadcrumbs/Breadcrumbs.d.ts +4 -4
- package/dist/Button/BaseButton.d.ts +4 -4
- package/dist/Button/Button.d.ts +3 -3
- package/dist/Button/IconButton.d.ts +4 -4
- package/dist/ContextMenu/ContextMenu.d.ts +5 -5
- package/dist/ContextMenu/ContextMenuItem.d.ts +2 -2
- package/dist/DataGrid/DataGrid.d.ts +6 -6
- package/dist/DataGrid/DataGridActions/DataGridActions.d.ts +4 -4
- package/dist/DataGrid/DataGridActions/DataGridColumnsToggle.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridBody.d.ts +3 -3
- package/dist/DataGrid/DataGridBody/DataGridCell.d.ts +2 -2
- package/dist/DataGrid/DataGridBody/DataGridRow.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeader.d.ts +3 -3
- package/dist/DataGrid/DataGridHeader/DataGridHeaderCell.d.ts +3 -3
- package/dist/DataGrid/datagrid.interfaces.d.ts +1 -1
- package/dist/Form/Checkbox/Checkbox.d.ts +5 -5
- package/dist/Form/Fieldset/Fieldset.d.ts +3 -3
- package/dist/Form/Form.d.ts +1 -1
- package/dist/Form/FormControl/FormControl.d.ts +3 -3
- package/dist/Form/FormGroup/FormGroup.d.ts +5 -5
- package/dist/Form/FormHelperText/FormHelperText.d.ts +3 -3
- package/dist/Form/FormSelectorWrapper/FormSelectorWrapper.d.ts +6 -6
- package/dist/Form/Input/Input.d.ts +5 -5
- package/dist/Form/Label/Label.d.ts +2 -2
- package/dist/Form/Radio/Radio.d.ts +5 -5
- package/dist/Form/Select/Option.d.ts +2 -2
- package/dist/Form/Select/Select.d.ts +5 -5
- package/dist/Form/Textarea/Textarea.d.ts +6 -6
- package/dist/Form/Toggle/Toggle.d.ts +3 -3
- package/dist/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/InputWrapper/InputWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/RadioWrapper/RadioWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/SelectWrapper/SelectWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/TextareaWrapper/TextareaWrapper.d.ts +4 -4
- package/dist/Form/Wrapper/Wrapper/Wrapper.d.ts +6 -6
- package/dist/Form/form.interfaces.d.ts +1 -1
- package/dist/Icon/Icon.d.ts +3 -3
- package/dist/Link/Link.d.ts +7 -7
- package/dist/Notifications/BaseModal/BaseModal.d.ts +4 -4
- package/dist/Notifications/BaseModal/BaseModalActions/BaseModalActions.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalContent/BaseModalContent.d.ts +2 -2
- package/dist/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.d.ts +2 -2
- package/dist/Notifications/Dialog/Dialog.d.ts +5 -5
- package/dist/Notifications/Dialog/DialogActions/DialogActions.d.ts +3 -3
- package/dist/Notifications/Dialog/DialogTitle/DialogTitle.d.ts +2 -2
- package/dist/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.d.ts +3 -3
- package/dist/Notifications/DiscardChangesModal/DiscardChangesModal.d.ts +7 -7
- package/dist/Notifications/Modal/Modal.d.ts +1 -1
- package/dist/Notifications/Modal/ModalActions/ModalActions.d.ts +1 -1
- package/dist/Notifications/Modal/ModalContent/ModalContent.d.ts +1 -1
- package/dist/Notifications/Modal/ModalHeader/ModalHeader.d.ts +1 -1
- package/dist/Notifications/SlideInModal/SlideInModal.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarItem/SnackbarItem.d.ts +2 -2
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.d.ts +3 -3
- package/dist/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.d.ts +2 -2
- package/dist/Notifications/Snackbar/interfaces.d.ts +2 -2
- package/dist/Pagination/Pagination.d.ts +3 -3
- package/dist/Popover/Popover.d.ts +3 -3
- package/dist/Skeleton/Skeleton.d.ts +3 -3
- package/dist/StatusIndicator/StatusIndicator.d.ts +5 -5
- package/dist/Tabs/Tab.d.ts +1 -1
- package/dist/Tabs/TabButton.d.ts +2 -2
- package/dist/Tabs/TabPanel.d.ts +2 -2
- package/dist/Tabs/Tabs.d.ts +4 -4
- package/dist/TextEllipsis/TextEllipsis.d.ts +2 -2
- package/dist/Tiles/Tile.d.ts +5 -5
- package/dist/Tiles/Tiles.d.ts +2 -2
- package/dist/Tooltip/Tooltip.d.ts +3 -3
- package/dist/Typography/Typography.d.ts +3 -3
- package/dist/Wizard/BaseWizardSteps/BaseWizardSteps.d.ts +2 -2
- package/dist/Wizard/Wizard.d.ts +3 -3
- package/dist/Wizard/WizardActions/WizardActions.d.ts +2 -2
- package/dist/Wizard/WizardStateProvider.d.ts +2 -2
- package/dist/Wizard/WizardSteps/WizardSteps.d.ts +2 -2
- package/dist/Wizard/wizardStateReducer.d.ts +5 -5
- package/dist/_BaseStyling_/BaseStyling.d.ts +1 -1
- package/dist/hooks/usePosition.d.ts +4 -4
- package/dist/hooks/useRepeater.d.ts +1 -1
- package/dist/hooks/useScroll.d.ts +1 -1
- package/dist/hooks/useSpacing.d.ts +1 -1
- package/dist/hooks/useWrapper.d.ts +1 -1
- package/dist/index.d.ts +55 -55
- package/dist/react-lib-components.cjs.development.js +676 -578
- package/dist/react-lib-components.cjs.development.js.map +1 -1
- package/dist/react-lib-components.cjs.production.min.js +1 -1
- package/dist/react-lib-components.cjs.production.min.js.map +1 -1
- package/dist/react-lib-components.esm.js +676 -578
- package/dist/react-lib-components.esm.js.map +1 -1
- package/package.json +27 -16
- package/src/Breadcrumbs/Breadcrumbs.test.tsx +15 -15
- package/src/Breadcrumbs/Breadcrumbs.tsx +11 -11
- package/src/Button/BaseButton.module.scss +1 -1
- package/src/Button/BaseButton.test.tsx +27 -27
- package/src/Button/BaseButton.tsx +8 -8
- package/src/Button/Button.module.scss +5 -5
- package/src/Button/Button.test.tsx +39 -39
- package/src/Button/Button.tsx +10 -10
- package/src/Button/IconButton.module.scss +5 -5
- package/src/Button/IconButton.test.tsx +29 -29
- package/src/Button/IconButton.tsx +11 -11
- package/src/ContextMenu/ContextMenu.test.tsx +97 -76
- package/src/ContextMenu/ContextMenu.tsx +48 -42
- package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
- package/src/ContextMenu/ContextMenuItem.tsx +7 -5
- package/src/DataGrid/DataGrid.test.tsx +193 -193
- package/src/DataGrid/DataGrid.tsx +26 -26
- package/src/DataGrid/DataGridActions/DataGridActions.test.tsx +63 -63
- package/src/DataGrid/DataGridActions/DataGridActions.tsx +15 -15
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.module.scss +1 -1
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.test.tsx +21 -21
- package/src/DataGrid/DataGridActions/DataGridColumnsToggle.tsx +20 -20
- package/src/DataGrid/DataGridBody/DataGridBody.test.tsx +40 -40
- package/src/DataGrid/DataGridBody/DataGridBody.tsx +10 -10
- package/src/DataGrid/DataGridBody/DataGridCell.module.scss +1 -1
- package/src/DataGrid/DataGridBody/DataGridCell.test.tsx +25 -25
- package/src/DataGrid/DataGridBody/DataGridCell.tsx +6 -6
- package/src/DataGrid/DataGridBody/DataGridRow.test.tsx +38 -38
- package/src/DataGrid/DataGridBody/DataGridRow.tsx +8 -8
- package/src/DataGrid/DataGridHeader/DataGridHeader.module.scss +1 -2
- package/src/DataGrid/DataGridHeader/DataGridHeader.test.tsx +119 -119
- package/src/DataGrid/DataGridHeader/DataGridHeader.tsx +13 -13
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.module.scss +2 -0
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.test.tsx +51 -51
- package/src/DataGrid/DataGridHeader/DataGridHeaderCell.tsx +14 -14
- package/src/DataGrid/datagrid.interfaces.ts +1 -1
- package/src/Form/Checkbox/Checkbox.test.tsx +74 -74
- package/src/Form/Checkbox/Checkbox.tsx +27 -27
- package/src/Form/Fieldset/Fieldset.module.scss +1 -1
- package/src/Form/Fieldset/Fieldset.test.tsx +35 -35
- package/src/Form/Fieldset/Fieldset.tsx +27 -27
- package/src/Form/Form.test.tsx +18 -18
- package/src/Form/Form.tsx +3 -3
- package/src/Form/FormControl/FormControl.test.tsx +22 -22
- package/src/Form/FormControl/FormControl.tsx +10 -10
- package/src/Form/FormGroup/FormGroup.test.tsx +37 -37
- package/src/Form/FormGroup/FormGroup.tsx +16 -16
- package/src/Form/FormHelperText/FormHelperText.test.tsx +18 -18
- package/src/Form/FormHelperText/FormHelperText.tsx +7 -7
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.test.tsx +15 -15
- package/src/Form/FormSelectorWrapper/FormSelectorWrapper.tsx +14 -14
- package/src/Form/Input/Input.module.scss +20 -44
- package/src/Form/Input/Input.test.tsx +121 -73
- package/src/Form/Input/Input.tsx +96 -35
- package/src/Form/Label/Label.test.tsx +13 -13
- package/src/Form/Label/Label.tsx +6 -6
- package/src/Form/Radio/Radio.test.tsx +35 -35
- package/src/Form/Radio/Radio.tsx +17 -17
- package/src/Form/Select/Option.test.tsx +10 -10
- package/src/Form/Select/Option.tsx +8 -8
- package/src/Form/Select/Select.module.scss +7 -9
- package/src/Form/Select/Select.test.tsx +144 -141
- package/src/Form/Select/Select.tsx +79 -78
- package/src/Form/Textarea/Textarea.module.scss +8 -18
- package/src/Form/Textarea/Textarea.test.tsx +27 -27
- package/src/Form/Textarea/Textarea.tsx +33 -13
- package/src/Form/Toggle/Toggle.module.scss +1 -1
- package/src/Form/Toggle/Toggle.test.tsx +22 -22
- package/src/Form/Toggle/Toggle.tsx +10 -10
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.test.tsx +39 -39
- package/src/Form/Wrapper/CheckboxWrapper/CheckboxWrapper.tsx +12 -12
- package/src/Form/Wrapper/InputWrapper/InputWrapper.module.scss +2 -8
- package/src/Form/Wrapper/InputWrapper/InputWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/InputWrapper/InputWrapper.tsx +30 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.test.tsx +35 -35
- package/src/Form/Wrapper/RadioWrapper/RadioWrapper.tsx +12 -12
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.test.tsx +55 -55
- package/src/Form/Wrapper/SelectWrapper/SelectWrapper.tsx +12 -12
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.module.scss +2 -11
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.test.tsx +50 -50
- package/src/Form/Wrapper/TextareaWrapper/TextareaWrapper.tsx +22 -22
- package/src/Form/Wrapper/Wrapper/Wrapper.module.scss +2 -2
- package/src/Form/Wrapper/Wrapper/Wrapper.test.tsx +11 -11
- package/src/Form/Wrapper/Wrapper/Wrapper.tsx +17 -17
- package/src/Form/form.interfaces.ts +1 -1
- package/src/Icon/Icon.module.scss +71 -71
- package/src/Icon/Icon.test.tsx +18 -18
- package/src/Icon/Icon.tsx +70 -70
- package/src/Link/Link.module.scss +5 -5
- package/src/Link/Link.test.tsx +76 -76
- package/src/Link/Link.tsx +27 -27
- package/src/Link/types.d.ts +1 -1
- package/src/Notifications/BaseModal/BaseModal.module.scss +1 -1
- package/src/Notifications/BaseModal/BaseModal.test.tsx +53 -53
- package/src/Notifications/BaseModal/BaseModal.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.test.tsx +13 -13
- package/src/Notifications/BaseModal/BaseModalActions/BaseModalActions.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.test.tsx +16 -16
- package/src/Notifications/BaseModal/BaseModalContent/BaseModalContent.tsx +5 -5
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.test.tsx +19 -19
- package/src/Notifications/BaseModal/BaseModalHeader/BaseModalHeader.tsx +10 -10
- package/src/Notifications/Dialog/Dialog.test.tsx +35 -35
- package/src/Notifications/Dialog/Dialog.tsx +19 -19
- package/src/Notifications/Dialog/DialogActions/DialogActions.test.tsx +14 -14
- package/src/Notifications/Dialog/DialogActions/DialogActions.tsx +6 -6
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.test.tsx +12 -12
- package/src/Notifications/Dialog/DialogTitle/DialogTitle.tsx +6 -6
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.test.tsx +20 -20
- package/src/Notifications/DiscardChangesModal/DiscardChangesDialog/DiscardChangesDialog.tsx +7 -7
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.test.tsx +36 -36
- package/src/Notifications/DiscardChangesModal/DiscardChangesModal.tsx +8 -8
- package/src/Notifications/Modal/Modal.test.tsx +6 -6
- package/src/Notifications/Modal/Modal.tsx +1 -1
- package/src/Notifications/Modal/ModalActions/ModalActions.tsx +2 -2
- package/src/Notifications/Modal/ModalContent/ModalContent.tsx +2 -2
- package/src/Notifications/Modal/ModalHeader/ModalHeader.tsx +2 -2
- package/src/Notifications/SlideInModal/SlideInModal.test.tsx +16 -16
- package/src/Notifications/SlideInModal/SlideInModal.tsx +16 -11
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.test.tsx +16 -16
- package/src/Notifications/Snackbar/SnackbarContainer/SnackbarContainer.tsx +6 -6
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.module.scss +2 -2
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.test.tsx +17 -17
- package/src/Notifications/Snackbar/SnackbarItem/SnackbarItem.tsx +23 -23
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.test.tsx +32 -32
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarProvider.tsx +18 -18
- package/src/Notifications/Snackbar/SnackbarProvider/SnackbarStateProvider.tsx +3 -3
- package/src/Notifications/Snackbar/interfaces.ts +2 -2
- package/src/Notifications/Snackbar/useSnackbar.ts +2 -2
- package/src/Pagination/Pagination.module.scss +2 -0
- package/src/Pagination/Pagination.test.tsx +47 -47
- package/src/Pagination/Pagination.tsx +35 -35
- package/src/Popover/Popover.test.tsx +19 -19
- package/src/Popover/Popover.tsx +7 -7
- package/src/Skeleton/Skeleton.module.scss +2 -2
- package/src/Skeleton/Skeleton.test.tsx +29 -29
- package/src/Skeleton/Skeleton.tsx +10 -10
- package/src/StatusIndicator/StatusIndicator.test.tsx +38 -38
- package/src/StatusIndicator/StatusIndicator.tsx +9 -9
- package/src/Tabs/Tab.test.tsx +13 -13
- package/src/Tabs/Tab.tsx +1 -1
- package/src/Tabs/TabButton.test.tsx +28 -28
- package/src/Tabs/TabButton.tsx +7 -7
- package/src/Tabs/TabPanel.test.tsx +30 -30
- package/src/Tabs/TabPanel.tsx +4 -4
- package/src/Tabs/Tabs.test.tsx +93 -93
- package/src/Tabs/Tabs.tsx +25 -25
- package/src/TextEllipsis/TextEllipsis.test.tsx +22 -22
- package/src/TextEllipsis/TextEllipsis.tsx +6 -6
- package/src/Tiles/Tile.module.scss +1 -1
- package/src/Tiles/Tile.test.tsx +42 -42
- package/src/Tiles/Tile.tsx +22 -22
- package/src/Tiles/Tiles.test.tsx +30 -30
- package/src/Tiles/Tiles.tsx +9 -9
- package/src/Tooltip/Tooltip.test.tsx +35 -35
- package/src/Tooltip/Tooltip.tsx +21 -21
- package/src/Typography/Typography.module.scss +1 -1
- package/src/Typography/Typography.test.tsx +49 -49
- package/src/Typography/Typography.tsx +42 -42
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.module.scss +1 -1
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.test.tsx +26 -26
- package/src/Wizard/BaseWizardSteps/BaseWizardSteps.tsx +24 -24
- package/src/Wizard/Wizard.test.tsx +56 -56
- package/src/Wizard/Wizard.tsx +6 -6
- package/src/Wizard/WizardActions/WizardActions.test.tsx +34 -34
- package/src/Wizard/WizardActions/WizardActions.tsx +14 -14
- package/src/Wizard/WizardStateProvider.tsx +3 -3
- package/src/Wizard/WizardSteps/WizardSteps.test.tsx +27 -27
- package/src/Wizard/WizardSteps/WizardSteps.tsx +7 -7
- package/src/Wizard/wizardStateReducer.ts +9 -9
- package/src/_BaseStyling_/BaseStyling.test.tsx +14 -14
- package/src/_BaseStyling_/BaseStyling.tsx +50 -50
- package/src/hooks/useAnimation.test.tsx +12 -12
- package/src/hooks/useAnimation.ts +4 -4
- package/src/hooks/useBodyClick.test.tsx +8 -8
- package/src/hooks/useBodyClick.ts +3 -3
- package/src/hooks/useFormSelector.test.ts +17 -17
- package/src/hooks/useFormSelector.ts +4 -4
- package/src/hooks/usePosition.test.tsx +215 -215
- package/src/hooks/usePosition.ts +68 -68
- package/src/hooks/useRepeater.test.tsx +26 -26
- package/src/hooks/useRepeater.ts +5 -5
- package/src/hooks/useScroll.test.tsx +5 -5
- package/src/hooks/useScroll.ts +3 -3
- package/src/hooks/useSpacing.test.ts +40 -40
- package/src/hooks/useSpacing.ts +3 -3
- package/src/hooks/useWrapper.test.ts +12 -12
- package/src/hooks/useWrapper.ts +14 -7
- package/src/index.ts +67 -67
- package/src/mixins.module.scss +76 -27
- package/src/types.d.ts +1 -1
- package/src/util/helper.test.tsx +25 -25
- package/src/util/helper.tsx +64 -64
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, useEffect, useRef, useState } from
|
|
2
|
-
import { Input, Type, Props as InputProps } from
|
|
3
|
-
import classes from
|
|
4
|
-
import { Wrapper, WrapperProps } from
|
|
5
|
-
import { useWrapper } from
|
|
1
|
+
import React, { ComponentPropsWithRef, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Input, Type, Props as InputProps } from "../../Input/Input";
|
|
3
|
+
import classes from "./InputWrapper.module.scss";
|
|
4
|
+
import { Wrapper, WrapperProps } from "../Wrapper/Wrapper";
|
|
5
|
+
import { useWrapper } from "../../../hooks/useWrapper";
|
|
6
6
|
|
|
7
7
|
interface PartialInputProps extends Partial<InputProps> {}
|
|
8
8
|
|
|
9
|
-
export interface Props extends ComponentPropsWithRef<
|
|
9
|
+
export interface Props extends ComponentPropsWithRef<"div">, WrapperProps {
|
|
10
10
|
label: string;
|
|
11
11
|
type: Type;
|
|
12
12
|
name: string;
|
|
@@ -18,7 +18,6 @@ export interface Props extends ComponentPropsWithRef<'div'>, WrapperProps {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const useLabelOffset = (
|
|
21
|
-
wrapper: React.RefObject<HTMLDivElement>,
|
|
22
21
|
input: React.RefObject<HTMLInputElement>,
|
|
23
22
|
floatingLabelActive: boolean,
|
|
24
23
|
prefix?: string
|
|
@@ -28,19 +27,17 @@ const useLabelOffset = (
|
|
|
28
27
|
const resetLabelOffset = () => setLabelOffset({ left: undefined });
|
|
29
28
|
|
|
30
29
|
useEffect(() => {
|
|
31
|
-
if (
|
|
30
|
+
if (input.current && prefix) {
|
|
32
31
|
if (floatingLabelActive) {
|
|
33
32
|
resetLabelOffset();
|
|
34
33
|
} else {
|
|
34
|
+
const spacingBetweenPrefixAndInput = 4;
|
|
35
35
|
const prefixDifference =
|
|
36
|
-
input.current
|
|
37
|
-
wrapper.current.getBoundingClientRect().left +
|
|
38
|
-
4;
|
|
39
|
-
|
|
36
|
+
getComputedStyle(input.current).paddingLeft + spacingBetweenPrefixAndInput;
|
|
40
37
|
setLabelOffset({ left: `${prefixDifference}px` });
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
}, [
|
|
40
|
+
}, [input.current, prefix, floatingLabelActive]);
|
|
44
41
|
|
|
45
42
|
return { labelOffset };
|
|
46
43
|
};
|
|
@@ -70,32 +67,30 @@ export const InputWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
70
67
|
hasFocus,
|
|
71
68
|
setHasFocus,
|
|
72
69
|
helperId,
|
|
73
|
-
labelId
|
|
70
|
+
labelId
|
|
74
71
|
} = useWrapper(value, inputProps?.placeholder, type);
|
|
75
72
|
const { prefix, suffix } = inputProps || {};
|
|
76
|
-
const wrapper = useRef<HTMLDivElement>(null);
|
|
77
73
|
const input = useRef<HTMLInputElement>(null);
|
|
78
74
|
const hasValueOrActiveFloatingLabel = !!value || floatingLabelActive;
|
|
79
|
-
const labelClasses = [classes[
|
|
75
|
+
const labelClasses = [classes["input-label"]];
|
|
80
76
|
const { labelOffset } = useLabelOffset(
|
|
81
|
-
(ref as React.RefObject<HTMLDivElement>) || wrapper,
|
|
82
77
|
(inputProps && (inputProps.ref as React.RefObject<HTMLInputElement>)) || input,
|
|
83
78
|
floatingLabelActive,
|
|
84
79
|
prefix
|
|
85
80
|
);
|
|
86
81
|
|
|
87
|
-
hasFocus && labelClasses.push(classes[
|
|
82
|
+
hasFocus && labelClasses.push(classes["focus"]);
|
|
88
83
|
|
|
89
84
|
return (
|
|
90
85
|
<Wrapper
|
|
91
86
|
{...rest}
|
|
92
|
-
ref={ref
|
|
87
|
+
ref={ref}
|
|
93
88
|
name={name}
|
|
94
|
-
className={`${classes[
|
|
89
|
+
className={`${classes["input-wrapper"]} ${className ?? ""}`}
|
|
95
90
|
labelProps={{
|
|
96
91
|
id: labelId,
|
|
97
|
-
className: labelClasses.join(
|
|
98
|
-
style: { ...labelOffset }
|
|
92
|
+
className: labelClasses.join(" "),
|
|
93
|
+
style: { ...labelOffset }
|
|
99
94
|
}}
|
|
100
95
|
floatingLabelActive={floatingLabelActive}
|
|
101
96
|
errorId={errorId}
|
|
@@ -104,42 +99,42 @@ export const InputWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
104
99
|
helperText={helperText}
|
|
105
100
|
helperProps={{
|
|
106
101
|
...helperProps,
|
|
107
|
-
className: `${classes[
|
|
102
|
+
className: `${classes["input-wrapper-helper"]} ${helperProps?.className ?? ""} `
|
|
108
103
|
}}
|
|
109
104
|
helperIndent={20}
|
|
110
105
|
>
|
|
111
106
|
<Input
|
|
112
107
|
{...inputProps}
|
|
113
|
-
prefix={hasValueOrActiveFloatingLabel ? prefix :
|
|
114
|
-
suffix={hasValueOrActiveFloatingLabel ? suffix :
|
|
108
|
+
prefix={hasValueOrActiveFloatingLabel ? prefix : ""}
|
|
109
|
+
suffix={hasValueOrActiveFloatingLabel ? suffix : ""}
|
|
115
110
|
wrapperProps={{
|
|
116
|
-
className: `${floatingLabelActive ? classes[
|
|
117
|
-
inputProps?.wrapperProps?.className ??
|
|
118
|
-
}
|
|
111
|
+
className: `${floatingLabelActive ? classes["floating-label-active"] : ""} ${
|
|
112
|
+
inputProps?.wrapperProps?.className ?? ""
|
|
113
|
+
}`
|
|
119
114
|
}}
|
|
120
115
|
ref={(inputProps && inputProps.ref) || input}
|
|
121
116
|
aria-labelledby={labelId}
|
|
122
117
|
aria-describedby={error ? errorId : helperId}
|
|
123
118
|
onChange={onChange}
|
|
124
|
-
onFocus={
|
|
119
|
+
onFocus={e => {
|
|
125
120
|
onFocus && onFocus(e);
|
|
126
121
|
setHasFocus(true);
|
|
127
122
|
setFloatingLabelActive(true);
|
|
128
123
|
}}
|
|
129
|
-
onBlur={
|
|
124
|
+
onBlur={e => {
|
|
130
125
|
onBlur && onBlur(e);
|
|
131
126
|
setHasFocus(false);
|
|
132
127
|
e.target.value ||
|
|
133
128
|
e.target.placeholder ||
|
|
134
129
|
inputProps?.placeholder?.length ||
|
|
135
|
-
type ===
|
|
136
|
-
type ===
|
|
137
|
-
type ===
|
|
130
|
+
type === "datetime-local" ||
|
|
131
|
+
type === "time" ||
|
|
132
|
+
type === "date"
|
|
138
133
|
? setFloatingLabelActive(true)
|
|
139
134
|
: setFloatingLabelActive(false);
|
|
140
135
|
}}
|
|
141
|
-
className={`${floatingLabelActive ? classes[
|
|
142
|
-
inputProps?.className ??
|
|
136
|
+
className={`${floatingLabelActive ? classes["floating-label"] : ""} ${
|
|
137
|
+
inputProps?.className ?? ""
|
|
143
138
|
}`}
|
|
144
139
|
name={name}
|
|
145
140
|
error={error}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { RadioWrapper, Props } from
|
|
3
|
-
import { Radio } from
|
|
4
|
-
import { render } from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RadioWrapper, Props } from "./RadioWrapper";
|
|
3
|
+
import { Radio } from "../../Radio/Radio";
|
|
4
|
+
import { render } from "@testing-library/react";
|
|
5
5
|
|
|
6
6
|
const onChangeHandler = jest.fn();
|
|
7
|
-
const checkedOptionValue =
|
|
7
|
+
const checkedOptionValue = "option1";
|
|
8
8
|
|
|
9
9
|
const defaultParams: Props = {
|
|
10
|
-
label:
|
|
11
|
-
errorMessage:
|
|
12
|
-
helperText:
|
|
10
|
+
label: "Label",
|
|
11
|
+
errorMessage: "Error message",
|
|
12
|
+
helperText: "Helper text",
|
|
13
13
|
error: false,
|
|
14
14
|
onChange: onChangeHandler,
|
|
15
|
-
fieldsetProps: { legend:
|
|
15
|
+
fieldsetProps: { legend: "Example title" },
|
|
16
16
|
value: checkedOptionValue,
|
|
17
|
-
name:
|
|
17
|
+
name: "my-group",
|
|
18
18
|
children: [
|
|
19
19
|
<Radio helperText="This is helpertext" value="option1">
|
|
20
20
|
Option 1
|
|
21
21
|
</Radio>,
|
|
22
22
|
<Radio value="option2">Option 2</Radio>,
|
|
23
|
-
<Radio value="option3">Option 3</Radio
|
|
24
|
-
]
|
|
23
|
+
<Radio value="option3">Option 3</Radio>
|
|
24
|
+
]
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const createRadioWrapper = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -30,72 +30,72 @@ const createRadioWrapper = (params?: (defaultParams: Props) => Props) => {
|
|
|
30
30
|
parameters = params(defaultParams);
|
|
31
31
|
}
|
|
32
32
|
const queries = render(<RadioWrapper {...parameters} data-testid="radiowrapper" />);
|
|
33
|
-
const radiowrapper = queries.getByTestId(
|
|
33
|
+
const radiowrapper = queries.getByTestId("radiowrapper");
|
|
34
34
|
|
|
35
35
|
return {
|
|
36
36
|
...queries,
|
|
37
|
-
radiowrapper
|
|
37
|
+
radiowrapper
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
describe(
|
|
42
|
-
it(
|
|
41
|
+
describe("RadioWrapper should render", () => {
|
|
42
|
+
it("renders without crashing", () => {
|
|
43
43
|
const { radiowrapper } = createRadioWrapper();
|
|
44
44
|
|
|
45
45
|
expect(radiowrapper).toBeTruthy();
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it(
|
|
48
|
+
it("has option 1 properly linked with aria-describedby to its helpertext", () => {
|
|
49
49
|
const { radiowrapper } = createRadioWrapper();
|
|
50
50
|
|
|
51
51
|
const option1RadioWrapper = radiowrapper
|
|
52
52
|
?.querySelector('input[value="option1"]')
|
|
53
|
-
?.closest(
|
|
53
|
+
?.closest(".radio-wrapper");
|
|
54
54
|
const option1 = radiowrapper?.querySelector('input[value="option1"]');
|
|
55
|
-
const option1helper = option1RadioWrapper?.querySelector(
|
|
55
|
+
const option1helper = option1RadioWrapper?.querySelector(".helper-text");
|
|
56
56
|
|
|
57
57
|
if (option1helper && option1) {
|
|
58
|
-
expect(`${option1helper.getAttribute(
|
|
58
|
+
expect(`${option1helper.getAttribute("id")}-radio`).toBe(`${option1.getAttribute("id")}`);
|
|
59
59
|
expect(option1).toHaveAccessibleDescription();
|
|
60
|
-
expect(option1).toHaveAttribute(
|
|
60
|
+
expect(option1).toHaveAttribute("aria-describedby", option1helper.getAttribute("id"));
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it("has all option's aria-describedby linked with the error message ID", () => {
|
|
65
|
-
const { radiowrapper } = createRadioWrapper(
|
|
65
|
+
const { radiowrapper } = createRadioWrapper(defaultParams => ({
|
|
66
66
|
...defaultParams,
|
|
67
67
|
error: true,
|
|
68
|
-
errorMessage:
|
|
68
|
+
errorMessage: "This is an error message"
|
|
69
69
|
}));
|
|
70
70
|
|
|
71
|
-
const errorMessage = radiowrapper?.querySelector(
|
|
71
|
+
const errorMessage = radiowrapper?.querySelector(".error-message .message");
|
|
72
72
|
const option1 = radiowrapper?.querySelector('input[value="option1"]');
|
|
73
73
|
|
|
74
74
|
expect(errorMessage).toBeTruthy();
|
|
75
75
|
if (errorMessage) {
|
|
76
|
-
expect(option1).toHaveAttribute(
|
|
76
|
+
expect(option1).toHaveAttribute("aria-describedby", errorMessage.id);
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
describe(
|
|
82
|
-
it(
|
|
83
|
-
const { radiowrapper } = createRadioWrapper(
|
|
81
|
+
describe("RadioWrapper selection", () => {
|
|
82
|
+
it("has option 2 selected, the rest is unselected", () => {
|
|
83
|
+
const { radiowrapper } = createRadioWrapper(defaultParams => ({
|
|
84
84
|
...defaultParams,
|
|
85
|
-
value:
|
|
85
|
+
value: "option2"
|
|
86
86
|
}));
|
|
87
87
|
|
|
88
88
|
expect(radiowrapper?.querySelector('input[value="option1"]')).toHaveAttribute(
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
"aria-checked",
|
|
90
|
+
"false"
|
|
91
91
|
);
|
|
92
92
|
expect(radiowrapper?.querySelector('input[value="option2"]')).toHaveAttribute(
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
"aria-checked",
|
|
94
|
+
"true"
|
|
95
95
|
);
|
|
96
96
|
expect(radiowrapper?.querySelector('input[value="option3"]')).toHaveAttribute(
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
"aria-checked",
|
|
98
|
+
"false"
|
|
99
99
|
);
|
|
100
100
|
});
|
|
101
101
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, ReactElement, useEffect } from
|
|
2
|
-
import classes from
|
|
3
|
-
import { Wrapper, WrapperProps } from
|
|
4
|
-
import { useWrapper } from
|
|
5
|
-
import { Icons } from
|
|
6
|
-
import { Fieldset, Props as FieldsetProps } from
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactElement, useEffect } from "react";
|
|
2
|
+
import classes from "./RadioWrapper.module.scss";
|
|
3
|
+
import { Wrapper, WrapperProps } from "../Wrapper/Wrapper";
|
|
4
|
+
import { useWrapper } from "../../../hooks/useWrapper";
|
|
5
|
+
import { Icons } from "../../../Icon/Icon";
|
|
6
|
+
import { Fieldset, Props as FieldsetProps } from "../../../Form/Fieldset/Fieldset";
|
|
7
7
|
|
|
8
|
-
export interface Props extends ComponentPropsWithRef<
|
|
8
|
+
export interface Props extends ComponentPropsWithRef<"div">, WrapperProps {
|
|
9
9
|
children: ReactElement | ReactElement[];
|
|
10
10
|
fieldsetProps: FieldsetProps;
|
|
11
11
|
value: string;
|
|
@@ -39,7 +39,7 @@ export const RadioWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
39
39
|
}, []);
|
|
40
40
|
|
|
41
41
|
const renderChildren = () =>
|
|
42
|
-
React.Children.map(children,
|
|
42
|
+
React.Children.map(children, child =>
|
|
43
43
|
React.cloneElement(child, {
|
|
44
44
|
parentErrorId: errorId,
|
|
45
45
|
error: error,
|
|
@@ -47,7 +47,7 @@ export const RadioWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
47
47
|
name: name,
|
|
48
48
|
parentHelperId: helperText ? helperId : false,
|
|
49
49
|
onChange: onChange,
|
|
50
|
-
disabled: child.props.disabled !== undefined ? child.props.disabled : disabled
|
|
50
|
+
disabled: child.props.disabled !== undefined ? child.props.disabled : disabled
|
|
51
51
|
})
|
|
52
52
|
);
|
|
53
53
|
|
|
@@ -62,9 +62,9 @@ export const RadioWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
62
62
|
helperText={helperText}
|
|
63
63
|
helperProps={{
|
|
64
64
|
...helperProps,
|
|
65
|
-
className: `${classes[
|
|
66
|
-
error ? classes[
|
|
67
|
-
} ${helperProps?.className ??
|
|
65
|
+
className: `${classes["radio-wrapper-helper"]} ${
|
|
66
|
+
error ? classes["radio-wrapper-error"] : ""
|
|
67
|
+
} ${helperProps?.className ?? ""}`
|
|
68
68
|
}}
|
|
69
69
|
error={error}
|
|
70
70
|
errorId={errorId}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { SelectWrapper, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import { Option } from
|
|
5
|
-
import userEvent from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { SelectWrapper, Props } from "./SelectWrapper";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { Option } from "../../Select/Option";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
6
|
|
|
7
7
|
const onChangeHandler = jest.fn();
|
|
8
8
|
const onClearHandler = jest.fn();
|
|
@@ -20,17 +20,17 @@ const defaultParams: Props = {
|
|
|
20
20
|
</Option>,
|
|
21
21
|
<Option key="4" value="option4">
|
|
22
22
|
Option 4
|
|
23
|
-
</Option
|
|
23
|
+
</Option>
|
|
24
24
|
],
|
|
25
|
-
label:
|
|
26
|
-
name:
|
|
27
|
-
helperText:
|
|
28
|
-
helperProps: {
|
|
29
|
-
errorMessage:
|
|
25
|
+
label: "select_label",
|
|
26
|
+
name: "select",
|
|
27
|
+
helperText: "helpertext",
|
|
28
|
+
helperProps: { "data-testid": "helpertext" },
|
|
29
|
+
errorMessage: "errormessage",
|
|
30
30
|
error: false,
|
|
31
|
-
value:
|
|
31
|
+
value: "option1",
|
|
32
32
|
onChange: onChangeHandler,
|
|
33
|
-
onClear: onClearHandler
|
|
33
|
+
onClear: onClearHandler
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
const createSelectWrapper = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -39,28 +39,28 @@ const createSelectWrapper = (params?: (defaultParams: Props) => Props) => {
|
|
|
39
39
|
parameters = params(defaultParams);
|
|
40
40
|
}
|
|
41
41
|
const queries = render(<SelectWrapper {...parameters} data-testid="selectwrapper" />);
|
|
42
|
-
const selectwrapper = queries.getByTestId(
|
|
43
|
-
const select = selectwrapper.querySelector(
|
|
42
|
+
const selectwrapper = queries.getByTestId("selectwrapper");
|
|
43
|
+
const select = selectwrapper.querySelector("button");
|
|
44
44
|
|
|
45
45
|
return {
|
|
46
46
|
...queries,
|
|
47
47
|
selectwrapper,
|
|
48
|
-
select
|
|
48
|
+
select
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
describe(
|
|
53
|
-
it(
|
|
52
|
+
describe("SelectWrapper should render", () => {
|
|
53
|
+
it("renders without crashing", () => {
|
|
54
54
|
const { selectwrapper } = createSelectWrapper();
|
|
55
55
|
|
|
56
56
|
expect(selectwrapper).toBeDefined();
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
describe(
|
|
61
|
-
it(
|
|
60
|
+
describe("ref should work", () => {
|
|
61
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
62
62
|
const ExampleComponent = ({
|
|
63
|
-
propagateRef
|
|
63
|
+
propagateRef
|
|
64
64
|
}: {
|
|
65
65
|
propagateRef?: (
|
|
66
66
|
ref: React.RefObject<HTMLElement>,
|
|
@@ -79,7 +79,7 @@ describe('ref should work', () => {
|
|
|
79
79
|
return (
|
|
80
80
|
<SelectWrapper
|
|
81
81
|
{...defaultParams}
|
|
82
|
-
selectProps={{ ref: innerRef,
|
|
82
|
+
selectProps={{ ref: innerRef, "data-ref": "inner-testing" }}
|
|
83
83
|
name="test"
|
|
84
84
|
data-ref="testing"
|
|
85
85
|
ref={ref}
|
|
@@ -91,94 +91,94 @@ describe('ref should work', () => {
|
|
|
91
91
|
ref: React.RefObject<HTMLElement>,
|
|
92
92
|
innerRef: React.RefObject<HTMLElement>
|
|
93
93
|
) => {
|
|
94
|
-
expect(ref.current).toHaveAttribute(
|
|
95
|
-
expect(innerRef.current!.nodeName).toBe(
|
|
94
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
95
|
+
expect(innerRef.current!.nodeName).toBe("SELECT");
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
describe(
|
|
103
|
-
it(
|
|
102
|
+
describe("SelectWrapper & Select have the right attributes", () => {
|
|
103
|
+
it("select has aria values", async () => {
|
|
104
104
|
const { select, getByTestId, findByText } = createSelectWrapper();
|
|
105
105
|
|
|
106
|
-
const helpertext = getByTestId(
|
|
107
|
-
const label = await findByText(
|
|
106
|
+
const helpertext = getByTestId("helpertext");
|
|
107
|
+
const label = await findByText("select_label");
|
|
108
108
|
|
|
109
|
-
expect(select).toHaveAttribute(
|
|
110
|
-
expect(select).toHaveAttribute(
|
|
109
|
+
expect(select).toHaveAttribute("aria-describedby", helpertext.id);
|
|
110
|
+
expect(select).toHaveAttribute("aria-labelledby", label.id);
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
it(
|
|
113
|
+
it("SelectWrapper has the right helpertext", () => {
|
|
114
114
|
const { getByTestId } = createSelectWrapper();
|
|
115
115
|
|
|
116
|
-
const helpertext = getByTestId(
|
|
116
|
+
const helpertext = getByTestId("helpertext");
|
|
117
117
|
|
|
118
118
|
expect(helpertext).toBeTruthy();
|
|
119
|
-
expect(helpertext).toHaveTextContent(
|
|
119
|
+
expect(helpertext).toHaveTextContent("helpertext");
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
it(
|
|
123
|
-
const { getByTestId } = createSelectWrapper(
|
|
122
|
+
it("Passes the proper helperProps class", () => {
|
|
123
|
+
const { getByTestId } = createSelectWrapper(defaultParams => ({
|
|
124
124
|
...defaultParams,
|
|
125
|
-
helperProps: { ...defaultParams.helperProps, className:
|
|
125
|
+
helperProps: { ...defaultParams.helperProps, className: "example-helper-classname" }
|
|
126
126
|
}));
|
|
127
127
|
|
|
128
|
-
const helpertext = getByTestId(
|
|
128
|
+
const helpertext = getByTestId("helpertext");
|
|
129
129
|
|
|
130
|
-
expect(helpertext.parentElement).toHaveClass(
|
|
130
|
+
expect(helpertext.parentElement).toHaveClass("example-helper-classname");
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
it(
|
|
134
|
-
const { getByTestId } = createSelectWrapper(
|
|
133
|
+
it("Passes the proper selectProps class", () => {
|
|
134
|
+
const { getByTestId } = createSelectWrapper(defaultParams => ({
|
|
135
135
|
...defaultParams,
|
|
136
136
|
selectProps: {
|
|
137
137
|
...defaultParams.selectProps,
|
|
138
|
-
|
|
139
|
-
className:
|
|
140
|
-
}
|
|
138
|
+
"data-testid": "select-element",
|
|
139
|
+
className: "example-select-classname"
|
|
140
|
+
}
|
|
141
141
|
}));
|
|
142
142
|
|
|
143
|
-
const select = getByTestId(
|
|
143
|
+
const select = getByTestId("select-element");
|
|
144
144
|
|
|
145
|
-
expect(select).toHaveClass(
|
|
145
|
+
expect(select).toHaveClass("example-select-classname");
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
it(
|
|
149
|
-
const { findByText, select } = createSelectWrapper(
|
|
148
|
+
it("SelectWrapper has the right errormessage", async () => {
|
|
149
|
+
const { findByText, select } = createSelectWrapper(defaultParams => ({
|
|
150
150
|
...defaultParams,
|
|
151
|
-
error: true
|
|
151
|
+
error: true
|
|
152
152
|
}));
|
|
153
153
|
|
|
154
|
-
const errorMessage = await findByText(
|
|
154
|
+
const errorMessage = await findByText("errormessage");
|
|
155
155
|
|
|
156
156
|
expect(errorMessage).toBeTruthy();
|
|
157
|
-
expect(select).toHaveAttribute(
|
|
157
|
+
expect(select).toHaveAttribute("aria-describedby", errorMessage.id);
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
-
it(
|
|
160
|
+
it("Fires the onChange event", async () => {
|
|
161
161
|
const { select, findByText } = createSelectWrapper();
|
|
162
162
|
|
|
163
163
|
userEvent.click(select as Element);
|
|
164
164
|
|
|
165
|
-
const option3 = await findByText(
|
|
165
|
+
const option3 = await findByText("Option 3");
|
|
166
166
|
|
|
167
167
|
userEvent.click(option3 as Element);
|
|
168
168
|
|
|
169
169
|
expect(onChangeHandler).toHaveBeenCalled();
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
it(
|
|
172
|
+
it("Fires the onClear event", async () => {
|
|
173
173
|
const { select, findByText } = createSelectWrapper();
|
|
174
174
|
|
|
175
175
|
userEvent.click(select as Element);
|
|
176
176
|
|
|
177
|
-
const option3 = await findByText(
|
|
177
|
+
const option3 = await findByText("Option 3");
|
|
178
178
|
|
|
179
179
|
userEvent.click(option3 as Element);
|
|
180
180
|
|
|
181
|
-
const clearButton = select!.querySelector(
|
|
181
|
+
const clearButton = select!.querySelector("[data-clear]")!;
|
|
182
182
|
|
|
183
183
|
userEvent.click(clearButton);
|
|
184
184
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React, { ComponentPropsWithRef, ReactChild, ReactElement } from
|
|
2
|
-
import classes from
|
|
3
|
-
import { Wrapper, WrapperProps } from
|
|
4
|
-
import { Select, Props as SelectProps } from
|
|
5
|
-
import { useWrapper } from
|
|
1
|
+
import React, { ComponentPropsWithRef, ReactChild, ReactElement } from "react";
|
|
2
|
+
import classes from "./SelectWrapper.module.scss";
|
|
3
|
+
import { Wrapper, WrapperProps } from "../Wrapper/Wrapper";
|
|
4
|
+
import { Select, Props as SelectProps } from "../../Select/Select";
|
|
5
|
+
import { useWrapper } from "../../../hooks/useWrapper";
|
|
6
6
|
|
|
7
7
|
interface PartialSelectProps extends Partial<SelectProps> {}
|
|
8
8
|
|
|
9
9
|
export interface Props
|
|
10
|
-
extends Omit<ComponentPropsWithRef<
|
|
11
|
-
Omit<WrapperProps,
|
|
10
|
+
extends Omit<ComponentPropsWithRef<"div">, "onChange">,
|
|
11
|
+
Omit<WrapperProps, "onChange" | "error"> {
|
|
12
12
|
children: ReactChild | ReactChild[];
|
|
13
13
|
placeholder?: string;
|
|
14
14
|
value: string;
|
|
@@ -42,10 +42,10 @@ export const SelectWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
42
42
|
floatingLabelActive={floatingLabelActive}
|
|
43
43
|
errorId={errorId}
|
|
44
44
|
helperId={helperId}
|
|
45
|
-
labelProps={{ id: labelId, className: classes[
|
|
45
|
+
labelProps={{ id: labelId, className: classes["select-label"] }}
|
|
46
46
|
helperProps={{
|
|
47
47
|
...helperProps,
|
|
48
|
-
className: `${classes[
|
|
48
|
+
className: `${classes["select-helper-text"]} ${helperProps?.className ?? ""}`
|
|
49
49
|
}}
|
|
50
50
|
error={error}
|
|
51
51
|
>
|
|
@@ -56,12 +56,12 @@ export const SelectWrapper = React.forwardRef<HTMLDivElement, Props>(
|
|
|
56
56
|
error={error}
|
|
57
57
|
describedBy={error ? errorId : helperId}
|
|
58
58
|
onChange={onChange}
|
|
59
|
-
onClear={
|
|
59
|
+
onClear={e => {
|
|
60
60
|
onClear && onClear(e);
|
|
61
61
|
}}
|
|
62
62
|
placeholder={placeholder}
|
|
63
|
-
className={`${floatingLabelActive ? classes[
|
|
64
|
-
selectProps?.className ??
|
|
63
|
+
className={`${floatingLabelActive ? classes["floating-label-active"] : ""} ${
|
|
64
|
+
selectProps?.className ?? ""
|
|
65
65
|
}`}
|
|
66
66
|
>
|
|
67
67
|
{children as ReactElement[]}
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
.
|
|
2
|
-
left: calc(
|
|
3
|
-
1.25rem + 1px
|
|
4
|
-
); // 1px is for offset of the textarea border. It's relative to the parent div which doesn't have a border.
|
|
1
|
+
@import "../../../mixins.module.scss";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
color: var(--color-primary);
|
|
8
|
-
}
|
|
9
|
-
&.error {
|
|
10
|
-
color: var(--error);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
3
|
+
@include inputLabelPrimaryColorOnFocus("label.textarea-label");
|
|
13
4
|
|
|
14
5
|
.textarea {
|
|
15
6
|
padding-top: 1.625rem;
|