@onewelcome/react-lib-components 0.2.1 → 0.2.2
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 +672 -576
- 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 +672 -576
- 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 +81 -76
- package/src/ContextMenu/ContextMenu.tsx +43 -41
- package/src/ContextMenu/ContextMenuItem.module.scss +1 -1
- package/src/ContextMenu/ContextMenuItem.tsx +5 -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 +86 -59
- 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 +10 -10
- 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,9 +1,9 @@
|
|
|
1
|
-
import React, { useRef, useEffect } from
|
|
2
|
-
import { IconButton, Props } from
|
|
3
|
-
import { render } from
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
|
+
import { IconButton, Props } from "./IconButton";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
4
|
|
|
5
5
|
const defaultParams: Props = {
|
|
6
|
-
title:
|
|
6
|
+
title: "iconbutton"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
const createIconButton = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -16,26 +16,26 @@ const createIconButton = (params?: (defaultParams: Props) => Props) => {
|
|
|
16
16
|
iconButton content
|
|
17
17
|
</IconButton>
|
|
18
18
|
);
|
|
19
|
-
const iconButton = queries.getByTestId(
|
|
19
|
+
const iconButton = queries.getByTestId("iconButton");
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
22
|
...queries,
|
|
23
|
-
iconButton
|
|
23
|
+
iconButton
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
describe(
|
|
28
|
-
it(
|
|
27
|
+
describe("IconButton should render", () => {
|
|
28
|
+
it("renders without crashing", () => {
|
|
29
29
|
const { iconButton } = createIconButton();
|
|
30
30
|
|
|
31
31
|
expect(iconButton).toBeDefined();
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
describe(
|
|
36
|
-
it(
|
|
35
|
+
describe("ref should work", () => {
|
|
36
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
37
37
|
const ExampleComponent = ({
|
|
38
|
-
propagateRef
|
|
38
|
+
propagateRef
|
|
39
39
|
}: {
|
|
40
40
|
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
41
41
|
}) => {
|
|
@@ -51,56 +51,56 @@ describe('ref should work', () => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
54
|
-
expect(ref.current).toHaveAttribute(
|
|
54
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
58
58
|
});
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
describe(
|
|
61
|
+
describe("Different variants of the button", () => {
|
|
62
62
|
it('should have a class of "primary"', () => {
|
|
63
63
|
const { iconButton } = createIconButton();
|
|
64
|
-
expect(iconButton.classList.contains(
|
|
64
|
+
expect(iconButton.classList.contains("primary")).toBe(true);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('should have a class of "secondary"', () => {
|
|
68
|
-
const { iconButton } = createIconButton(
|
|
68
|
+
const { iconButton } = createIconButton(defaultParams => ({
|
|
69
69
|
...defaultParams,
|
|
70
|
-
color:
|
|
70
|
+
color: "secondary"
|
|
71
71
|
}));
|
|
72
|
-
expect(iconButton.classList.contains(
|
|
72
|
+
expect(iconButton.classList.contains("secondary")).toBe(true);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
it('should have a class of "tertiary"', () => {
|
|
76
|
-
const { iconButton } = createIconButton(
|
|
76
|
+
const { iconButton } = createIconButton(defaultParams => ({
|
|
77
77
|
...defaultParams,
|
|
78
|
-
color:
|
|
78
|
+
color: "tertiary"
|
|
79
79
|
}));
|
|
80
|
-
expect(iconButton.classList.contains(
|
|
80
|
+
expect(iconButton.classList.contains("tertiary")).toBe(true);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
it('should have a class of "fill"', () => {
|
|
84
|
-
const { iconButton } = createIconButton(
|
|
84
|
+
const { iconButton } = createIconButton(defaultParams => ({
|
|
85
85
|
...defaultParams,
|
|
86
|
-
variant:
|
|
86
|
+
variant: "fill"
|
|
87
87
|
}));
|
|
88
|
-
expect(iconButton.classList.contains(
|
|
88
|
+
expect(iconButton.classList.contains("fill")).toBe(true);
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
it('should have a class of "outline"', () => {
|
|
92
|
-
const { iconButton } = createIconButton(
|
|
92
|
+
const { iconButton } = createIconButton(defaultParams => ({
|
|
93
93
|
...defaultParams,
|
|
94
|
-
variant:
|
|
94
|
+
variant: "outline"
|
|
95
95
|
}));
|
|
96
|
-
expect(iconButton.classList.contains(
|
|
96
|
+
expect(iconButton.classList.contains("outline")).toBe(true);
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it('should have a class of "text"', () => {
|
|
100
|
-
const { iconButton } = createIconButton(
|
|
100
|
+
const { iconButton } = createIconButton(defaultParams => ({
|
|
101
101
|
...defaultParams,
|
|
102
|
-
variant:
|
|
102
|
+
variant: "text"
|
|
103
103
|
}));
|
|
104
|
-
expect(iconButton.classList.contains(
|
|
104
|
+
expect(iconButton.classList.contains("text")).toBe(true);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import React, { Fragment } from
|
|
2
|
-
import { BaseButton, Props as BaseButtonProps } from
|
|
3
|
-
import classes from
|
|
4
|
-
import readyclasses from
|
|
1
|
+
import React, { Fragment } from "react";
|
|
2
|
+
import { BaseButton, Props as BaseButtonProps } from "./BaseButton";
|
|
3
|
+
import classes from "./IconButton.module.scss";
|
|
4
|
+
import readyclasses from "../readyclasses.module.scss";
|
|
5
5
|
|
|
6
6
|
export interface Props extends BaseButtonProps {
|
|
7
7
|
children?: React.ReactNode;
|
|
8
|
-
iconSize?:
|
|
9
|
-
variant?:
|
|
8
|
+
iconSize?: "s" | "m" | "l";
|
|
9
|
+
variant?: "text" | "fill" | "outline";
|
|
10
10
|
className?: string;
|
|
11
11
|
title?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const IconButton = React.forwardRef<HTMLButtonElement, Props>(
|
|
15
15
|
(
|
|
16
|
-
{ children, color =
|
|
16
|
+
{ children, color = "primary", variant = "text", iconSize = "m", title, className, ...rest },
|
|
17
17
|
ref
|
|
18
18
|
) => {
|
|
19
19
|
if (!title) {
|
|
@@ -21,10 +21,10 @@ export const IconButton = React.forwardRef<HTMLButtonElement, Props>(
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const iconButtonClasses = [
|
|
24
|
-
classes[
|
|
24
|
+
classes["icon-button"],
|
|
25
25
|
classes[variant],
|
|
26
26
|
classes[color],
|
|
27
|
-
classes[
|
|
27
|
+
classes["button-" + iconSize]
|
|
28
28
|
];
|
|
29
29
|
|
|
30
30
|
if (className) {
|
|
@@ -32,10 +32,10 @@ export const IconButton = React.forwardRef<HTMLButtonElement, Props>(
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
|
-
<BaseButton {...rest} ref={ref} className={iconButtonClasses.join(
|
|
35
|
+
<BaseButton {...rest} ref={ref} className={iconButtonClasses.join(" ")}>
|
|
36
36
|
<Fragment>
|
|
37
37
|
{children}
|
|
38
|
-
<span className={readyclasses[
|
|
38
|
+
<span className={readyclasses["sr-only"]}>{title}</span>
|
|
39
39
|
</Fragment>
|
|
40
40
|
</BaseButton>
|
|
41
41
|
);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from
|
|
2
|
-
import { ContextMenu, Props } from
|
|
3
|
-
import { render } from
|
|
4
|
-
import { Button } from
|
|
5
|
-
import { ContextMenuItem } from
|
|
6
|
-
import userEvent from
|
|
1
|
+
import React, { useEffect, useRef } from "react";
|
|
2
|
+
import { ContextMenu, Props } from "./ContextMenu";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { Button } from "../Button/Button";
|
|
5
|
+
import { ContextMenuItem } from "./ContextMenuItem";
|
|
6
|
+
import userEvent from "@testing-library/user-event";
|
|
7
7
|
|
|
8
8
|
const onShow = jest.fn();
|
|
9
9
|
const onClick = jest.fn();
|
|
10
10
|
|
|
11
11
|
const defaultParams: Props = {
|
|
12
|
-
id:
|
|
12
|
+
id: "example-contextmenu",
|
|
13
13
|
trigger: <Button data-testid="trigger">Click me for a context menu</Button>,
|
|
14
14
|
children: [
|
|
15
15
|
<ContextMenuItem onClick={onClick} data-testid="contextmenuitem" key="1">
|
|
@@ -20,10 +20,10 @@ const defaultParams: Props = {
|
|
|
20
20
|
</ContextMenuItem>,
|
|
21
21
|
<ContextMenuItem onClick={onClick} data-testid="contextmenuitem3" key="3">
|
|
22
22
|
Example item 3
|
|
23
|
-
</ContextMenuItem
|
|
23
|
+
</ContextMenuItem>
|
|
24
24
|
],
|
|
25
25
|
show: false,
|
|
26
|
-
onShow: onShow
|
|
26
|
+
onShow: onShow
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const createContextMenu = (params?: (defaultParams: Props) => Props) => {
|
|
@@ -34,24 +34,24 @@ const createContextMenu = (params?: (defaultParams: Props) => Props) => {
|
|
|
34
34
|
|
|
35
35
|
const queries = render(<ContextMenu {...parameters} data-testid="contextmenu"></ContextMenu>);
|
|
36
36
|
|
|
37
|
-
const contextmenu = queries.getByTestId(
|
|
38
|
-
const trigger = queries.getByTestId(
|
|
37
|
+
const contextmenu = queries.getByTestId("contextmenu");
|
|
38
|
+
const trigger = queries.getByTestId("trigger");
|
|
39
39
|
|
|
40
40
|
return {
|
|
41
41
|
...queries,
|
|
42
42
|
contextmenu,
|
|
43
|
-
trigger
|
|
43
|
+
trigger
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
describe(
|
|
48
|
-
it(
|
|
47
|
+
describe("ContextMenu should render", () => {
|
|
48
|
+
it("renders without crashing", () => {
|
|
49
49
|
const { contextmenu } = createContextMenu();
|
|
50
50
|
|
|
51
51
|
expect(contextmenu).toBeTruthy();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
it(
|
|
54
|
+
it("executed onShow function", () => {
|
|
55
55
|
const { trigger } = createContextMenu();
|
|
56
56
|
|
|
57
57
|
userEvent.click(trigger);
|
|
@@ -59,20 +59,20 @@ describe('ContextMenu should render', () => {
|
|
|
59
59
|
expect(onShow).toHaveBeenCalled();
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
it(
|
|
63
|
-
const { getByTestId } = createContextMenu(
|
|
62
|
+
it("executed onShow function", () => {
|
|
63
|
+
const { getByTestId } = createContextMenu(defaultParams => ({
|
|
64
64
|
...defaultParams,
|
|
65
|
-
show: true
|
|
65
|
+
show: true
|
|
66
66
|
}));
|
|
67
67
|
|
|
68
|
-
const button = getByTestId(
|
|
68
|
+
const button = getByTestId("contextmenuitem");
|
|
69
69
|
|
|
70
70
|
userEvent.click(button);
|
|
71
71
|
|
|
72
72
|
expect(onClick).toHaveBeenCalled();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it(
|
|
75
|
+
it("should throw an error", () => {
|
|
76
76
|
// Prevent throwing an error in the console when this test is executed. We fix this and the end of this test.
|
|
77
77
|
const err = console.error;
|
|
78
78
|
console.error = jest.fn();
|
|
@@ -86,7 +86,7 @@ describe('ContextMenu should render', () => {
|
|
|
86
86
|
actual = e.message;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const expected =
|
|
89
|
+
const expected = "You need to provide an ID to the context menu";
|
|
90
90
|
|
|
91
91
|
expect(actual).toEqual(expected);
|
|
92
92
|
|
|
@@ -94,10 +94,10 @@ describe('ContextMenu should render', () => {
|
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
-
describe(
|
|
98
|
-
it(
|
|
97
|
+
describe("ref should work", () => {
|
|
98
|
+
it("should give back the proper data prop, this also checks if the component propagates ...rest properly", () => {
|
|
99
99
|
const ExampleComponent = ({
|
|
100
|
-
propagateRef
|
|
100
|
+
propagateRef
|
|
101
101
|
}: {
|
|
102
102
|
propagateRef?: (ref: React.RefObject<HTMLElement>) => void;
|
|
103
103
|
}) => {
|
|
@@ -113,121 +113,126 @@ describe('ref should work', () => {
|
|
|
113
113
|
};
|
|
114
114
|
|
|
115
115
|
const refCheck = (ref: React.RefObject<HTMLElement>) => {
|
|
116
|
-
expect(ref.current).toHaveAttribute(
|
|
116
|
+
expect(ref.current).toHaveAttribute("data-ref", "testing");
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
render(<ExampleComponent propagateRef={refCheck} />);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
describe(
|
|
124
|
-
it(
|
|
123
|
+
describe("accessibility controls", () => {
|
|
124
|
+
it("opening works correctly with arrow key down, then navigation should work with arrow keys", () => {
|
|
125
125
|
const { getByTestId, trigger } = createContextMenu();
|
|
126
|
-
const firstContextMenuItem = getByTestId(
|
|
127
|
-
const secondContextMenuItem = getByTestId(
|
|
128
|
-
const thirdContextMenuItem = getByTestId(
|
|
129
|
-
|
|
130
|
-
userEvent.
|
|
131
|
-
userEvent.keyboard(
|
|
132
|
-
|
|
126
|
+
const firstContextMenuItem = getByTestId("contextmenuitem");
|
|
127
|
+
const secondContextMenuItem = getByTestId("contextmenuitem2");
|
|
128
|
+
const thirdContextMenuItem = getByTestId("contextmenuitem3");
|
|
129
|
+
|
|
130
|
+
userEvent.tab();
|
|
131
|
+
userEvent.keyboard("{arrowdown}");
|
|
132
|
+
userEvent.keyboard("{arrowdown}");
|
|
133
|
+
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
|
133
134
|
expect(firstContextMenuItem).toHaveFocus();
|
|
134
135
|
|
|
135
|
-
userEvent.keyboard(
|
|
136
|
+
userEvent.keyboard("{arrowdown}");
|
|
136
137
|
expect(secondContextMenuItem).toHaveFocus();
|
|
137
138
|
|
|
138
|
-
userEvent.keyboard(
|
|
139
|
+
userEvent.keyboard("{arrowdown}");
|
|
139
140
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
140
141
|
|
|
141
|
-
userEvent.keyboard(
|
|
142
|
+
userEvent.keyboard("{arrowdown}");
|
|
142
143
|
expect(firstContextMenuItem).toHaveFocus();
|
|
143
144
|
|
|
144
|
-
userEvent.keyboard(
|
|
145
|
+
userEvent.keyboard("{arrowup}");
|
|
145
146
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
146
147
|
|
|
147
|
-
userEvent.keyboard(
|
|
148
|
+
userEvent.keyboard("{arrowup}");
|
|
148
149
|
expect(secondContextMenuItem).toHaveFocus();
|
|
149
150
|
});
|
|
150
151
|
|
|
151
|
-
it(
|
|
152
|
+
it("opens correctly with enter key, closing works with escape key.", async () => {
|
|
152
153
|
const { trigger } = createContextMenu();
|
|
153
154
|
|
|
154
|
-
userEvent.
|
|
155
|
+
userEvent.tab();
|
|
156
|
+
userEvent.keyboard("{enter}");
|
|
155
157
|
|
|
156
|
-
expect(trigger).toHaveAttribute(
|
|
158
|
+
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
|
157
159
|
|
|
158
|
-
userEvent.keyboard(
|
|
160
|
+
userEvent.keyboard("{escape}");
|
|
159
161
|
|
|
160
|
-
expect(trigger).toHaveAttribute(
|
|
162
|
+
expect(trigger).toHaveAttribute("aria-expanded", "false");
|
|
161
163
|
});
|
|
162
164
|
|
|
163
|
-
it(
|
|
165
|
+
it("opens correctly with space, home and end buttons work", () => {
|
|
164
166
|
const { trigger, getByTestId } = createContextMenu();
|
|
165
|
-
const firstContextMenuItem = getByTestId(
|
|
166
|
-
const thirdContextMenuItem = getByTestId(
|
|
167
|
+
const firstContextMenuItem = getByTestId("contextmenuitem");
|
|
168
|
+
const thirdContextMenuItem = getByTestId("contextmenuitem3");
|
|
167
169
|
|
|
168
|
-
userEvent.
|
|
170
|
+
userEvent.tab();
|
|
171
|
+
userEvent.keyboard("{space}");
|
|
169
172
|
|
|
170
|
-
expect(trigger).toHaveAttribute(
|
|
173
|
+
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
|
171
174
|
|
|
172
|
-
userEvent.keyboard(
|
|
175
|
+
userEvent.keyboard("{end}");
|
|
173
176
|
|
|
174
177
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
175
178
|
|
|
176
|
-
userEvent.keyboard(
|
|
179
|
+
userEvent.keyboard("{home}");
|
|
177
180
|
|
|
178
181
|
expect(firstContextMenuItem).toHaveFocus();
|
|
179
182
|
});
|
|
180
183
|
|
|
181
|
-
it(
|
|
182
|
-
onClick.mockImplementation(
|
|
183
|
-
expect(e.target.getAttribute(
|
|
184
|
+
it("opens correctly with space, navigate with arrow keys, select with enter", () => {
|
|
185
|
+
onClick.mockImplementation(e => {
|
|
186
|
+
expect(e.target.getAttribute("data-testid")).toBe("contextmenuitem3");
|
|
184
187
|
});
|
|
185
188
|
|
|
186
|
-
const { trigger, getByTestId } = createContextMenu(
|
|
187
|
-
...defaultParams
|
|
189
|
+
const { trigger, getByTestId } = createContextMenu(defaultParams => ({
|
|
190
|
+
...defaultParams
|
|
188
191
|
}));
|
|
189
|
-
const thirdContextMenuItem = getByTestId(
|
|
192
|
+
const thirdContextMenuItem = getByTestId("contextmenuitem3");
|
|
190
193
|
|
|
191
|
-
userEvent.
|
|
194
|
+
userEvent.tab();
|
|
195
|
+
userEvent.keyboard("{space}");
|
|
192
196
|
|
|
193
|
-
expect(trigger).toHaveAttribute(
|
|
197
|
+
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
|
194
198
|
|
|
195
|
-
userEvent.keyboard(
|
|
196
|
-
userEvent.keyboard(
|
|
197
|
-
userEvent.keyboard(
|
|
199
|
+
userEvent.keyboard("{arrowdown}");
|
|
200
|
+
userEvent.keyboard("{arrowdown}");
|
|
201
|
+
userEvent.keyboard("{arrowdown}");
|
|
198
202
|
|
|
199
203
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
200
204
|
|
|
201
|
-
userEvent.keyboard(
|
|
205
|
+
userEvent.keyboard("{enter}");
|
|
202
206
|
|
|
203
207
|
expect(onClick).toHaveBeenCalled();
|
|
204
208
|
});
|
|
205
209
|
|
|
206
|
-
it(
|
|
207
|
-
onClick.mockImplementation(
|
|
208
|
-
expect(e.target.getAttribute(
|
|
210
|
+
it("opens correctly with enter, navigate with arrow keys, select with space", () => {
|
|
211
|
+
onClick.mockImplementation(e => {
|
|
212
|
+
expect(e.target.getAttribute("data-testid")).toBe("contextmenuitem3");
|
|
209
213
|
});
|
|
210
214
|
|
|
211
|
-
const { trigger, getByTestId } = createContextMenu(
|
|
212
|
-
...defaultParams
|
|
215
|
+
const { trigger, getByTestId } = createContextMenu(defaultParams => ({
|
|
216
|
+
...defaultParams
|
|
213
217
|
}));
|
|
214
|
-
const thirdContextMenuItem = getByTestId(
|
|
218
|
+
const thirdContextMenuItem = getByTestId("contextmenuitem3");
|
|
215
219
|
|
|
216
|
-
userEvent.
|
|
220
|
+
userEvent.tab();
|
|
221
|
+
userEvent.keyboard("{enter}");
|
|
217
222
|
|
|
218
|
-
expect(trigger).toHaveAttribute(
|
|
223
|
+
expect(trigger).toHaveAttribute("aria-expanded", "true");
|
|
219
224
|
|
|
220
|
-
userEvent.keyboard(
|
|
221
|
-
userEvent.keyboard(
|
|
222
|
-
userEvent.keyboard(
|
|
225
|
+
userEvent.keyboard("{arrowdown}");
|
|
226
|
+
userEvent.keyboard("{arrowdown}");
|
|
227
|
+
userEvent.keyboard("{arrowdown}");
|
|
223
228
|
|
|
224
229
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
225
230
|
|
|
226
|
-
userEvent.keyboard(
|
|
231
|
+
userEvent.keyboard("{space}");
|
|
227
232
|
|
|
228
233
|
expect(onClick).toHaveBeenCalled();
|
|
229
234
|
|
|
230
|
-
userEvent.keyboard(
|
|
235
|
+
userEvent.keyboard("{space}");
|
|
231
236
|
|
|
232
237
|
expect(thirdContextMenuItem).toHaveFocus();
|
|
233
238
|
});
|
|
@@ -4,17 +4,17 @@ import React, {
|
|
|
4
4
|
ReactNode,
|
|
5
5
|
useEffect,
|
|
6
6
|
useRef,
|
|
7
|
-
useState
|
|
8
|
-
} from
|
|
9
|
-
import { Props as ButtonProps } from
|
|
10
|
-
import { Props as IconButtonProps } from
|
|
11
|
-
import { Popover } from
|
|
12
|
-
import { Placement, Offset } from
|
|
13
|
-
import classes from
|
|
14
|
-
import { useBodyClick } from
|
|
15
|
-
import { createPortal } from
|
|
7
|
+
useState
|
|
8
|
+
} from "react";
|
|
9
|
+
import { Props as ButtonProps } from "../Button/Button";
|
|
10
|
+
import { Props as IconButtonProps } from "../Button/IconButton";
|
|
11
|
+
import { Popover } from "../Popover/Popover";
|
|
12
|
+
import { Placement, Offset } from "../hooks/usePosition";
|
|
13
|
+
import classes from "./ContextMenu.module.scss";
|
|
14
|
+
import { useBodyClick } from "../hooks/useBodyClick";
|
|
15
|
+
import { createPortal } from "react-dom";
|
|
16
16
|
|
|
17
|
-
export interface Props extends ComponentPropsWithRef<
|
|
17
|
+
export interface Props extends ComponentPropsWithRef<"div"> {
|
|
18
18
|
trigger: ReactElement<ButtonProps> | ReactElement<IconButtonProps>;
|
|
19
19
|
children: ReactNode;
|
|
20
20
|
placement?: Placement;
|
|
@@ -36,9 +36,9 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
36
36
|
show = false,
|
|
37
37
|
onShow,
|
|
38
38
|
onClose,
|
|
39
|
-
placement = { horizontal:
|
|
39
|
+
placement = { horizontal: "right", vertical: "top" },
|
|
40
40
|
offset = { top: 0, bottom: 0, left: 0, right: 0 },
|
|
41
|
-
transformOrigin = { horizontal:
|
|
41
|
+
transformOrigin = { horizontal: "left", vertical: "top" },
|
|
42
42
|
domRoot = document.body,
|
|
43
43
|
...rest
|
|
44
44
|
}: Props,
|
|
@@ -46,6 +46,7 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
46
46
|
) => {
|
|
47
47
|
const anchorEl = useRef<HTMLButtonElement>(null);
|
|
48
48
|
const [showContextMenu, setShowContextMenu] = useState(show);
|
|
49
|
+
const [hasBeenClosed, setHasBeenClosed] = useState(false);
|
|
49
50
|
const [selectedContextMenuItem, setSelectedContextMenuItem] = useState(-1);
|
|
50
51
|
const [focusedContextMenuItem, setFocusedContextMenuItem] = useState(-1);
|
|
51
52
|
const [shouldClick, setShouldClick] =
|
|
@@ -55,7 +56,7 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
55
56
|
const [childrenCount] = useState(React.Children.count(children));
|
|
56
57
|
|
|
57
58
|
if (!id) {
|
|
58
|
-
throw new Error(
|
|
59
|
+
throw new Error("You need to provide an ID to the context menu");
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
const onArrowNavigation = (event: React.KeyboardEvent) => {
|
|
@@ -64,15 +65,15 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
const codesToPrevenDefault = [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
"ArrowDown",
|
|
69
|
+
"ArrowUp",
|
|
70
|
+
"ArrowLeft",
|
|
71
|
+
"ArrowRight",
|
|
72
|
+
"Enter",
|
|
73
|
+
"Space",
|
|
74
|
+
"Escape",
|
|
75
|
+
"End",
|
|
76
|
+
"Home"
|
|
76
77
|
];
|
|
77
78
|
|
|
78
79
|
if (codesToPrevenDefault.includes(event.code)) {
|
|
@@ -80,22 +81,22 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
switch (event.code) {
|
|
83
|
-
case
|
|
84
|
+
case "ArrowDown":
|
|
84
85
|
if (!showContextMenu) {
|
|
85
86
|
setShowContextMenu(true);
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
|
-
setFocusedContextMenuItem(
|
|
89
|
+
setFocusedContextMenuItem(prevState => {
|
|
89
90
|
return prevState + 1 > childrenCount - 1 ? 0 : prevState + 1;
|
|
90
91
|
});
|
|
91
92
|
return;
|
|
92
|
-
case
|
|
93
|
-
setFocusedContextMenuItem(
|
|
93
|
+
case "ArrowUp":
|
|
94
|
+
setFocusedContextMenuItem(prevState => {
|
|
94
95
|
return prevState - 1 < 0 ? childrenCount - 1 : prevState - 1;
|
|
95
96
|
});
|
|
96
97
|
return;
|
|
97
|
-
case
|
|
98
|
-
case
|
|
98
|
+
case "Enter":
|
|
99
|
+
case "Space":
|
|
99
100
|
if (!showContextMenu) {
|
|
100
101
|
setShowContextMenu(true);
|
|
101
102
|
return;
|
|
@@ -105,21 +106,21 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
105
106
|
setSelectedContextMenuItem(focusedContextMenuItem);
|
|
106
107
|
setShowContextMenu(false);
|
|
107
108
|
return;
|
|
108
|
-
case
|
|
109
|
-
case
|
|
109
|
+
case "Tab":
|
|
110
|
+
case "Escape":
|
|
110
111
|
setShowContextMenu(false);
|
|
111
112
|
return;
|
|
112
|
-
case
|
|
113
|
+
case "End":
|
|
113
114
|
setFocusedContextMenuItem(childrenCount - 1);
|
|
114
115
|
return;
|
|
115
|
-
case
|
|
116
|
+
case "Home":
|
|
116
117
|
setFocusedContextMenuItem(0);
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
};
|
|
120
121
|
|
|
121
122
|
useBodyClick(
|
|
122
|
-
|
|
123
|
+
event => {
|
|
123
124
|
return showContextMenu && anchorEl.current !== event.target;
|
|
124
125
|
},
|
|
125
126
|
() => {
|
|
@@ -133,20 +134,21 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
133
134
|
onShow && onShow();
|
|
134
135
|
} else {
|
|
135
136
|
onClose && onClose();
|
|
137
|
+
!hasBeenClosed && setHasBeenClosed(true);
|
|
136
138
|
setFocusedContextMenuItem(-1);
|
|
137
|
-
anchorEl.current && anchorEl.current.focus();
|
|
139
|
+
hasBeenClosed && anchorEl.current && anchorEl.current.focus();
|
|
138
140
|
}
|
|
139
141
|
}, [showContextMenu]);
|
|
140
142
|
|
|
141
143
|
const renderTrigger = () =>
|
|
142
144
|
React.cloneElement(trigger, {
|
|
143
145
|
id: id,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
"aria-haspopup": "true",
|
|
147
|
+
"aria-controls": `${id}-menu`,
|
|
148
|
+
"aria-expanded": showContextMenu,
|
|
147
149
|
onClick: () => setShowContextMenu(!showContextMenu),
|
|
148
150
|
tabIndex: 0,
|
|
149
|
-
ref: anchorEl
|
|
151
|
+
ref: anchorEl
|
|
150
152
|
});
|
|
151
153
|
|
|
152
154
|
const renderChildren = () => {
|
|
@@ -161,13 +163,13 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
161
163
|
hasFocus: focusedContextMenuItem === index,
|
|
162
164
|
isSelected: selectedContextMenuItem === index,
|
|
163
165
|
contextMenuOpened: showContextMenu,
|
|
164
|
-
shouldClick: shouldClick
|
|
166
|
+
shouldClick: shouldClick
|
|
165
167
|
});
|
|
166
168
|
});
|
|
167
169
|
};
|
|
168
170
|
|
|
169
171
|
return (
|
|
170
|
-
<div {...rest} ref={ref} onKeyDown={onArrowNavigation} className={classes[
|
|
172
|
+
<div {...rest} ref={ref} onKeyDown={onArrowNavigation} className={classes["context-menu"]}>
|
|
171
173
|
{renderTrigger()}
|
|
172
174
|
{createPortal(
|
|
173
175
|
<Popover
|
|
@@ -177,7 +179,7 @@ export const ContextMenu = React.forwardRef<HTMLDivElement, Props>(
|
|
|
177
179
|
anchorEl={anchorEl}
|
|
178
180
|
show={showContextMenu}
|
|
179
181
|
>
|
|
180
|
-
<ul className={classes[
|
|
182
|
+
<ul className={classes["menu"]} id={`${id}-menu`} aria-describedby={id} role="menu">
|
|
181
183
|
{renderChildren()}
|
|
182
184
|
</ul>
|
|
183
185
|
</Popover>,
|