@entur/dropdown 9.0.2 → 9.1.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/Dropdown.d.ts +77 -2
- package/dist/NativeDropdown.d.ts +48 -2
- package/dist/SearchableDropdown.d.ts +31 -1
- package/dist/dropdown.cjs +32 -6
- package/dist/dropdown.cjs.map +1 -1
- package/dist/dropdown.mjs +33 -7
- package/dist/dropdown.mjs.map +1 -1
- package/dist/useFloatingRef.d.ts +27 -0
- package/package.json +8 -8
package/dist/dropdown.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDebounce, getActiveElement, mergeRefs, warnAboutMissingStyles } from "@entur/utils";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import React, { forwardRef, createElement,
|
|
3
|
+
import React, { forwardRef, createElement, useRef, useLayoutEffect, useCallback, useMemo, useState, useEffect, useId } from "react";
|
|
4
4
|
import { useCombobox, useMultipleSelection, useSelect } from "downshift";
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import { useFloating, offset, shift, size, flip, autoUpdate } from "@floating-ui/react-dom";
|
|
@@ -385,6 +385,15 @@ const useResolvedItems = (itemsOrItemsResolver, debounceTimeout = 250) => {
|
|
|
385
385
|
fetchItems: debouncedFetchItems
|
|
386
386
|
};
|
|
387
387
|
};
|
|
388
|
+
function useFloatingRef(setElement) {
|
|
389
|
+
const latestSetElement = useRef(setElement);
|
|
390
|
+
useLayoutEffect(() => {
|
|
391
|
+
latestSetElement.current = setElement;
|
|
392
|
+
}, [setElement]);
|
|
393
|
+
return useCallback((node) => {
|
|
394
|
+
if (node !== null) latestSetElement.current(node);
|
|
395
|
+
}, []);
|
|
396
|
+
}
|
|
388
397
|
function createShadowEnvironment(shadowRoot) {
|
|
389
398
|
return {
|
|
390
399
|
addEventListener: shadowRoot.addEventListener.bind(shadowRoot),
|
|
@@ -695,6 +704,7 @@ const SearchableDropdown = React.forwardRef(
|
|
|
695
704
|
flip({ fallbackStrategy: "initialPlacement" })
|
|
696
705
|
]
|
|
697
706
|
});
|
|
707
|
+
const setFloatingMenu = useFloatingRef(refs.setFloating);
|
|
698
708
|
useLayoutEffect(() => {
|
|
699
709
|
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
700
710
|
return autoUpdate(
|
|
@@ -710,7 +720,7 @@ const SearchableDropdown = React.forwardRef(
|
|
|
710
720
|
});
|
|
711
721
|
const menuProps = getMenuProps({
|
|
712
722
|
refKey: "innerRef",
|
|
713
|
-
ref:
|
|
723
|
+
ref: setFloatingMenu,
|
|
714
724
|
style: listStyle
|
|
715
725
|
});
|
|
716
726
|
const inputProps = getInputProps({
|
|
@@ -808,7 +818,8 @@ const SearchableDropdown = React.forwardRef(
|
|
|
808
818
|
className: classNames("eds-dropdown__input eds-form-control", {
|
|
809
819
|
"eds-dropdown__input--hidden": showSelectedItem
|
|
810
820
|
}),
|
|
811
|
-
...inputProps
|
|
821
|
+
...inputProps,
|
|
822
|
+
"aria-invalid": variant === "negative" || variant === "error"
|
|
812
823
|
}
|
|
813
824
|
),
|
|
814
825
|
/* @__PURE__ */ jsx(
|
|
@@ -1075,6 +1086,7 @@ const MultiSelect = React.forwardRef(
|
|
|
1075
1086
|
flip({ fallbackStrategy: "initialPlacement" })
|
|
1076
1087
|
]
|
|
1077
1088
|
});
|
|
1089
|
+
const setFloatingMenu = useFloatingRef(refs.setFloating);
|
|
1078
1090
|
useLayoutEffect(() => {
|
|
1079
1091
|
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1080
1092
|
return autoUpdate(
|
|
@@ -1118,7 +1130,7 @@ const MultiSelect = React.forwardRef(
|
|
|
1118
1130
|
const menuProps = getMenuProps({
|
|
1119
1131
|
"aria-multiselectable": true,
|
|
1120
1132
|
refKey: "innerRef",
|
|
1121
|
-
ref:
|
|
1133
|
+
ref: setFloatingMenu,
|
|
1122
1134
|
style: listStyle
|
|
1123
1135
|
});
|
|
1124
1136
|
const toggleButtonProps = getToggleButtonProps({
|
|
@@ -1210,7 +1222,13 @@ const MultiSelect = React.forwardRef(
|
|
|
1210
1222
|
selectedItem: summarySelectedItems
|
|
1211
1223
|
}
|
|
1212
1224
|
),
|
|
1213
|
-
/* @__PURE__ */ jsx(
|
|
1225
|
+
/* @__PURE__ */ jsx(
|
|
1226
|
+
"input",
|
|
1227
|
+
{
|
|
1228
|
+
...inputProps,
|
|
1229
|
+
"aria-invalid": variant === "negative" || variant === "error"
|
|
1230
|
+
}
|
|
1231
|
+
)
|
|
1214
1232
|
]
|
|
1215
1233
|
}
|
|
1216
1234
|
),
|
|
@@ -1236,6 +1254,7 @@ const MultiSelect = React.forwardRef(
|
|
|
1236
1254
|
);
|
|
1237
1255
|
}
|
|
1238
1256
|
);
|
|
1257
|
+
const error$1 = "error";
|
|
1239
1258
|
const Dropdown = React.forwardRef(
|
|
1240
1259
|
({
|
|
1241
1260
|
ariaLabelChosenSingular,
|
|
@@ -1319,6 +1338,8 @@ const Dropdown = React.forwardRef(
|
|
|
1319
1338
|
]
|
|
1320
1339
|
});
|
|
1321
1340
|
floatingRefs = refs;
|
|
1341
|
+
const setFloatingMenu = useFloatingRef(refs.setFloating);
|
|
1342
|
+
const setFloatingReference = useFloatingRef(refs.setReference);
|
|
1322
1343
|
useLayoutEffect(() => {
|
|
1323
1344
|
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1324
1345
|
return autoUpdate(
|
|
@@ -1336,7 +1357,7 @@ const Dropdown = React.forwardRef(
|
|
|
1336
1357
|
isFilled
|
|
1337
1358
|
});
|
|
1338
1359
|
const toggleButtonProps = getToggleButtonProps({
|
|
1339
|
-
ref: mergeRefs(ref,
|
|
1360
|
+
ref: mergeRefs(ref, setFloatingReference, toggleButtonRef),
|
|
1340
1361
|
"aria-disabled": disabled,
|
|
1341
1362
|
"aria-label": disabled ? "Disabled dropdown" : "",
|
|
1342
1363
|
disabled,
|
|
@@ -1357,7 +1378,7 @@ const Dropdown = React.forwardRef(
|
|
|
1357
1378
|
});
|
|
1358
1379
|
const menuProps = getMenuProps({
|
|
1359
1380
|
refKey: "innerRef",
|
|
1360
|
-
ref:
|
|
1381
|
+
ref: setFloatingMenu,
|
|
1361
1382
|
style: listStyle
|
|
1362
1383
|
});
|
|
1363
1384
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1374,6 +1395,7 @@ const Dropdown = React.forwardRef(
|
|
|
1374
1395
|
style,
|
|
1375
1396
|
variant,
|
|
1376
1397
|
...toggleButtonProps,
|
|
1398
|
+
"aria-invalid": variant === "negative" || variant === error$1,
|
|
1377
1399
|
after: /* @__PURE__ */ jsx(
|
|
1378
1400
|
DropdownList,
|
|
1379
1401
|
{
|
|
@@ -1447,6 +1469,8 @@ const NativeDropdown = forwardRef(
|
|
|
1447
1469
|
style,
|
|
1448
1470
|
value,
|
|
1449
1471
|
variant,
|
|
1472
|
+
ariaAlertOnFeedback,
|
|
1473
|
+
feedbackProps,
|
|
1450
1474
|
...rest
|
|
1451
1475
|
}, ref) => {
|
|
1452
1476
|
const { items: normalizedItems, loading } = useResolvedItems(items);
|
|
@@ -1457,6 +1481,8 @@ const NativeDropdown = forwardRef(
|
|
|
1457
1481
|
disabled,
|
|
1458
1482
|
readOnly,
|
|
1459
1483
|
prepend,
|
|
1484
|
+
ariaAlertOnFeedback,
|
|
1485
|
+
feedbackProps,
|
|
1460
1486
|
append: /* @__PURE__ */ jsx(
|
|
1461
1487
|
FieldAppend,
|
|
1462
1488
|
{
|