@hitachivantara/uikit-react-core 6.6.1 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseDropdown/BaseDropdown.js +28 -120
- package/dist/BaseDropdown/BaseDropdown.styles.js +4 -19
- package/dist/BaseDropdown/BaseDropdownPanel.js +79 -65
- package/dist/BaseDropdown/utils.js +79 -0
- package/dist/DropDownMenu/DropDownMenu.js +5 -5
- package/dist/Dropdown/Dropdown.js +7 -2
- package/dist/Dropdown/List/List.js +2 -3
- package/dist/DropdownButton/DropdownButton.js +0 -2
- package/dist/FormElement/Suggestions/Suggestions.js +12 -9
- package/dist/FormElement/Suggestions/Suggestions.styles.js +5 -18
- package/dist/Select/Select.js +13 -19
- package/dist/Select/Select.styles.js +6 -11
- package/dist/TreeView/TreeView.js +1 -1
- package/dist/TreeView/internals/hooks/plugins/useTreeViewNodes.js +1 -1
- package/dist/TreeView/internals/hooks/useTreeView.js +1 -1
- package/dist/TreeView/internals/hooks/useTreeViewModels.js +18 -16
- package/dist/VerticalNavigation/NavigationPopup/NavigationPopupContainer.js +2 -1
- package/dist/index.d.ts +377 -363
- package/dist/index.js +2 -0
- package/dist/themes/next.js +22 -23
- package/dist/themes/pentaho.js +19 -28
- package/package.json +6 -6
- package/dist/BaseDropdown/context.js +0 -11
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { forwardRef, useState,
|
|
3
|
-
import
|
|
4
|
-
import { useForkRef } from "@mui/material/utils";
|
|
5
|
-
import { detectOverflow } from "@popperjs/core";
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useId, useCallback, isValidElement, cloneElement, Fragment } from "react";
|
|
3
|
+
import useForkRef from "@mui/utils/useForkRef";
|
|
6
4
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
7
5
|
import { useControlled } from "../hooks/useControlled.js";
|
|
8
6
|
import { useUniqueId } from "../hooks/useUniqueId.js";
|
|
9
7
|
import { HvIcon } from "../icons.js";
|
|
10
|
-
import { getFirstAndLastFocus } from "../utils/focusableElementFinder.js";
|
|
11
8
|
import { isKey, isOneOfKeys } from "../utils/keyboardUtils.js";
|
|
12
9
|
import { useClasses } from "./BaseDropdown.styles.js";
|
|
13
10
|
import { staticClasses } from "./BaseDropdown.styles.js";
|
|
14
|
-
import {
|
|
15
|
-
import { BaseDropdownContext, useBaseDropdownContext } from "./context.js";
|
|
11
|
+
import { HvDropdownPanel } from "./BaseDropdownPanel.js";
|
|
16
12
|
import { HvTypography } from "../Typography/Typography.js";
|
|
17
|
-
const
|
|
13
|
+
const HvBaseDropdown = forwardRef(function BaseDropdown(props, ref) {
|
|
18
14
|
const {
|
|
19
15
|
id: idProp,
|
|
20
16
|
className,
|
|
@@ -26,6 +22,9 @@ const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
|
26
22
|
headerComponent: HeaderComponentProp,
|
|
27
23
|
adornment,
|
|
28
24
|
expanded,
|
|
25
|
+
popperProps,
|
|
26
|
+
variableWidth = false,
|
|
27
|
+
placement: placementProp = "right",
|
|
29
28
|
dropdownHeaderProps,
|
|
30
29
|
defaultExpanded,
|
|
31
30
|
disabled,
|
|
@@ -38,15 +37,14 @@ const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
|
38
37
|
dropdownHeaderRef: dropdownHeaderRefProp,
|
|
39
38
|
onToggle,
|
|
40
39
|
onClickOutside,
|
|
40
|
+
onContainerCreation,
|
|
41
41
|
...others
|
|
42
|
-
} = props;
|
|
42
|
+
} = useDefaultProps("HvBaseDropdown", props);
|
|
43
43
|
const { classes, cx } = useClasses(classesProp);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
setReferenceElement
|
|
49
|
-
} = useBaseDropdownContext();
|
|
44
|
+
const [computedPlacement, setComputedPlacement] = useState();
|
|
45
|
+
const [referenceElement, setReferenceElement] = useState(
|
|
46
|
+
null
|
|
47
|
+
);
|
|
50
48
|
const [isOpen, setIsOpen] = useControlled(expanded, Boolean(defaultExpanded));
|
|
51
49
|
const headerRef = useForkRef(
|
|
52
50
|
setReferenceElement,
|
|
@@ -92,7 +90,7 @@ const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
|
92
90
|
const defaultHeaderElement = /* @__PURE__ */ jsxs(
|
|
93
91
|
"div",
|
|
94
92
|
{
|
|
95
|
-
"data-popper-placement":
|
|
93
|
+
"data-popper-placement": computedPlacement,
|
|
96
94
|
className: cx(classes.header, {
|
|
97
95
|
[classes.headerOpen]: isOpen,
|
|
98
96
|
[classes.headerReadOnly]: readOnly,
|
|
@@ -130,18 +128,6 @@ const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
|
130
128
|
ref: headerRef,
|
|
131
129
|
...headerControlArias
|
|
132
130
|
}) : defaultHeaderElement;
|
|
133
|
-
const handleContainerKeyDown = (event) => {
|
|
134
|
-
if (isKey(event, "Esc")) {
|
|
135
|
-
handleToggle(event);
|
|
136
|
-
}
|
|
137
|
-
if (isKey(event, "Tab") && !event.shiftKey) {
|
|
138
|
-
const focusList = getFirstAndLastFocus(popperElement);
|
|
139
|
-
if (document.activeElement === focusList?.last) {
|
|
140
|
-
event.preventDefault();
|
|
141
|
-
focusList?.first?.focus();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
131
|
const handleOutside = (event) => {
|
|
146
132
|
const isButtonClick = referenceElement?.contains(event.target);
|
|
147
133
|
if (!isButtonClick) {
|
|
@@ -178,106 +164,28 @@ const BaseDropdown = forwardRef(function BaseDropdown2(props, ref) {
|
|
|
178
164
|
children: headerElement
|
|
179
165
|
}
|
|
180
166
|
),
|
|
181
|
-
|
|
182
|
-
|
|
167
|
+
/* @__PURE__ */ jsx(
|
|
168
|
+
HvDropdownPanel,
|
|
183
169
|
{
|
|
184
|
-
|
|
170
|
+
open: isOpen,
|
|
171
|
+
classes: { container: classes.container, panel: classes.panel },
|
|
172
|
+
placement: `bottom-${placementProp === "right" ? "start" : "end"}`,
|
|
173
|
+
variableWidth,
|
|
185
174
|
containerId,
|
|
186
175
|
onClickAway: handleOutside,
|
|
187
176
|
disablePortal,
|
|
188
|
-
|
|
177
|
+
anchorEl: referenceElement,
|
|
178
|
+
onToggle: handleToggle,
|
|
179
|
+
onFirstUpdate: (state) => {
|
|
180
|
+
setComputedPlacement(state.placement);
|
|
181
|
+
onContainerCreation?.(state.elements?.popper ?? null, state);
|
|
182
|
+
},
|
|
183
|
+
popperOptions: popperProps,
|
|
189
184
|
children
|
|
190
185
|
}
|
|
191
186
|
)
|
|
192
187
|
] });
|
|
193
188
|
});
|
|
194
|
-
const HvBaseDropdown = forwardRef(
|
|
195
|
-
function HvBaseDropdown2(props, ref) {
|
|
196
|
-
const {
|
|
197
|
-
popperProps = {},
|
|
198
|
-
variableWidth,
|
|
199
|
-
placement: placementProp = "right",
|
|
200
|
-
onContainerCreation,
|
|
201
|
-
...others
|
|
202
|
-
} = useDefaultProps("HvBaseDropdown", props);
|
|
203
|
-
const placement = `bottom-${placementProp === "right" ? "start" : "end"}`;
|
|
204
|
-
const { modifiers: popperPropsModifiers, ...otherPopperProps } = popperProps;
|
|
205
|
-
const [referenceElement, setReferenceElement] = useState(null);
|
|
206
|
-
const [popperElement, setPopperElement] = useState(
|
|
207
|
-
null
|
|
208
|
-
);
|
|
209
|
-
const onFirstUpdate = useCallback(() => {
|
|
210
|
-
onContainerCreation?.(popperElement);
|
|
211
|
-
}, [onContainerCreation, popperElement]);
|
|
212
|
-
const modifiers = useMemo(
|
|
213
|
-
() => [
|
|
214
|
-
{
|
|
215
|
-
name: "variableWidth",
|
|
216
|
-
enabled: !variableWidth,
|
|
217
|
-
phase: "beforeWrite",
|
|
218
|
-
requires: ["computeStyles"],
|
|
219
|
-
fn: ({ state }) => {
|
|
220
|
-
state.styles.popper.width = `${state.rects.reference.width}px`;
|
|
221
|
-
},
|
|
222
|
-
effect: ({ state }) => {
|
|
223
|
-
state.elements.popper.style.width = `${state.elements.reference.offsetWidth}px`;
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
name: "maxSize",
|
|
228
|
-
enabled: true,
|
|
229
|
-
phase: "main",
|
|
230
|
-
requiresIfExists: ["offset", "preventOverflow", "flip"],
|
|
231
|
-
fn: ({ state, name, options }) => {
|
|
232
|
-
const overflow = detectOverflow(state, options);
|
|
233
|
-
const x = state.modifiersData.preventOverflow?.x || 0;
|
|
234
|
-
const y = state.modifiersData.preventOverflow?.y || 0;
|
|
235
|
-
const popperWidth = state.rects.popper.width;
|
|
236
|
-
const popperHeight = state.rects.popper.height;
|
|
237
|
-
const basePlacement = state.placement.split("-")[0];
|
|
238
|
-
const widthProp = basePlacement === "left" ? "left" : "right";
|
|
239
|
-
const heightProp = basePlacement === "top" ? "top" : "bottom";
|
|
240
|
-
state.modifiersData[name] = {
|
|
241
|
-
width: popperWidth - overflow[widthProp] - x,
|
|
242
|
-
height: popperHeight - overflow[heightProp] - y
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
name: "applyMaxSize",
|
|
248
|
-
enabled: true,
|
|
249
|
-
phase: "beforeWrite",
|
|
250
|
-
requires: ["maxSize"],
|
|
251
|
-
fn: ({ state }) => {
|
|
252
|
-
const { width, height } = state.modifiersData.maxSize;
|
|
253
|
-
state.styles.popper.maxWidth = `${width}px`;
|
|
254
|
-
state.styles.popper.maxHeight = `${height}px`;
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
|
-
...popperPropsModifiers || []
|
|
258
|
-
],
|
|
259
|
-
[popperPropsModifiers, variableWidth]
|
|
260
|
-
);
|
|
261
|
-
const popper = usePopper(referenceElement, popperElement, {
|
|
262
|
-
placement,
|
|
263
|
-
modifiers,
|
|
264
|
-
onFirstUpdate,
|
|
265
|
-
...otherPopperProps
|
|
266
|
-
});
|
|
267
|
-
const value = useMemo(
|
|
268
|
-
() => ({
|
|
269
|
-
popperPlacement: popper?.attributes.popper?.["data-popper-placement"] ?? "bottom",
|
|
270
|
-
popper,
|
|
271
|
-
popperElement,
|
|
272
|
-
setPopperElement,
|
|
273
|
-
referenceElement,
|
|
274
|
-
setReferenceElement
|
|
275
|
-
}),
|
|
276
|
-
[popper, popperElement, referenceElement]
|
|
277
|
-
);
|
|
278
|
-
return /* @__PURE__ */ jsx(BaseDropdownContext.Provider, { value, children: /* @__PURE__ */ jsx(BaseDropdown, { ref, ...others }) });
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
189
|
export {
|
|
282
190
|
HvBaseDropdown,
|
|
283
191
|
staticClasses as baseDropdownClasses
|
|
@@ -10,7 +10,7 @@ const { useClasses, staticClasses } = createClasses("HvBaseDropdown", {
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
anchor: { display: "inline-block", width: "100%" },
|
|
13
|
-
container: {
|
|
13
|
+
container: {},
|
|
14
14
|
header: {
|
|
15
15
|
cursor: "pointer",
|
|
16
16
|
userSelect: "none",
|
|
@@ -76,24 +76,9 @@ const { useClasses, staticClasses } = createClasses("HvBaseDropdown", {
|
|
|
76
76
|
color: theme.colors.textSubtle
|
|
77
77
|
},
|
|
78
78
|
panel: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
inputExtensionOpen: {
|
|
84
|
-
height: "0px",
|
|
85
|
-
backgroundColor: theme.colors.bgContainer,
|
|
86
|
-
borderTop: "none",
|
|
87
|
-
borderBottom: "none",
|
|
88
|
-
borderRight: `1px solid ${theme.colors.text}`,
|
|
89
|
-
borderLeft: `1px solid ${theme.colors.text}`
|
|
90
|
-
},
|
|
91
|
-
inputExtensionLeftPosition: { marginLeft: "auto" },
|
|
92
|
-
inputExtensionOpenShadow: {
|
|
93
|
-
boxShadow: `0px 8px 0px ${theme.colors.textDimmed}, 0px 0px 9px 0px rgba(65,65,65,.12)`
|
|
94
|
-
},
|
|
95
|
-
inputExtensionFloatRight: { float: "right" },
|
|
96
|
-
inputExtensionFloatLeft: { float: "left" }
|
|
79
|
+
padding: 0
|
|
80
|
+
// TODO(major): re-add padding as most elements need it
|
|
81
|
+
}
|
|
97
82
|
});
|
|
98
83
|
export {
|
|
99
84
|
staticClasses,
|
|
@@ -1,77 +1,91 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
|
4
|
+
import Popper from "@mui/material/Popper";
|
|
5
|
+
import { useDefaultProps, useTheme, createClasses } from "@hitachivantara/uikit-react-utils";
|
|
6
|
+
import { theme } from "@hitachivantara/uikit-styles";
|
|
4
7
|
import { getContainerElement } from "../utils/document.js";
|
|
5
|
-
import {
|
|
8
|
+
import { getFirstAndLastFocus } from "../utils/focusableElementFinder.js";
|
|
9
|
+
import { isKey } from "../utils/keyboardUtils.js";
|
|
10
|
+
import { usePopperModifiers } from "./utils.js";
|
|
6
11
|
import { HvPanel } from "../Panel/Panel.js";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const name = "HvDropdownPanel";
|
|
13
|
+
const { useClasses } = createClasses(name, {
|
|
14
|
+
container: {
|
|
15
|
+
zIndex: theme.zIndices.popover,
|
|
16
|
+
width: "auto"
|
|
17
|
+
},
|
|
18
|
+
panel: {
|
|
19
|
+
padding: theme.space.xs,
|
|
20
|
+
border: `1px solid ${theme.colors.text}`
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const HvDropdownPanel = (props) => {
|
|
24
|
+
const {
|
|
25
|
+
classes: classesProp,
|
|
26
|
+
className,
|
|
27
|
+
containerId,
|
|
28
|
+
children,
|
|
29
|
+
variableWidth = true,
|
|
30
|
+
anchorEl,
|
|
31
|
+
disablePortal,
|
|
32
|
+
modifiers: modifiersProp,
|
|
33
|
+
popperOptions,
|
|
34
|
+
onToggle,
|
|
35
|
+
onClickAway,
|
|
36
|
+
onFirstUpdate,
|
|
37
|
+
...others
|
|
38
|
+
} = useDefaultProps(name, props);
|
|
39
|
+
const { classes, cx } = useClasses(classesProp, false);
|
|
17
40
|
const { rootId } = useTheme();
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
),
|
|
39
|
-
/* @__PURE__ */ jsx(
|
|
40
|
-
HvPanel,
|
|
41
|
-
{
|
|
42
|
-
id: containerId,
|
|
43
|
-
"data-popper-placement": popperPlacement,
|
|
44
|
-
className: classes.panel,
|
|
45
|
-
children
|
|
46
|
-
}
|
|
47
|
-
),
|
|
48
|
-
popperPlacement?.includes("top") && /* @__PURE__ */ jsx(
|
|
49
|
-
"div",
|
|
50
|
-
{
|
|
51
|
-
style: { width: extensionWidth },
|
|
52
|
-
className: cx(
|
|
53
|
-
classes.inputExtensionOpen,
|
|
54
|
-
classes.inputExtensionOpenShadow,
|
|
55
|
-
{
|
|
56
|
-
[classes.inputExtensionFloatRight]: popperPlacement.includes("end"),
|
|
57
|
-
[classes.inputExtensionFloatLeft]: popperPlacement.includes("start")
|
|
58
|
-
}
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
)
|
|
62
|
-
]
|
|
41
|
+
const popperRef = useRef(null);
|
|
42
|
+
const [placement, setPlacement] = useState();
|
|
43
|
+
const modifiers = usePopperModifiers({
|
|
44
|
+
variableWidth,
|
|
45
|
+
modifiers: modifiersProp,
|
|
46
|
+
onPlacementChange: setPlacement
|
|
47
|
+
});
|
|
48
|
+
const handleKeyDown = (event) => {
|
|
49
|
+
if (isKey(event, "Esc")) {
|
|
50
|
+
onToggle?.(event);
|
|
51
|
+
}
|
|
52
|
+
if (isKey(event, "Tab") && !event.shiftKey) {
|
|
53
|
+
const focusList = getFirstAndLastFocus(
|
|
54
|
+
popperRef.current?.state?.elements.popper
|
|
55
|
+
);
|
|
56
|
+
if (document.activeElement === focusList?.last) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
focusList?.first?.focus();
|
|
63
59
|
}
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
}
|
|
61
|
+
};
|
|
66
62
|
return /* @__PURE__ */ jsx(
|
|
67
|
-
|
|
63
|
+
Popper,
|
|
68
64
|
{
|
|
69
|
-
|
|
65
|
+
anchorEl,
|
|
66
|
+
popperRef,
|
|
70
67
|
disablePortal,
|
|
71
|
-
|
|
68
|
+
container: !disablePortal ? getContainerElement(rootId) : void 0,
|
|
69
|
+
className: cx(classes.container, className),
|
|
70
|
+
modifiers,
|
|
71
|
+
onKeyDown: handleKeyDown,
|
|
72
|
+
popperOptions: {
|
|
73
|
+
onFirstUpdate,
|
|
74
|
+
...popperOptions
|
|
75
|
+
},
|
|
76
|
+
...others,
|
|
77
|
+
children: /* @__PURE__ */ jsx(ClickAwayListener, { onClickAway, children: /* @__PURE__ */ jsx(
|
|
78
|
+
HvPanel,
|
|
79
|
+
{
|
|
80
|
+
id: containerId,
|
|
81
|
+
className: classes.panel,
|
|
82
|
+
"data-popper-placement": placement,
|
|
83
|
+
children
|
|
84
|
+
}
|
|
85
|
+
) })
|
|
72
86
|
}
|
|
73
87
|
);
|
|
74
88
|
};
|
|
75
89
|
export {
|
|
76
|
-
|
|
90
|
+
HvDropdownPanel
|
|
77
91
|
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { detectOverflow } from "@popperjs/core";
|
|
3
|
+
function usePopperModifiers({
|
|
4
|
+
variableWidth,
|
|
5
|
+
modifiers,
|
|
6
|
+
onPlacementChange
|
|
7
|
+
}) {
|
|
8
|
+
return useMemo(
|
|
9
|
+
() => [
|
|
10
|
+
{
|
|
11
|
+
name: "placementListener",
|
|
12
|
+
enabled: true,
|
|
13
|
+
phase: "main",
|
|
14
|
+
fn: ({ state }) => onPlacementChange?.(state.placement)
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "fixedWidth",
|
|
18
|
+
enabled: !variableWidth,
|
|
19
|
+
phase: "beforeWrite",
|
|
20
|
+
requires: ["computeStyles"],
|
|
21
|
+
fn: ({ state }) => {
|
|
22
|
+
state.styles.popper.width = `${state.rects.reference.width}px`;
|
|
23
|
+
},
|
|
24
|
+
effect: ({ state }) => {
|
|
25
|
+
const { popper, reference } = state.elements;
|
|
26
|
+
popper.style.width = `${reference.offsetWidth}px`;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "minSize",
|
|
31
|
+
enabled: true,
|
|
32
|
+
phase: "main",
|
|
33
|
+
fn: ({ state }) => {
|
|
34
|
+
state.styles.popper.minWidth = `${state.rects.reference.width}px`;
|
|
35
|
+
},
|
|
36
|
+
effect: ({ state }) => {
|
|
37
|
+
const { popper, reference } = state.elements;
|
|
38
|
+
popper.style.minWidth = `${reference.offsetWidth}px`;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "maxSize",
|
|
43
|
+
enabled: true,
|
|
44
|
+
phase: "main",
|
|
45
|
+
requiresIfExists: ["offset", "preventOverflow", "flip"],
|
|
46
|
+
fn: ({ state, name, options }) => {
|
|
47
|
+
const overflow = detectOverflow(state, options);
|
|
48
|
+
const x = state.modifiersData.preventOverflow?.x || 0;
|
|
49
|
+
const y = state.modifiersData.preventOverflow?.y || 0;
|
|
50
|
+
const popperWidth = state.rects.popper.width;
|
|
51
|
+
const popperHeight = state.rects.popper.height;
|
|
52
|
+
const basePlacement = state.placement.split("-")[0];
|
|
53
|
+
const widthProp = basePlacement === "left" ? "left" : "right";
|
|
54
|
+
const heightProp = basePlacement === "top" ? "top" : "bottom";
|
|
55
|
+
state.modifiersData[name] = {
|
|
56
|
+
width: popperWidth - overflow[widthProp] - x,
|
|
57
|
+
height: popperHeight - overflow[heightProp] - y
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "applyMaxSize",
|
|
63
|
+
enabled: true,
|
|
64
|
+
phase: "beforeWrite",
|
|
65
|
+
requires: ["maxSize"],
|
|
66
|
+
fn: ({ state }) => {
|
|
67
|
+
const { width, height } = state.modifiersData.maxSize;
|
|
68
|
+
state.styles.popper.maxWidth = `${width}px`;
|
|
69
|
+
state.styles.popper.maxHeight = `${height}px`;
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
...modifiers || []
|
|
73
|
+
],
|
|
74
|
+
[modifiers, variableWidth, onPlacementChange]
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
usePopperModifiers
|
|
79
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useMemo } from "react";
|
|
2
|
+
import { forwardRef, useState, useMemo } from "react";
|
|
3
3
|
import { useDefaultProps } from "@hitachivantara/uikit-react-utils";
|
|
4
|
-
import { useBaseDropdownContext } from "../BaseDropdown/context.js";
|
|
5
4
|
import { useControlled } from "../hooks/useControlled.js";
|
|
6
5
|
import { useLabels } from "../hooks/useLabels.js";
|
|
7
6
|
import { useUniqueId } from "../hooks/useUniqueId.js";
|
|
@@ -19,7 +18,6 @@ const DEFAULT_LABELS = {
|
|
|
19
18
|
const HeaderComponent = forwardRef(
|
|
20
19
|
function HeaderComponent2(props, ref) {
|
|
21
20
|
const { open, icon, disabled, ...others } = props;
|
|
22
|
-
const { popperPlacement } = useBaseDropdownContext();
|
|
23
21
|
return /* @__PURE__ */ jsx(
|
|
24
22
|
HvDropdownButton,
|
|
25
23
|
{
|
|
@@ -29,7 +27,6 @@ const HeaderComponent = forwardRef(
|
|
|
29
27
|
disabled,
|
|
30
28
|
"aria-expanded": open,
|
|
31
29
|
"aria-haspopup": "menu",
|
|
32
|
-
placement: popperPlacement,
|
|
33
30
|
...others,
|
|
34
31
|
children: icon || /* @__PURE__ */ jsx(HvIcon, { name: "DotsVertical" })
|
|
35
32
|
}
|
|
@@ -58,6 +55,7 @@ const HvDropDownMenu = forwardRef(function HvDropDownMenu2(props, ref) {
|
|
|
58
55
|
} = useDefaultProps("HvDropDownMenu", props);
|
|
59
56
|
const { classes, cx } = useClasses(classesProp);
|
|
60
57
|
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
58
|
+
const [computedPlacement, setComputedPlacement] = useState();
|
|
61
59
|
const [open, setOpen] = useControlled(expanded, Boolean(defaultExpanded));
|
|
62
60
|
const id = useUniqueId(idProp);
|
|
63
61
|
const handleClose = (event) => {
|
|
@@ -87,6 +85,7 @@ const HvDropDownMenu = forwardRef(function HvDropDownMenu2(props, ref) {
|
|
|
87
85
|
},
|
|
88
86
|
expanded: open && !disabled,
|
|
89
87
|
headerComponent: HeaderComponent,
|
|
88
|
+
"data-popper-placement": computedPlacement,
|
|
90
89
|
size,
|
|
91
90
|
variant,
|
|
92
91
|
open,
|
|
@@ -100,7 +99,8 @@ const HvDropDownMenu = forwardRef(function HvDropDownMenu2(props, ref) {
|
|
|
100
99
|
onToggle?.(e, s);
|
|
101
100
|
},
|
|
102
101
|
disabled,
|
|
103
|
-
onContainerCreation: (containerEl) => {
|
|
102
|
+
onContainerCreation: (containerEl, state) => {
|
|
103
|
+
setComputedPlacement(state.placement);
|
|
104
104
|
containerEl?.getElementsByTagName("li")[0]?.focus();
|
|
105
105
|
},
|
|
106
106
|
...others,
|
|
@@ -76,6 +76,7 @@ const HvDropdown = fixedForwardRef(function HvDropdown2(props, ref) {
|
|
|
76
76
|
const { classes, cx } = useClasses(classesProp);
|
|
77
77
|
const labels = useLabels(DEFAULT_LABELS, labelsProp);
|
|
78
78
|
const elementId = useUniqueId(id);
|
|
79
|
+
const [popperStyles, setPopperStyles] = useState();
|
|
79
80
|
const [validationState, setValidationState] = useControlled(
|
|
80
81
|
status,
|
|
81
82
|
"standBy"
|
|
@@ -254,7 +255,10 @@ const HvDropdown = fixedForwardRef(function HvDropdown2(props, ref) {
|
|
|
254
255
|
placeholder: buildHeaderLabel(),
|
|
255
256
|
onToggle: handleToggle,
|
|
256
257
|
onClickOutside: handleClickOutside,
|
|
257
|
-
onContainerCreation:
|
|
258
|
+
onContainerCreation: (el, state) => {
|
|
259
|
+
setFocusToContent(el);
|
|
260
|
+
setPopperStyles(state.elements?.popper.style);
|
|
261
|
+
},
|
|
258
262
|
role: "combobox",
|
|
259
263
|
variableWidth,
|
|
260
264
|
"aria-label": ariaLabel,
|
|
@@ -276,6 +280,7 @@ const HvDropdown = fixedForwardRef(function HvDropdown2(props, ref) {
|
|
|
276
280
|
},
|
|
277
281
|
values: internalValues,
|
|
278
282
|
multiSelect,
|
|
283
|
+
popperStyles,
|
|
279
284
|
showSearch,
|
|
280
285
|
onChange: handleSelection,
|
|
281
286
|
onCancel: handleCancel,
|
|
@@ -287,7 +292,7 @@ const HvDropdown = fixedForwardRef(function HvDropdown2(props, ref) {
|
|
|
287
292
|
height,
|
|
288
293
|
maxHeight,
|
|
289
294
|
virtualized,
|
|
290
|
-
"data-is-dropdown":
|
|
295
|
+
"data-is-dropdown": true,
|
|
291
296
|
...listProps
|
|
292
297
|
}
|
|
293
298
|
)
|
|
@@ -2,7 +2,6 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState, useMemo, useEffect } from "react";
|
|
3
3
|
import { useDefaultProps, mergeStyles } from "@hitachivantara/uikit-react-utils";
|
|
4
4
|
import { theme } from "@hitachivantara/uikit-styles";
|
|
5
|
-
import { useBaseDropdownContext } from "../../BaseDropdown/context.js";
|
|
6
5
|
import { CounterLabel } from "../../utils/CounterLabel.js";
|
|
7
6
|
import { getSelected } from "../utils.js";
|
|
8
7
|
import { useClasses } from "./List.styles.js";
|
|
@@ -29,6 +28,7 @@ const HvDropdownList = (props) => {
|
|
|
29
28
|
notifyChangesOnFirstRender = false,
|
|
30
29
|
singleSelectionToggle,
|
|
31
30
|
height: heightProp,
|
|
31
|
+
popperStyles,
|
|
32
32
|
maxHeight: maxHeightProp,
|
|
33
33
|
virtualized = false,
|
|
34
34
|
...others
|
|
@@ -38,8 +38,7 @@ const HvDropdownList = (props) => {
|
|
|
38
38
|
const [list, setList] = useState(clone(values));
|
|
39
39
|
const [allSelected, setAllSelected] = useState(false);
|
|
40
40
|
const [anySelected, setAnySelected] = useState(false);
|
|
41
|
-
const {
|
|
42
|
-
const { maxWidth, maxHeight } = popper?.styles.popper || {};
|
|
41
|
+
const { maxWidth, maxHeight } = popperStyles || {};
|
|
43
42
|
const hasChanges = useMemo(() => {
|
|
44
43
|
return String(getSelectedIds(values)) !== String(getSelectedIds(list));
|
|
45
44
|
}, [list, values]);
|
|
@@ -9,7 +9,6 @@ const HvDropdownButton = forwardRef(function HvDropdownButton2(props, ref) {
|
|
|
9
9
|
const {
|
|
10
10
|
className,
|
|
11
11
|
classes: classesProp,
|
|
12
|
-
placement = "bottom",
|
|
13
12
|
disabled,
|
|
14
13
|
open,
|
|
15
14
|
icon,
|
|
@@ -27,7 +26,6 @@ const HvDropdownButton = forwardRef(function HvDropdownButton2(props, ref) {
|
|
|
27
26
|
ref,
|
|
28
27
|
icon,
|
|
29
28
|
disabled: disabled || readOnly,
|
|
30
|
-
"data-popper-placement": placement,
|
|
31
29
|
className: cx(
|
|
32
30
|
classes.root,
|
|
33
31
|
{
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useContext, useRef } from "react";
|
|
3
|
-
import { ClickAwayListener, Popper } from "@mui/base";
|
|
4
3
|
import { useForkRef } from "@mui/material/utils";
|
|
5
|
-
import { useDefaultProps, useTheme } from "@hitachivantara/uikit-react-utils";
|
|
4
|
+
import { useDefaultProps, useTheme, mergeStyles } from "@hitachivantara/uikit-react-utils";
|
|
5
|
+
import { HvDropdownPanel } from "../../BaseDropdown/BaseDropdownPanel.js";
|
|
6
6
|
import { getContainerElement } from "../../utils/document.js";
|
|
7
7
|
import { setId } from "../../utils/setId.js";
|
|
8
8
|
import { HvFormElementContext } from "../context.js";
|
|
@@ -37,13 +37,13 @@ const HvSuggestions = forwardRef(function HvSuggestions2(props, extRef) {
|
|
|
37
37
|
ref: forkedRef,
|
|
38
38
|
className: cx(classes.root, className),
|
|
39
39
|
...others,
|
|
40
|
-
children: /* @__PURE__ */ jsx(
|
|
41
|
-
|
|
40
|
+
children: /* @__PURE__ */ jsx(
|
|
41
|
+
HvDropdownPanel,
|
|
42
42
|
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"--popper-width": enablePortal
|
|
46
|
-
},
|
|
43
|
+
onClickAway: onClose,
|
|
44
|
+
style: mergeStyles(void 0, {
|
|
45
|
+
"--popper-width": enablePortal && `${anchorEl?.clientWidth}px`
|
|
46
|
+
}),
|
|
47
47
|
open: openProp,
|
|
48
48
|
disablePortal: !enablePortal,
|
|
49
49
|
container: enablePortal ? getContainerElement(rootId) : void 0,
|
|
@@ -51,6 +51,7 @@ const HvSuggestions = forwardRef(function HvSuggestions2(props, extRef) {
|
|
|
51
51
|
className: cx(classes.popper, {
|
|
52
52
|
[classes.portal]: enablePortal
|
|
53
53
|
}),
|
|
54
|
+
classes: { panel: classes.panel },
|
|
54
55
|
...popperProps,
|
|
55
56
|
children: /* @__PURE__ */ jsx(
|
|
56
57
|
HvSelectionList,
|
|
@@ -58,11 +59,13 @@ const HvSuggestions = forwardRef(function HvSuggestions2(props, extRef) {
|
|
|
58
59
|
className: classes.list,
|
|
59
60
|
id: setId(id, "list"),
|
|
60
61
|
onChange: onSuggestionSelected,
|
|
62
|
+
onMouseDown: (evt) => evt.preventDefault(),
|
|
63
|
+
onPointerDown: (evt) => evt.preventDefault(),
|
|
61
64
|
children: suggestionValues?.map((item) => /* @__PURE__ */ jsx(HvListItem, { value: item, disabled: item.disabled, children: item.label }, item.id))
|
|
62
65
|
}
|
|
63
66
|
)
|
|
64
67
|
}
|
|
65
|
-
)
|
|
68
|
+
)
|
|
66
69
|
}
|
|
67
70
|
);
|
|
68
71
|
});
|