@onewelcome/react-lib-components 0.2.1 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +2 -2
- 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 +5 -5
- 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/interfaces.d.ts +1 -1
- package/dist/react-lib-components.cjs.development.js +683 -581
- 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 +683 -581
- 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 +8 -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 +9 -9
- 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 +2 -2
- 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 +2 -2
- 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 +73 -72
- 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 +10 -10
- package/src/index.ts +67 -67
- package/src/interfaces.ts +1 -1
- 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
package/src/Tabs/Tabs.test.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { Tabs, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import { TabButton as Tab } from
|
|
5
|
-
import userEvent from
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Tabs, Props } from "./Tabs";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { TabButton as Tab } from "./TabButton";
|
|
5
|
+
import userEvent from "@testing-library/user-event";
|
|
6
6
|
|
|
7
7
|
const defaultParams: Props = {
|
|
8
|
-
|
|
8
|
+
"aria-label": "Entertainment",
|
|
9
9
|
children: [
|
|
10
10
|
<Tab title="Tab1">Tabpanel1 content</Tab>,
|
|
11
11
|
<Tab title="Tab2">Tabpanel2 content</Tab>,
|
|
12
|
-
<Tab title="Tab3">Tabpanel3 content</Tab
|
|
13
|
-
]
|
|
12
|
+
<Tab title="Tab3">Tabpanel3 content</Tab>
|
|
13
|
+
]
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const createTabs = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -19,39 +19,39 @@ const createTabs = (params?: (defaultParams: Props) => Props) => {
|
|
|
19
19
|
parameters = params(defaultParams);
|
|
20
20
|
}
|
|
21
21
|
const queries = render(<Tabs {...parameters} data-testid="tabs"></Tabs>);
|
|
22
|
-
const tabs = queries.getByTestId(
|
|
22
|
+
const tabs = queries.getByTestId("tabs");
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
...queries,
|
|
26
|
-
tabs
|
|
26
|
+
tabs
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
describe(
|
|
31
|
-
it(
|
|
30
|
+
describe("Tabs should render", () => {
|
|
31
|
+
it("renders without crashing", () => {
|
|
32
32
|
const { tabs } = createTabs();
|
|
33
33
|
|
|
34
34
|
expect(tabs).toBeDefined();
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it(
|
|
38
|
-
const { tabs } = createTabs(
|
|
37
|
+
it("renders with properties passed", () => {
|
|
38
|
+
const { tabs } = createTabs(defaultParams => ({
|
|
39
39
|
...defaultParams,
|
|
40
|
-
className:
|
|
40
|
+
className: "testclass"
|
|
41
41
|
}));
|
|
42
42
|
|
|
43
|
-
expect(tabs).toHaveClass(
|
|
43
|
+
expect(tabs).toHaveClass("testclass");
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
it(
|
|
47
|
-
const { tabs } = createTabs(
|
|
46
|
+
it("switches to tab and tabpanel when selected property is changed", () => {
|
|
47
|
+
const { tabs } = createTabs(defaultParams => ({
|
|
48
48
|
...defaultParams,
|
|
49
|
-
selected: 2
|
|
49
|
+
selected: 2
|
|
50
50
|
}));
|
|
51
51
|
|
|
52
52
|
const tablist = tabs.firstChild as HTMLDivElement;
|
|
53
53
|
const tabpanels = tabs.lastChild as HTMLDivElement;
|
|
54
|
-
const tabButtons = tablist.querySelectorAll(
|
|
54
|
+
const tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
55
55
|
|
|
56
56
|
const tab1 = tabButtons[0] as HTMLButtonElement;
|
|
57
57
|
const tab3 = tabButtons[2] as HTMLButtonElement;
|
|
@@ -59,21 +59,21 @@ describe('Tabs should render', () => {
|
|
|
59
59
|
const tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
60
60
|
const tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
61
61
|
|
|
62
|
-
expect(tab1).not.toHaveClass(
|
|
63
|
-
expect(tab3).toHaveClass(
|
|
62
|
+
expect(tab1).not.toHaveClass("selected");
|
|
63
|
+
expect(tab3).toHaveClass("selected");
|
|
64
64
|
|
|
65
|
-
expect(tabpanel1).not.toHaveClass(
|
|
66
|
-
expect(tabpanel3).toHaveClass(
|
|
65
|
+
expect(tabpanel1).not.toHaveClass("selected");
|
|
66
|
+
expect(tabpanel3).toHaveClass("selected");
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
it(
|
|
70
|
-
const { tabs } = createTabs(
|
|
71
|
-
...defaultParams
|
|
69
|
+
it("switches to tab and tabpanel when tab is clicked", () => {
|
|
70
|
+
const { tabs } = createTabs(defaultParams => ({
|
|
71
|
+
...defaultParams
|
|
72
72
|
}));
|
|
73
73
|
|
|
74
74
|
const tablist = tabs.firstChild as HTMLDivElement;
|
|
75
75
|
const tabpanels = tabs.lastChild as HTMLDivElement;
|
|
76
|
-
let tabButtons = tablist.querySelectorAll(
|
|
76
|
+
let tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
77
77
|
|
|
78
78
|
let tab1 = tabButtons[0] as HTMLButtonElement;
|
|
79
79
|
let tab3 = tabButtons[2] as HTMLButtonElement;
|
|
@@ -81,15 +81,15 @@ describe('Tabs should render', () => {
|
|
|
81
81
|
let tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
82
82
|
let tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
83
83
|
|
|
84
|
-
expect(tab1).toHaveClass(
|
|
85
|
-
expect(tab3).not.toHaveClass(
|
|
84
|
+
expect(tab1).toHaveClass("selected");
|
|
85
|
+
expect(tab3).not.toHaveClass("selected");
|
|
86
86
|
|
|
87
|
-
expect(tabpanel1).toHaveClass(
|
|
88
|
-
expect(tabpanel3).not.toHaveClass(
|
|
87
|
+
expect(tabpanel1).toHaveClass("selected");
|
|
88
|
+
expect(tabpanel3).not.toHaveClass("selected");
|
|
89
89
|
|
|
90
90
|
userEvent.click(tab3);
|
|
91
91
|
|
|
92
|
-
tabButtons = tablist.querySelectorAll(
|
|
92
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
93
93
|
|
|
94
94
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
95
95
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
@@ -97,23 +97,23 @@ describe('Tabs should render', () => {
|
|
|
97
97
|
tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
98
98
|
tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
99
99
|
|
|
100
|
-
expect(tab1).not.toHaveClass(
|
|
101
|
-
expect(tab3).toHaveClass(
|
|
100
|
+
expect(tab1).not.toHaveClass("selected");
|
|
101
|
+
expect(tab3).toHaveClass("selected");
|
|
102
102
|
|
|
103
|
-
expect(tabpanel1).not.toHaveClass(
|
|
104
|
-
expect(tabpanel3).toHaveClass(
|
|
103
|
+
expect(tabpanel1).not.toHaveClass("selected");
|
|
104
|
+
expect(tabpanel3).toHaveClass("selected");
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
-
it(
|
|
107
|
+
it("triggers the onTabChange when switching tabs", () => {
|
|
108
108
|
const onTabChangeHandler = jest.fn();
|
|
109
109
|
|
|
110
|
-
const { tabs } = createTabs(
|
|
110
|
+
const { tabs } = createTabs(defaultParams => ({
|
|
111
111
|
...defaultParams,
|
|
112
|
-
onTabChange: onTabChangeHandler
|
|
112
|
+
onTabChange: onTabChangeHandler
|
|
113
113
|
}));
|
|
114
114
|
|
|
115
115
|
const tablist = tabs.firstChild as HTMLDivElement;
|
|
116
|
-
const tabButtons = tablist.querySelectorAll(
|
|
116
|
+
const tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
117
117
|
|
|
118
118
|
let tab3 = tabButtons[2] as HTMLButtonElement;
|
|
119
119
|
|
|
@@ -123,8 +123,8 @@ describe('Tabs should render', () => {
|
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
describe(
|
|
127
|
-
it(
|
|
126
|
+
describe("Tabs should not render other children then tab components", () => {
|
|
127
|
+
it("renders no tabs", () => {
|
|
128
128
|
const queries = render(
|
|
129
129
|
<Tabs data-testid="tabs">
|
|
130
130
|
<div>wrong component 1</div>
|
|
@@ -132,20 +132,20 @@ describe('Tabs should not render other children then tab components', () => {
|
|
|
132
132
|
</Tabs>
|
|
133
133
|
);
|
|
134
134
|
|
|
135
|
-
const tabs = queries.getByTestId(
|
|
135
|
+
const tabs = queries.getByTestId("tabs");
|
|
136
136
|
|
|
137
137
|
expect(tabs).toBeDefined();
|
|
138
138
|
expect(tabs).toBeEmptyDOMElement;
|
|
139
139
|
});
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
describe(
|
|
143
|
-
it(
|
|
142
|
+
describe("Tabs should comply with accessibility rules", () => {
|
|
143
|
+
it("traverse through tabs with keyboard", async () => {
|
|
144
144
|
const { tabs } = createTabs();
|
|
145
145
|
|
|
146
146
|
const tablist = tabs.firstChild as HTMLDivElement;
|
|
147
147
|
const tabpanels = tabs.lastChild as HTMLDivElement;
|
|
148
|
-
let tabButtons = tablist.querySelectorAll(
|
|
148
|
+
let tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
149
149
|
|
|
150
150
|
let tab1 = tabButtons[0] as HTMLButtonElement;
|
|
151
151
|
let tab3 = tabButtons[2] as HTMLButtonElement;
|
|
@@ -155,107 +155,107 @@ describe('Tabs should comply with accessibility rules', () => {
|
|
|
155
155
|
|
|
156
156
|
tab1.focus();
|
|
157
157
|
|
|
158
|
-
tabButtons = tablist.querySelectorAll(
|
|
158
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
159
159
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
160
160
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
161
161
|
tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
162
162
|
tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
163
163
|
|
|
164
164
|
expect(tab1).toHaveFocus();
|
|
165
|
-
expect(tab1).toHaveClass(
|
|
166
|
-
expect(tab1).not.toHaveClass(
|
|
167
|
-
expect(tab3).not.toHaveClass(
|
|
168
|
-
expect(tab3).not.toHaveClass(
|
|
169
|
-
expect(tabpanel1).toHaveClass(
|
|
170
|
-
expect(tabpanel3).not.toHaveClass(
|
|
165
|
+
expect(tab1).toHaveClass("selected");
|
|
166
|
+
expect(tab1).not.toHaveClass("focussed");
|
|
167
|
+
expect(tab3).not.toHaveClass("selected");
|
|
168
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
169
|
+
expect(tabpanel1).toHaveClass("selected");
|
|
170
|
+
expect(tabpanel3).not.toHaveClass("selected");
|
|
171
171
|
|
|
172
|
-
userEvent.keyboard(
|
|
173
|
-
userEvent.keyboard(
|
|
172
|
+
userEvent.keyboard("[ArrowLeft]");
|
|
173
|
+
userEvent.keyboard("[Space]");
|
|
174
174
|
|
|
175
|
-
tabButtons = tablist.querySelectorAll(
|
|
175
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
176
176
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
177
177
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
178
178
|
tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
179
179
|
tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
180
180
|
|
|
181
181
|
expect(tab3).toHaveFocus();
|
|
182
|
-
expect(tab3).toHaveClass(
|
|
183
|
-
expect(tab1).not.toHaveClass(
|
|
184
|
-
expect(tab1).not.toHaveClass(
|
|
185
|
-
expect(tabpanel3).toHaveClass(
|
|
186
|
-
expect(tabpanel1).not.toHaveClass(
|
|
182
|
+
expect(tab3).toHaveClass("selected");
|
|
183
|
+
expect(tab1).not.toHaveClass("selected");
|
|
184
|
+
expect(tab1).not.toHaveClass("focussed");
|
|
185
|
+
expect(tabpanel3).toHaveClass("selected");
|
|
186
|
+
expect(tabpanel1).not.toHaveClass("selected");
|
|
187
187
|
|
|
188
|
-
userEvent.keyboard(
|
|
189
|
-
userEvent.keyboard(
|
|
188
|
+
userEvent.keyboard("[ArrowRight]");
|
|
189
|
+
userEvent.keyboard("[Enter]");
|
|
190
190
|
|
|
191
|
-
tabButtons = tablist.querySelectorAll(
|
|
191
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
192
192
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
193
193
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
194
194
|
tabpanel1 = tabpanels.firstChild as HTMLDivElement;
|
|
195
195
|
tabpanel3 = tabpanels.lastChild as HTMLDivElement;
|
|
196
196
|
|
|
197
197
|
expect(tab1).toHaveFocus();
|
|
198
|
-
expect(tab1).toHaveClass(
|
|
199
|
-
expect(tab3).not.toHaveClass(
|
|
200
|
-
expect(tab3).not.toHaveClass(
|
|
201
|
-
expect(tabpanel1).toHaveClass(
|
|
202
|
-
expect(tabpanel3).not.toHaveClass(
|
|
198
|
+
expect(tab1).toHaveClass("selected");
|
|
199
|
+
expect(tab3).not.toHaveClass("selected");
|
|
200
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
201
|
+
expect(tabpanel1).toHaveClass("selected");
|
|
202
|
+
expect(tabpanel3).not.toHaveClass("selected");
|
|
203
203
|
|
|
204
|
-
userEvent.keyboard(
|
|
204
|
+
userEvent.keyboard("[End]");
|
|
205
205
|
|
|
206
|
-
tabButtons = tablist.querySelectorAll(
|
|
206
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
207
207
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
208
208
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
209
209
|
|
|
210
210
|
expect(tab3).toHaveFocus();
|
|
211
|
-
expect(tab3).toHaveClass(
|
|
212
|
-
expect(tab1).not.toHaveClass(
|
|
211
|
+
expect(tab3).toHaveClass("focussed");
|
|
212
|
+
expect(tab1).not.toHaveClass("focussed");
|
|
213
213
|
|
|
214
|
-
userEvent.keyboard(
|
|
214
|
+
userEvent.keyboard("[Home]");
|
|
215
215
|
|
|
216
|
-
tabButtons = tablist.querySelectorAll(
|
|
216
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
217
217
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
218
218
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
219
219
|
|
|
220
220
|
expect(tab1).toHaveFocus();
|
|
221
|
-
expect(tab1).toHaveClass(
|
|
222
|
-
expect(tab3).not.toHaveClass(
|
|
221
|
+
expect(tab1).toHaveClass("selected");
|
|
222
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
223
223
|
|
|
224
224
|
// should have no effect
|
|
225
|
-
userEvent.keyboard(
|
|
225
|
+
userEvent.keyboard("a");
|
|
226
226
|
|
|
227
|
-
tabButtons = tablist.querySelectorAll(
|
|
227
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
228
228
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
229
229
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
230
230
|
|
|
231
231
|
expect(tab1).toHaveFocus();
|
|
232
|
-
expect(tab1).toHaveClass(
|
|
233
|
-
expect(tab3).not.toHaveClass(
|
|
232
|
+
expect(tab1).toHaveClass("selected");
|
|
233
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
234
234
|
|
|
235
|
-
userEvent.keyboard(
|
|
235
|
+
userEvent.keyboard("[ArrowRight]");
|
|
236
236
|
|
|
237
|
-
tabButtons = tablist.querySelectorAll(
|
|
237
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
238
238
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
239
239
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
240
240
|
|
|
241
241
|
expect(tab1).not.toHaveFocus();
|
|
242
242
|
expect(tab3).not.toHaveFocus();
|
|
243
|
-
expect(tab1).not.toHaveClass(
|
|
244
|
-
expect(tab3).not.toHaveClass(
|
|
243
|
+
expect(tab1).not.toHaveClass("focussed");
|
|
244
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
245
245
|
|
|
246
|
-
userEvent.keyboard(
|
|
246
|
+
userEvent.keyboard("[ArrowLeft]");
|
|
247
247
|
|
|
248
|
-
tabButtons = tablist.querySelectorAll(
|
|
248
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
249
249
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
250
250
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
251
251
|
|
|
252
252
|
expect(tab1).toHaveFocus();
|
|
253
|
-
expect(tab1).toHaveClass(
|
|
254
|
-
expect(tab3).not.toHaveClass(
|
|
253
|
+
expect(tab1).toHaveClass("selected");
|
|
254
|
+
expect(tab3).not.toHaveClass("focussed");
|
|
255
255
|
|
|
256
|
-
userEvent.keyboard(
|
|
256
|
+
userEvent.keyboard("[ArrowLeft]");
|
|
257
257
|
|
|
258
|
-
tabButtons = tablist.querySelectorAll(
|
|
258
|
+
tabButtons = tablist.querySelectorAll(".tabbutton");
|
|
259
259
|
tab1 = tabButtons[0] as HTMLButtonElement;
|
|
260
260
|
tab3 = tabButtons[2] as HTMLButtonElement;
|
|
261
261
|
|
|
@@ -263,6 +263,6 @@ describe('Tabs should comply with accessibility rules', () => {
|
|
|
263
263
|
|
|
264
264
|
expect(tab1).not.toHaveFocus();
|
|
265
265
|
expect(tab3).not.toHaveFocus();
|
|
266
|
-
expect(tab1).toHaveClass(
|
|
266
|
+
expect(tab1).toHaveClass("selected");
|
|
267
267
|
});
|
|
268
268
|
});
|
package/src/Tabs/Tabs.tsx
CHANGED
|
@@ -4,25 +4,25 @@ import React, {
|
|
|
4
4
|
MutableRefObject,
|
|
5
5
|
useEffect,
|
|
6
6
|
useRef,
|
|
7
|
-
useState
|
|
8
|
-
} from
|
|
9
|
-
import { generateID } from
|
|
10
|
-
import { Props as TabProps } from
|
|
11
|
-
import { TabButton } from
|
|
12
|
-
import { TabPanel } from
|
|
13
|
-
import classes from
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { generateID } from "../util/helper";
|
|
10
|
+
import { Props as TabProps } from "./Tab";
|
|
11
|
+
import { TabButton } from "./TabButton";
|
|
12
|
+
import { TabPanel } from "./TabPanel";
|
|
13
|
+
import classes from "./Tabs.module.scss";
|
|
14
14
|
|
|
15
|
-
export interface Props extends ComponentPropsWithRef<
|
|
15
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
16
16
|
children: React.ReactElement<TabProps> | React.ReactElement<TabProps>[];
|
|
17
17
|
selected?: number;
|
|
18
|
-
|
|
18
|
+
"aria-label"?: string;
|
|
19
19
|
onTabChange?: (index: number) => void;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export const Tabs = ({
|
|
23
23
|
children,
|
|
24
24
|
selected = 0,
|
|
25
|
-
|
|
25
|
+
"aria-label": ariaLabel,
|
|
26
26
|
onTabChange,
|
|
27
27
|
className,
|
|
28
28
|
...rest
|
|
@@ -58,7 +58,7 @@ export const Tabs = ({
|
|
|
58
58
|
top:
|
|
59
59
|
selectedTabButton.offsetTop +
|
|
60
60
|
selectedTabButton.offsetHeight -
|
|
61
|
-
indicatorRef.current!.offsetHeight
|
|
61
|
+
indicatorRef.current!.offsetHeight
|
|
62
62
|
});
|
|
63
63
|
setIndicatorWidth(selectedTabButton.offsetWidth);
|
|
64
64
|
};
|
|
@@ -68,20 +68,20 @@ export const Tabs = ({
|
|
|
68
68
|
let currentFocussedTab = focussedTab === -1 ? selectedTab : focussedTab;
|
|
69
69
|
|
|
70
70
|
switch (e.code) {
|
|
71
|
-
case
|
|
71
|
+
case "ArrowLeft":
|
|
72
72
|
setFocussedTab(currentFocussedTab === min ? max : currentFocussedTab - 1);
|
|
73
73
|
break;
|
|
74
|
-
case
|
|
74
|
+
case "ArrowRight":
|
|
75
75
|
setFocussedTab(currentFocussedTab === max ? min : currentFocussedTab + 1);
|
|
76
76
|
break;
|
|
77
|
-
case
|
|
77
|
+
case "Home":
|
|
78
78
|
setFocussedTab(min);
|
|
79
79
|
break;
|
|
80
|
-
case
|
|
80
|
+
case "End":
|
|
81
81
|
setFocussedTab(max);
|
|
82
82
|
break;
|
|
83
|
-
case
|
|
84
|
-
case
|
|
83
|
+
case "Space":
|
|
84
|
+
case "Enter":
|
|
85
85
|
activateTab(currentFocussedTab);
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
@@ -106,7 +106,7 @@ export const Tabs = ({
|
|
|
106
106
|
selected: selectedTab === index,
|
|
107
107
|
focussed: focussedTab === index,
|
|
108
108
|
onTabButtonClick: () => activateTab(index),
|
|
109
|
-
children: child.props.title
|
|
109
|
+
children: child.props.title
|
|
110
110
|
})
|
|
111
111
|
);
|
|
112
112
|
|
|
@@ -117,33 +117,33 @@ export const Tabs = ({
|
|
|
117
117
|
selected: selectedTab === index,
|
|
118
118
|
tabId: tabIds[index],
|
|
119
119
|
tabPanelId: tabPanelIds[index],
|
|
120
|
-
children: child.props.children
|
|
120
|
+
children: child.props.children
|
|
121
121
|
})
|
|
122
122
|
);
|
|
123
123
|
|
|
124
124
|
return (
|
|
125
|
-
<div {...rest} className={`${classes[
|
|
125
|
+
<div {...rest} className={`${classes["tabs"]} ${className ?? ""}`}>
|
|
126
126
|
<div
|
|
127
127
|
role="tablist"
|
|
128
128
|
onKeyDown={handleKeyDown}
|
|
129
129
|
onBlur={handleBlur}
|
|
130
130
|
aria-label={ariaLabel}
|
|
131
|
-
className={classes[
|
|
131
|
+
className={classes["tablist"]}
|
|
132
132
|
>
|
|
133
|
-
<div className={classes[
|
|
133
|
+
<div className={classes["tabdivider"]} />
|
|
134
134
|
{tabButtons}
|
|
135
135
|
<div
|
|
136
|
-
className={classes[
|
|
136
|
+
className={classes["indicator"]}
|
|
137
137
|
ref={indicatorRef}
|
|
138
138
|
aria-hidden="true"
|
|
139
139
|
tabIndex={-1}
|
|
140
140
|
style={{
|
|
141
141
|
width: indicatorWidth,
|
|
142
|
-
...indicatorPosition
|
|
142
|
+
...indicatorPosition
|
|
143
143
|
}}
|
|
144
144
|
/>
|
|
145
145
|
</div>
|
|
146
|
-
<div className={classes[
|
|
146
|
+
<div className={classes["tabpanels"]}>{tabPanels}</div>
|
|
147
147
|
</div>
|
|
148
148
|
);
|
|
149
149
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { render } from
|
|
3
|
-
import user from
|
|
4
|
-
import { Props, TextEllipsis } from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import user from "@testing-library/user-event";
|
|
4
|
+
import { Props, TextEllipsis } from "./TextEllipsis";
|
|
5
5
|
|
|
6
6
|
const defaultParams: Props = {};
|
|
7
7
|
|
|
@@ -15,48 +15,48 @@ const createTextEllipsis = (params?: (defaultParams: Props) => Props) => {
|
|
|
15
15
|
content
|
|
16
16
|
</TextEllipsis>
|
|
17
17
|
);
|
|
18
|
-
const textEllipsis = queries.getByTestId(
|
|
18
|
+
const textEllipsis = queries.getByTestId("TextEllipsis");
|
|
19
19
|
|
|
20
20
|
return {
|
|
21
21
|
...queries,
|
|
22
|
-
textEllipsis
|
|
22
|
+
textEllipsis
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
describe(
|
|
27
|
-
it(
|
|
26
|
+
describe("TextEllipsis should render", () => {
|
|
27
|
+
it("renders without crashing", () => {
|
|
28
28
|
const { textEllipsis, getAllByText } = createTextEllipsis();
|
|
29
29
|
|
|
30
30
|
expect(textEllipsis).toBeDefined();
|
|
31
|
-
expect(getAllByText(
|
|
31
|
+
expect(getAllByText("content")).toHaveLength(2);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it(
|
|
34
|
+
it("does not show popover when full text is visible", () => {
|
|
35
35
|
const { textEllipsis, getByRole } = createTextEllipsis();
|
|
36
36
|
|
|
37
|
-
expect(getByRole(
|
|
37
|
+
expect(getByRole("tooltip", { hidden: true })).toHaveAttribute("data-hidden", "true");
|
|
38
38
|
user.hover(textEllipsis);
|
|
39
|
-
expect(getByRole(
|
|
39
|
+
expect(getByRole("tooltip", { hidden: true })).toHaveAttribute("data-hidden", "true");
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
it(
|
|
42
|
+
it("shows popover with full text when base text has ellipsis", () => {
|
|
43
43
|
const { textEllipsis, getByRole } = createTextEllipsis();
|
|
44
44
|
|
|
45
|
-
Object.defineProperty(textEllipsis,
|
|
46
|
-
Object.defineProperty(textEllipsis,
|
|
45
|
+
Object.defineProperty(textEllipsis, "offsetWidth", { configurable: true, value: 1 });
|
|
46
|
+
Object.defineProperty(textEllipsis, "scrollWidth", { configurable: true, value: 2 });
|
|
47
47
|
|
|
48
|
-
expect(getByRole(
|
|
48
|
+
expect(getByRole("tooltip", { hidden: true })).toHaveAttribute("data-hidden", "true");
|
|
49
49
|
user.hover(textEllipsis);
|
|
50
|
-
expect(getByRole(
|
|
50
|
+
expect(getByRole("tooltip", { hidden: true })).toHaveAttribute("data-hidden", "false");
|
|
51
51
|
user.unhover(textEllipsis);
|
|
52
|
-
expect(getByRole(
|
|
52
|
+
expect(getByRole("tooltip", { hidden: true })).toHaveAttribute("data-hidden", "true");
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
describe(
|
|
57
|
-
it(
|
|
56
|
+
describe("ref should work", () => {
|
|
57
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
58
58
|
const ExampleComponent = ({
|
|
59
|
-
propagateRef
|
|
59
|
+
propagateRef
|
|
60
60
|
}: {
|
|
61
61
|
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
62
62
|
}) => {
|
|
@@ -72,7 +72,7 @@ describe('ref should work', () => {
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
75
|
-
expect(ref.current).toHaveAttribute(
|
|
75
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useRef, MouseEventHandler, useState, ComponentPropsWithRef } from
|
|
2
|
-
import { Popover } from
|
|
3
|
-
import classes from
|
|
1
|
+
import React, { useRef, MouseEventHandler, useState, ComponentPropsWithRef } from "react";
|
|
2
|
+
import { Popover } from "../Popover/Popover";
|
|
3
|
+
import classes from "./TextEllipsis.module.scss";
|
|
4
4
|
|
|
5
|
-
export interface Props extends ComponentPropsWithRef<
|
|
5
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
6
6
|
children?: string;
|
|
7
7
|
popoverClassName?: string;
|
|
8
8
|
}
|
|
@@ -35,7 +35,7 @@ export const TextEllipsis = React.forwardRef<HTMLDivElement, Props>(
|
|
|
35
35
|
{...rest}
|
|
36
36
|
onMouseEnter={onMouseEnter}
|
|
37
37
|
onMouseLeave={onMouseLeave}
|
|
38
|
-
className={`${classes[
|
|
38
|
+
className={`${classes["text-ellipsis"]} ${className ?? ""}`}
|
|
39
39
|
ref={ref || textContainer}
|
|
40
40
|
>
|
|
41
41
|
{children}
|
|
@@ -45,7 +45,7 @@ export const TextEllipsis = React.forwardRef<HTMLDivElement, Props>(
|
|
|
45
45
|
show={showPopover}
|
|
46
46
|
role="tooltip"
|
|
47
47
|
anchorEl={textContainer}
|
|
48
|
-
className={`${classes.popover} ${popoverClassName ??
|
|
48
|
+
className={`${classes.popover} ${popoverClassName ?? ""}`}
|
|
49
49
|
>
|
|
50
50
|
{children}
|
|
51
51
|
</Popover>
|