@entur/dropdown 5.4.11 → 6.0.0-beta.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/components/DropdownList.d.ts +2 -1
- package/dist/dropdown.cjs.development.js +96 -51
- package/dist/dropdown.cjs.development.js.map +1 -1
- package/dist/dropdown.cjs.production.min.js +1 -1
- package/dist/dropdown.cjs.production.min.js.map +1 -1
- package/dist/dropdown.esm.js +99 -54
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +138 -192
- package/package.json +9 -8
|
@@ -13,6 +13,7 @@ type DropdownListProps<ValueType> = {
|
|
|
13
13
|
listStyle: {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
} | undefined;
|
|
16
|
+
listRef?: React.Ref<HTMLUListElement>;
|
|
16
17
|
loading?: boolean;
|
|
17
18
|
loadingText?: string;
|
|
18
19
|
noMatchesText?: string;
|
|
@@ -21,5 +22,5 @@ type DropdownListProps<ValueType> = {
|
|
|
21
22
|
selectedItems: NormalizedDropdownItemType<ValueType>[];
|
|
22
23
|
[key: string]: any;
|
|
23
24
|
};
|
|
24
|
-
export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, inputValue, isOpen, highlightedIndex, listItems, listStyle, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, showSelectAllInList, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
|
|
25
|
+
export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, inputValue, isOpen, highlightedIndex, listItems, listStyle, listRef, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, showSelectAllInList, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
|
|
25
26
|
export {};
|
|
@@ -11,6 +11,7 @@ var icons = require('@entur/icons');
|
|
|
11
11
|
var a11y = require('@entur/a11y');
|
|
12
12
|
var loader = require('@entur/loader');
|
|
13
13
|
var tokens = require('@entur/tokens');
|
|
14
|
+
var reactDom = require('@floating-ui/react-dom');
|
|
14
15
|
var button = require('@entur/button');
|
|
15
16
|
var chip = require('@entur/chip');
|
|
16
17
|
var tooltip = require('@entur/tooltip');
|
|
@@ -1238,7 +1239,7 @@ function SelectedItemsLabel(items) {
|
|
|
1238
1239
|
}).toString() : items.length + " elementer valgt";
|
|
1239
1240
|
}
|
|
1240
1241
|
|
|
1241
|
-
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "inputValue", "isOpen", "highlightedIndex", "listItems", "listStyle", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "showSelectAllInList"];
|
|
1242
|
+
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "inputValue", "isOpen", "highlightedIndex", "listItems", "listStyle", "listRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "showSelectAllInList"];
|
|
1242
1243
|
var DropdownList = function DropdownList(_ref) {
|
|
1243
1244
|
var _listItems$;
|
|
1244
1245
|
var _ref$ariaLabelChosenS = _ref.ariaLabelChosenSingular,
|
|
@@ -1251,6 +1252,7 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1251
1252
|
highlightedIndex = _ref.highlightedIndex,
|
|
1252
1253
|
listItems = _ref.listItems,
|
|
1253
1254
|
listStyle = _ref.listStyle,
|
|
1255
|
+
listRef = _ref.listRef,
|
|
1254
1256
|
_ref$loading = _ref.loading,
|
|
1255
1257
|
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
1256
1258
|
_ref$loadingText = _ref.loadingText,
|
|
@@ -1333,7 +1335,8 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1333
1335
|
return (
|
|
1334
1336
|
// use popover from @entur/tooltip when that package upgrades to floating-ui
|
|
1335
1337
|
React.createElement("ul", _extends({}, getMenuProps({
|
|
1336
|
-
'aria-multiselectable': isMultiselect
|
|
1338
|
+
'aria-multiselectable': isMultiselect,
|
|
1339
|
+
ref: utils.mergeRefs(getMenuProps().ref, listRef)
|
|
1337
1340
|
}), {
|
|
1338
1341
|
className: "eds-dropdown__list",
|
|
1339
1342
|
style: _extends({
|
|
@@ -1687,17 +1690,17 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1687
1690
|
var _useState = React.useState(value !== null),
|
|
1688
1691
|
showSelectedItem = _useState[0],
|
|
1689
1692
|
setShowSelectedItem = _useState[1];
|
|
1690
|
-
var
|
|
1691
|
-
lastHighlightedIndex =
|
|
1692
|
-
setLastHighlightedIndex =
|
|
1693
|
+
var _useState2 = React.useState(0),
|
|
1694
|
+
lastHighlightedIndex = _useState2[0],
|
|
1695
|
+
setLastHighlightedIndex = _useState2[1];
|
|
1693
1696
|
var inputRef = React.useRef(null);
|
|
1694
1697
|
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
1695
1698
|
normalizedItems = _useResolvedItems.items,
|
|
1696
1699
|
loading = _useResolvedItems.loading,
|
|
1697
1700
|
fetchItems = _useResolvedItems.fetchItems;
|
|
1698
|
-
var
|
|
1699
|
-
listItems =
|
|
1700
|
-
setListItems =
|
|
1701
|
+
var _useState3 = React.useState(normalizedItems),
|
|
1702
|
+
listItems = _useState3[0],
|
|
1703
|
+
setListItems = _useState3[1];
|
|
1701
1704
|
var filterListItems = function filterListItems(_ref2) {
|
|
1702
1705
|
var inputValue = _ref2.inputValue;
|
|
1703
1706
|
return setListItems(normalizedItems.filter(function (item) {
|
|
@@ -1712,12 +1715,22 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1712
1715
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
1713
1716
|
});
|
|
1714
1717
|
};
|
|
1718
|
+
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
1715
1719
|
React.useEffect(function () {
|
|
1716
1720
|
filterListItems({
|
|
1717
1721
|
inputValue: inputValue
|
|
1718
1722
|
});
|
|
1719
1723
|
}, [normalizedItems]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
1720
|
-
|
|
1724
|
+
React.useEffect(function () {
|
|
1725
|
+
// sync internal state on initial render
|
|
1726
|
+
if (selectedItem !== null && !inputHasFocus) {
|
|
1727
|
+
setShowSelectedItem(true);
|
|
1728
|
+
updateListItems({
|
|
1729
|
+
inputValue: EMPTY_INPUT
|
|
1730
|
+
});
|
|
1731
|
+
setInputValue(EMPTY_INPUT);
|
|
1732
|
+
}
|
|
1733
|
+
}, []);
|
|
1721
1734
|
var stateReducer = React.useCallback(function (_, _ref4) {
|
|
1722
1735
|
var type = _ref4.type,
|
|
1723
1736
|
changes = _ref4.changes;
|
|
@@ -1811,6 +1824,16 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1811
1824
|
selectedItem = _useCombobox.selectedItem,
|
|
1812
1825
|
inputValue = _useCombobox.inputValue,
|
|
1813
1826
|
setInputValue = _useCombobox.setInputValue;
|
|
1827
|
+
var _useFloating = reactDom.useFloating({
|
|
1828
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
1829
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
1830
|
+
},
|
|
1831
|
+
placement: 'bottom-start',
|
|
1832
|
+
open: isOpen,
|
|
1833
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
1834
|
+
}),
|
|
1835
|
+
refs = _useFloating.refs,
|
|
1836
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
1814
1837
|
var handleOnClear = function handleOnClear() {
|
|
1815
1838
|
var _inputRef$current;
|
|
1816
1839
|
onChange(null);
|
|
@@ -1821,13 +1844,24 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1821
1844
|
});
|
|
1822
1845
|
setShowSelectedItem(false);
|
|
1823
1846
|
};
|
|
1824
|
-
return React.createElement(
|
|
1825
|
-
|
|
1826
|
-
|
|
1847
|
+
return React.createElement(form.BaseFormControl, _extends({
|
|
1848
|
+
append: React.createElement(FieldAppend$1, {
|
|
1849
|
+
ariaLabelCloseList: ariaLabelCloseList,
|
|
1850
|
+
ariaLabelOpenList: ariaLabelOpenList,
|
|
1851
|
+
clearable: clearable,
|
|
1852
|
+
labelClearSelectedItems: labelClearSelectedItem,
|
|
1853
|
+
disabled: readOnly || disabled,
|
|
1854
|
+
focusable: false,
|
|
1855
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
1856
|
+
isOpen: isOpen,
|
|
1857
|
+
loading: loading,
|
|
1858
|
+
loadingText: loadingText,
|
|
1859
|
+
onClear: handleOnClear,
|
|
1860
|
+
selectedItems: [selectedItem]
|
|
1861
|
+
}),
|
|
1862
|
+
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
1863
|
+
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1827
1864
|
}),
|
|
1828
|
-
style: style
|
|
1829
|
-
}, React.createElement(form.BaseFormControl, _extends({
|
|
1830
|
-
className: classNames('eds-dropdown', 'eds-dropdown--searchable'),
|
|
1831
1865
|
disabled: disabled,
|
|
1832
1866
|
disableLabelAnimation: disableLabelAnimation,
|
|
1833
1867
|
feedback: feedback,
|
|
@@ -1842,23 +1876,10 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1842
1876
|
},
|
|
1843
1877
|
prepend: prepend,
|
|
1844
1878
|
readOnly: readOnly,
|
|
1879
|
+
ref: refs.setReference,
|
|
1880
|
+
style: style,
|
|
1845
1881
|
variant: variant
|
|
1846
|
-
}, rest, {
|
|
1847
|
-
append: React.createElement(FieldAppend$1, {
|
|
1848
|
-
ariaLabelCloseList: ariaLabelCloseList,
|
|
1849
|
-
ariaLabelOpenList: ariaLabelOpenList,
|
|
1850
|
-
clearable: clearable,
|
|
1851
|
-
labelClearSelectedItems: labelClearSelectedItem,
|
|
1852
|
-
disabled: readOnly || disabled,
|
|
1853
|
-
focusable: false,
|
|
1854
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
1855
|
-
isOpen: isOpen,
|
|
1856
|
-
loading: loading,
|
|
1857
|
-
loadingText: loadingText,
|
|
1858
|
-
onClear: handleOnClear,
|
|
1859
|
-
selectedItems: [selectedItem]
|
|
1860
|
-
})
|
|
1861
|
-
}), React.createElement("span", {
|
|
1882
|
+
}, rest), React.createElement("span", {
|
|
1862
1883
|
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1863
1884
|
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1864
1885
|
}),
|
|
@@ -1885,12 +1906,13 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1885
1906
|
if (selectOnTab && isOpen && e.key === 'Tab') onChange == null ? void 0 : onChange(listItems[highlightedIndex]);
|
|
1886
1907
|
},
|
|
1887
1908
|
ref: inputRef
|
|
1888
|
-
})))
|
|
1909
|
+
}))), React.createElement(DropdownList, {
|
|
1889
1910
|
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1890
1911
|
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1891
1912
|
isOpen: isOpen,
|
|
1892
1913
|
listItems: listItems,
|
|
1893
|
-
listStyle: listStyle,
|
|
1914
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
1915
|
+
listRef: refs.setFloating,
|
|
1894
1916
|
loading: loading,
|
|
1895
1917
|
loadingText: loadingText,
|
|
1896
1918
|
noMatchesText: noMatchesText,
|
|
@@ -2095,6 +2117,11 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2095
2117
|
updateListItems({
|
|
2096
2118
|
inputValue: changes.inputValue
|
|
2097
2119
|
});
|
|
2120
|
+
// set highlighted item to first item after search
|
|
2121
|
+
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
2122
|
+
return _extends({}, changes, {
|
|
2123
|
+
highlightedIndex: hideSelectAll ? 0 : 1
|
|
2124
|
+
});
|
|
2098
2125
|
}
|
|
2099
2126
|
return changes;
|
|
2100
2127
|
}
|
|
@@ -2162,6 +2189,16 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2162
2189
|
isOpen = _useCombobox.isOpen,
|
|
2163
2190
|
openMenu = _useCombobox.openMenu,
|
|
2164
2191
|
setInputValue = _useCombobox.setInputValue;
|
|
2192
|
+
var _useFloating = reactDom.useFloating({
|
|
2193
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
2194
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
2195
|
+
},
|
|
2196
|
+
placement: 'bottom-start',
|
|
2197
|
+
open: isOpen,
|
|
2198
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
2199
|
+
}),
|
|
2200
|
+
refs = _useFloating.refs,
|
|
2201
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
2165
2202
|
var handleOnClear = function handleOnClear() {
|
|
2166
2203
|
var _inputRef$current3;
|
|
2167
2204
|
onChange([]);
|
|
@@ -2171,12 +2208,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2171
2208
|
inputValue: inputValue
|
|
2172
2209
|
});
|
|
2173
2210
|
};
|
|
2174
|
-
return React.createElement(
|
|
2175
|
-
className: classNames('eds-dropdown__wrapper', className, {
|
|
2176
|
-
'eds-dropdown__wrapper--has-tooltip': labelTooltip !== undefined
|
|
2177
|
-
}),
|
|
2178
|
-
style: style
|
|
2179
|
-
}, React.createElement(form.BaseFormControl, _extends({
|
|
2211
|
+
return React.createElement(form.BaseFormControl, _extends({
|
|
2180
2212
|
append: React.createElement(FieldAppend$1, {
|
|
2181
2213
|
ariaLabelCloseList: ariaLabelCloseList,
|
|
2182
2214
|
ariaLabelOpenList: ariaLabelOpenList,
|
|
@@ -2191,7 +2223,9 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2191
2223
|
onClear: handleOnClear,
|
|
2192
2224
|
getToggleButtonProps: getToggleButtonProps
|
|
2193
2225
|
}),
|
|
2194
|
-
className: classNames('eds-dropdown', 'eds-dropdown--multiselect'
|
|
2226
|
+
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
2227
|
+
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
2228
|
+
}),
|
|
2195
2229
|
disabled: disabled,
|
|
2196
2230
|
feedback: feedback,
|
|
2197
2231
|
isFilled: hasSelectedItems || inputValue !== EMPTY_INPUT,
|
|
@@ -2204,6 +2238,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2204
2238
|
if (e.target === e.currentTarget) (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
2205
2239
|
},
|
|
2206
2240
|
readOnly: readOnly,
|
|
2241
|
+
ref: refs.setReference,
|
|
2242
|
+
style: style,
|
|
2207
2243
|
variant: variant
|
|
2208
2244
|
}, rest), React.createElement("div", {
|
|
2209
2245
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
@@ -2266,7 +2302,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2266
2302
|
preventKeyAction: isOpen,
|
|
2267
2303
|
ref: inputRef,
|
|
2268
2304
|
value: inputValue != null ? inputValue : EMPTY_INPUT
|
|
2269
|
-
}))))))
|
|
2305
|
+
})))))), React.createElement(DropdownList, {
|
|
2270
2306
|
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
2271
2307
|
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
2272
2308
|
getItemProps: getItemProps,
|
|
@@ -2275,7 +2311,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2275
2311
|
inputValue: inputValue,
|
|
2276
2312
|
isOpen: isOpen,
|
|
2277
2313
|
listItems: listItems,
|
|
2278
|
-
listStyle: listStyle,
|
|
2314
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
2315
|
+
listRef: refs.setFloating,
|
|
2279
2316
|
loading: loading,
|
|
2280
2317
|
loadingText: loadingText,
|
|
2281
2318
|
noMatchesText: noMatchesText,
|
|
@@ -2353,12 +2390,17 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2353
2390
|
getMenuProps = _useSelect.getMenuProps,
|
|
2354
2391
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
2355
2392
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2393
|
+
var _useFloating = reactDom.useFloating({
|
|
2394
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
2395
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
2396
|
+
},
|
|
2397
|
+
placement: 'bottom-start',
|
|
2398
|
+
open: isOpen,
|
|
2399
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
2359
2400
|
}),
|
|
2360
|
-
|
|
2361
|
-
|
|
2401
|
+
refs = _useFloating.refs,
|
|
2402
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
2403
|
+
return React.createElement(form.BaseFormControl, _extends({
|
|
2362
2404
|
append: React.createElement(FieldAppend$1, {
|
|
2363
2405
|
ariaHiddenToggleButton: true,
|
|
2364
2406
|
ariaLabelCloseList: ariaLabelCloseList,
|
|
@@ -2378,8 +2420,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2378
2420
|
disabled: readOnly || disabled,
|
|
2379
2421
|
selectedItems: [selectedItem]
|
|
2380
2422
|
}),
|
|
2381
|
-
className: classNames('eds-dropdown', {
|
|
2382
|
-
'eds-dropdown--
|
|
2423
|
+
className: classNames('eds-dropdown', className, {
|
|
2424
|
+
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
2383
2425
|
}),
|
|
2384
2426
|
disabled: disabled,
|
|
2385
2427
|
disableLabelAnimation: disableLabelAnimation,
|
|
@@ -2391,6 +2433,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2391
2433
|
labelTooltip: labelTooltip,
|
|
2392
2434
|
prepend: prepend,
|
|
2393
2435
|
readOnly: readOnly,
|
|
2436
|
+
ref: refs.setReference,
|
|
2437
|
+
style: style,
|
|
2394
2438
|
variant: variant
|
|
2395
2439
|
}, rest), React.createElement("div", _extends({
|
|
2396
2440
|
className: "eds-dropdown__selected-item"
|
|
@@ -2410,7 +2454,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2410
2454
|
className: classNames('eds-dropdown__selected-item__placeholder', {
|
|
2411
2455
|
'eds-dropdown__selected-item__placeholder--readonly': readOnly
|
|
2412
2456
|
})
|
|
2413
|
-
}, placeholder)) != null ? _ref3 : '')
|
|
2457
|
+
}, placeholder)) != null ? _ref3 : ''), React.createElement(DropdownList, {
|
|
2414
2458
|
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
2415
2459
|
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
2416
2460
|
getItemProps: getItemProps,
|
|
@@ -2418,7 +2462,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2418
2462
|
highlightedIndex: highlightedIndex,
|
|
2419
2463
|
isOpen: isOpen,
|
|
2420
2464
|
listItems: normalizedItems,
|
|
2421
|
-
listStyle: listStyle,
|
|
2465
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
2466
|
+
listRef: refs.setFloating,
|
|
2422
2467
|
loading: loading,
|
|
2423
2468
|
loadingText: loadingText,
|
|
2424
2469
|
selectedItems: selectedItem !== null ? [selectedItem] : []
|