@entur/dropdown 7.3.2-beta.9 → 7.3.3
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 +2 -3
- package/dist/MultiSelect.d.ts +2 -3
- package/dist/NativeDropdown.d.ts +2 -3
- package/dist/SearchableDropdown.d.ts +1 -2
- package/dist/components/DropdownList.d.ts +1 -2
- package/dist/components/FieldComponents.d.ts +1 -2
- package/dist/dropdown.cjs.js +1465 -0
- package/dist/dropdown.cjs.js.map +1 -0
- package/dist/dropdown.esm.js +1336 -1689
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/styles.css +82 -90
- package/package.json +31 -21
- package/dist/dropdown.cjs.development.js +0 -1825
- package/dist/dropdown.cjs.development.js.map +0 -1
- package/dist/dropdown.cjs.production.min.js +0 -2
- package/dist/dropdown.cjs.production.min.js.map +0 -1
- package/dist/index.js +0 -8
package/dist/dropdown.esm.js
CHANGED
|
@@ -1,678 +1,382 @@
|
|
|
1
|
-
import { useDebounce, mergeRefs, useRandomId, warnAboutMissingStyles } from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
46
|
-
var t = arguments[e];
|
|
47
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
48
|
-
}
|
|
49
|
-
return n;
|
|
50
|
-
}, _extends.apply(null, arguments);
|
|
51
|
-
}
|
|
52
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
53
|
-
if (null == r) return {};
|
|
54
|
-
var t = {};
|
|
55
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
56
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
57
|
-
t[n] = r[n];
|
|
58
|
-
}
|
|
59
|
-
return t;
|
|
60
|
-
}
|
|
61
|
-
function _regenerator() {
|
|
62
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
63
|
-
var e,
|
|
64
|
-
t,
|
|
65
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
66
|
-
n = r.iterator || "@@iterator",
|
|
67
|
-
o = r.toStringTag || "@@toStringTag";
|
|
68
|
-
function i(r, n, o, i) {
|
|
69
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
70
|
-
u = Object.create(c.prototype);
|
|
71
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
72
|
-
var i,
|
|
73
|
-
c,
|
|
74
|
-
u,
|
|
75
|
-
f = 0,
|
|
76
|
-
p = o || [],
|
|
77
|
-
y = !1,
|
|
78
|
-
G = {
|
|
79
|
-
p: 0,
|
|
80
|
-
n: 0,
|
|
81
|
-
v: e,
|
|
82
|
-
a: d,
|
|
83
|
-
f: d.bind(e, 4),
|
|
84
|
-
d: function (t, r) {
|
|
85
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
86
|
-
}
|
|
1
|
+
import { useDebounce, mergeRefs, useRandomId, warnAboutMissingStyles } from "@entur/utils";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { forwardRef, createElement, useState, useRef, useEffect, useCallback } from "react";
|
|
4
|
+
import { useCombobox, useMultipleSelection, useSelect } from "downshift";
|
|
5
|
+
import classNames from "classnames";
|
|
6
|
+
import { useFloating, offset, shift, size, flip, autoUpdate } from "@floating-ui/react-dom";
|
|
7
|
+
import { Checkbox, BaseFormControl } from "@entur/form";
|
|
8
|
+
import { space } from "@entur/tokens";
|
|
9
|
+
import { VisuallyHidden } from "@entur/a11y";
|
|
10
|
+
import { IconButton } from "@entur/button";
|
|
11
|
+
import { TagChip } from "@entur/chip";
|
|
12
|
+
import { DownArrowIcon, CloseSmallIcon } from "@entur/icons";
|
|
13
|
+
import { LoadingDots } from "@entur/loader";
|
|
14
|
+
import { Tooltip } from "@entur/tooltip";
|
|
15
|
+
const DropdownList = ({
|
|
16
|
+
ariaLabelChosenSingular = "valgt",
|
|
17
|
+
ariaLabelSelectedItem = ", valgt element, trykk for å fjerne",
|
|
18
|
+
getItemProps,
|
|
19
|
+
getMenuProps,
|
|
20
|
+
isOpen,
|
|
21
|
+
highlightedIndex,
|
|
22
|
+
listItems,
|
|
23
|
+
floatingStyles,
|
|
24
|
+
setListRef,
|
|
25
|
+
loading = false,
|
|
26
|
+
loadingText = "Laster inn …",
|
|
27
|
+
noMatchesText = "Ingen treff for søket",
|
|
28
|
+
selectAllCheckboxState,
|
|
29
|
+
selectAllItem,
|
|
30
|
+
selectedItems,
|
|
31
|
+
readOnly = false,
|
|
32
|
+
...rest
|
|
33
|
+
}) => {
|
|
34
|
+
const isMultiselect = selectAllItem !== void 0;
|
|
35
|
+
const isNoMatches = !loading && (listItems.length === 0 || listItems?.length === 1 && listItems?.[0]?.value === selectAllItem?.value);
|
|
36
|
+
const isItemSelected = (item) => selectedItems.some(
|
|
37
|
+
(selectedItem) => selectedItem?.value === item?.value && selectedItem?.label === item?.label
|
|
38
|
+
);
|
|
39
|
+
const ariaValuesSelectAll = () => {
|
|
40
|
+
switch (selectAllCheckboxState?.()) {
|
|
41
|
+
case "indeterminate": {
|
|
42
|
+
return {
|
|
43
|
+
label: `${selectAllItem?.label}, delvis valgt`,
|
|
44
|
+
selected: false
|
|
87
45
|
};
|
|
88
|
-
function d(r, n) {
|
|
89
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
90
|
-
var o,
|
|
91
|
-
i = p[t],
|
|
92
|
-
d = G.p,
|
|
93
|
-
l = i[2];
|
|
94
|
-
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
95
|
-
}
|
|
96
|
-
if (o || r > 1) return a;
|
|
97
|
-
throw y = !0, n;
|
|
98
46
|
}
|
|
99
|
-
|
|
100
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
101
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
102
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
103
|
-
try {
|
|
104
|
-
if (f = 2, i) {
|
|
105
|
-
if (c || (o = "next"), t = i[o]) {
|
|
106
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
107
|
-
if (!t.done) return t;
|
|
108
|
-
u = t.value, c < 2 && (c = 0);
|
|
109
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
110
|
-
i = e;
|
|
111
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
112
|
-
} catch (t) {
|
|
113
|
-
i = e, c = 1, u = t;
|
|
114
|
-
} finally {
|
|
115
|
-
f = 1;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
47
|
+
case true: {
|
|
118
48
|
return {
|
|
119
|
-
|
|
120
|
-
|
|
49
|
+
label: `${selectAllItem?.label}, ${ariaLabelChosenSingular}`,
|
|
50
|
+
selected: true
|
|
121
51
|
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
function Generator() {}
|
|
127
|
-
function GeneratorFunction() {}
|
|
128
|
-
function GeneratorFunctionPrototype() {}
|
|
129
|
-
t = Object.getPrototypeOf;
|
|
130
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
131
|
-
return this;
|
|
132
|
-
}), t),
|
|
133
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
134
|
-
function f(e) {
|
|
135
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
136
|
-
}
|
|
137
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
138
|
-
return this;
|
|
139
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
140
|
-
return "[object Generator]";
|
|
141
|
-
}), (_regenerator = function () {
|
|
142
|
-
return {
|
|
143
|
-
w: i,
|
|
144
|
-
m: f
|
|
145
|
-
};
|
|
146
|
-
})();
|
|
147
|
-
}
|
|
148
|
-
function _regeneratorAsync(n, e, r, t, o) {
|
|
149
|
-
var a = _regeneratorAsyncGen(n, e, r, t, o);
|
|
150
|
-
return a.next().then(function (n) {
|
|
151
|
-
return n.done ? n.value : a.next();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
function _regeneratorAsyncGen(r, e, t, o, n) {
|
|
155
|
-
return new _regeneratorAsyncIterator(_regenerator().w(r, e, t, o), n || Promise);
|
|
156
|
-
}
|
|
157
|
-
function _regeneratorAsyncIterator(t, e) {
|
|
158
|
-
function n(r, o, i, f) {
|
|
159
|
-
try {
|
|
160
|
-
var c = t[r](o),
|
|
161
|
-
u = c.value;
|
|
162
|
-
return u instanceof _OverloadYield ? e.resolve(u.v).then(function (t) {
|
|
163
|
-
n("next", t, i, f);
|
|
164
|
-
}, function (t) {
|
|
165
|
-
n("throw", t, i, f);
|
|
166
|
-
}) : e.resolve(u).then(function (t) {
|
|
167
|
-
c.value = t, i(c);
|
|
168
|
-
}, function (t) {
|
|
169
|
-
return n("throw", t, i, f);
|
|
170
|
-
});
|
|
171
|
-
} catch (t) {
|
|
172
|
-
f(t);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
var r;
|
|
176
|
-
this.next || (_regeneratorDefine(_regeneratorAsyncIterator.prototype), _regeneratorDefine(_regeneratorAsyncIterator.prototype, "function" == typeof Symbol && Symbol.asyncIterator || "@asyncIterator", function () {
|
|
177
|
-
return this;
|
|
178
|
-
})), _regeneratorDefine(this, "_invoke", function (t, o, i) {
|
|
179
|
-
function f() {
|
|
180
|
-
return new e(function (e, r) {
|
|
181
|
-
n(t, i, e, r);
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
return r = r ? r.then(f, f) : f();
|
|
185
|
-
}, !0);
|
|
186
|
-
}
|
|
187
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
188
|
-
var i = Object.defineProperty;
|
|
189
|
-
try {
|
|
190
|
-
i({}, "", {});
|
|
191
|
-
} catch (e) {
|
|
192
|
-
i = 0;
|
|
193
|
-
}
|
|
194
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
195
|
-
function o(r, n) {
|
|
196
|
-
_regeneratorDefine(e, r, function (e) {
|
|
197
|
-
return this._invoke(r, n, e);
|
|
198
|
-
});
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
return { label: `${selectAllItem?.label}`, selected: false };
|
|
55
|
+
}
|
|
199
56
|
}
|
|
200
|
-
r ? i ? i(e, r, {
|
|
201
|
-
value: n,
|
|
202
|
-
enumerable: !t,
|
|
203
|
-
configurable: !t,
|
|
204
|
-
writable: !t
|
|
205
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
206
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
207
|
-
}
|
|
208
|
-
function _regeneratorKeys(e) {
|
|
209
|
-
var n = Object(e),
|
|
210
|
-
r = [];
|
|
211
|
-
for (var t in n) r.unshift(t);
|
|
212
|
-
return function e() {
|
|
213
|
-
for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e;
|
|
214
|
-
return e.done = !0, e;
|
|
215
57
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return e && r >= e.length && (e = void 0), {
|
|
226
|
-
value: e && e[r++],
|
|
227
|
-
done: !e
|
|
228
|
-
};
|
|
58
|
+
const selectAllListItemContent = () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
Checkbox,
|
|
61
|
+
{
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
checked: selectAllCheckboxState?.(),
|
|
64
|
+
className: "eds-dropdown__list__item__checkbox",
|
|
65
|
+
tabIndex: -1,
|
|
66
|
+
onChange: () => void 0
|
|
229
67
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
e = r.m(_regeneratorRuntime),
|
|
238
|
-
t = (Object.getPrototypeOf ? Object.getPrototypeOf(e) : e.__proto__).constructor;
|
|
239
|
-
function n(r) {
|
|
240
|
-
var e = "function" == typeof r && r.constructor;
|
|
241
|
-
return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name));
|
|
242
|
-
}
|
|
243
|
-
var o = {
|
|
244
|
-
throw: 1,
|
|
245
|
-
return: 2,
|
|
246
|
-
break: 3,
|
|
247
|
-
continue: 3
|
|
248
|
-
};
|
|
249
|
-
function a(r) {
|
|
250
|
-
var e, t;
|
|
251
|
-
return function (n) {
|
|
252
|
-
e || (e = {
|
|
253
|
-
stop: function () {
|
|
254
|
-
return t(n.a, 2);
|
|
255
|
-
},
|
|
256
|
-
catch: function () {
|
|
257
|
-
return n.v;
|
|
258
|
-
},
|
|
259
|
-
abrupt: function (r, e) {
|
|
260
|
-
return t(n.a, o[r], e);
|
|
261
|
-
},
|
|
262
|
-
delegateYield: function (r, o, a) {
|
|
263
|
-
return e.resultName = o, t(n.d, _regeneratorValues(r), a);
|
|
264
|
-
},
|
|
265
|
-
finish: function (r) {
|
|
266
|
-
return t(n.f, r);
|
|
267
|
-
}
|
|
268
|
-
}, t = function (r, t, o) {
|
|
269
|
-
n.p = e.prev, n.n = e.next;
|
|
270
|
-
try {
|
|
271
|
-
return r(t, o);
|
|
272
|
-
} finally {
|
|
273
|
-
e.next = n.n;
|
|
274
|
-
}
|
|
275
|
-
}), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n;
|
|
276
|
-
try {
|
|
277
|
-
return r.call(this, e);
|
|
278
|
-
} finally {
|
|
279
|
-
n.p = e.prev, n.n = e.next;
|
|
68
|
+
),
|
|
69
|
+
/* @__PURE__ */ jsx(
|
|
70
|
+
"span",
|
|
71
|
+
{
|
|
72
|
+
className: "eds-dropdown__list__item__text",
|
|
73
|
+
"aria-label": ariaValuesSelectAll().label,
|
|
74
|
+
children: selectAllItem?.label
|
|
280
75
|
}
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return
|
|
285
|
-
wrap: function (e, t, n, o) {
|
|
286
|
-
return r.w(a(e), t, n, o && o.reverse());
|
|
287
|
-
},
|
|
288
|
-
isGeneratorFunction: n,
|
|
289
|
-
mark: r.m,
|
|
290
|
-
awrap: function (r, e) {
|
|
291
|
-
return new _OverloadYield(r, e);
|
|
292
|
-
},
|
|
293
|
-
AsyncIterator: _regeneratorAsyncIterator,
|
|
294
|
-
async: function (r, e, t, o, u) {
|
|
295
|
-
return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u);
|
|
296
|
-
},
|
|
297
|
-
keys: _regeneratorKeys,
|
|
298
|
-
values: _regeneratorValues
|
|
299
|
-
};
|
|
300
|
-
})();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "isOpen", "highlightedIndex", "listItems", "floatingStyles", "setListRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "readOnly"];
|
|
304
|
-
var DropdownList = function DropdownList(_ref) {
|
|
305
|
-
var _listItems$;
|
|
306
|
-
var _ref$ariaLabelChosenS = _ref.ariaLabelChosenSingular,
|
|
307
|
-
ariaLabelChosenSingular = _ref$ariaLabelChosenS === void 0 ? 'valgt' : _ref$ariaLabelChosenS,
|
|
308
|
-
_ref$ariaLabelSelecte = _ref.ariaLabelSelectedItem,
|
|
309
|
-
ariaLabelSelectedItem = _ref$ariaLabelSelecte === void 0 ? ', valgt element, trykk for å fjerne' : _ref$ariaLabelSelecte,
|
|
310
|
-
getItemProps = _ref.getItemProps,
|
|
311
|
-
getMenuProps = _ref.getMenuProps,
|
|
312
|
-
isOpen = _ref.isOpen,
|
|
313
|
-
highlightedIndex = _ref.highlightedIndex,
|
|
314
|
-
listItems = _ref.listItems,
|
|
315
|
-
floatingStyles = _ref.floatingStyles,
|
|
316
|
-
setListRef = _ref.setListRef,
|
|
317
|
-
_ref$loading = _ref.loading,
|
|
318
|
-
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
319
|
-
_ref$loadingText = _ref.loadingText,
|
|
320
|
-
loadingText = _ref$loadingText === void 0 ? 'Laster inn …' : _ref$loadingText,
|
|
321
|
-
_ref$noMatchesText = _ref.noMatchesText,
|
|
322
|
-
noMatchesText = _ref$noMatchesText === void 0 ? 'Ingen treff for søket' : _ref$noMatchesText,
|
|
323
|
-
selectAllCheckboxState = _ref.selectAllCheckboxState,
|
|
324
|
-
selectAllItem = _ref.selectAllItem,
|
|
325
|
-
selectedItems = _ref.selectedItems,
|
|
326
|
-
_ref$readOnly = _ref.readOnly,
|
|
327
|
-
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
328
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
329
|
-
var isMultiselect = selectAllItem !== undefined;
|
|
330
|
-
var isNoMatches = !loading && (listItems.length === 0 || (listItems == null ? void 0 : listItems.length) === 1 && (listItems == null || (_listItems$ = listItems[0]) == null ? void 0 : _listItems$.value) === (selectAllItem == null ? void 0 : selectAllItem.value));
|
|
331
|
-
var isItemSelected = function isItemSelected(item) {
|
|
332
|
-
return selectedItems.some(function (selectedItem) {
|
|
333
|
-
return (selectedItem == null ? void 0 : selectedItem.value) === (item == null ? void 0 : item.value) && (selectedItem == null ? void 0 : selectedItem.label) === (item == null ? void 0 : item.label);
|
|
334
|
-
});
|
|
76
|
+
)
|
|
77
|
+
] });
|
|
78
|
+
const isReactComponent = (icon) => {
|
|
79
|
+
return typeof icon === "function" || typeof icon === "object" && icon !== null && "$$typeof" in icon && typeof icon.$$typeof === "symbol";
|
|
335
80
|
};
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return {
|
|
341
|
-
label: (selectAllItem == null ? void 0 : selectAllItem.label) + ", delvis valgt",
|
|
342
|
-
selected: false
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
case true:
|
|
81
|
+
const listItemContent = (item) => {
|
|
82
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
83
|
+
isMultiselect && /* @__PURE__ */ jsx(
|
|
84
|
+
Checkbox,
|
|
346
85
|
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
86
|
+
"aria-hidden": "true",
|
|
87
|
+
checked: isItemSelected(item),
|
|
88
|
+
className: "eds-dropdown__list__item__checkbox",
|
|
89
|
+
tabIndex: -1,
|
|
90
|
+
onChange: () => void 0
|
|
351
91
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
}), React.createElement("span", {
|
|
371
|
-
className: "eds-dropdown__list__item__text",
|
|
372
|
-
"aria-label": ariaValuesSelectAll().label
|
|
373
|
-
}, selectAllItem == null ? void 0 : selectAllItem.label));
|
|
374
|
-
};
|
|
375
|
-
var isReactComponent = function isReactComponent(icon) {
|
|
376
|
-
return typeof icon === 'function' || typeof icon === 'object' && icon !== null && '$$typeof' in icon && typeof icon.$$typeof === 'symbol';
|
|
377
|
-
};
|
|
378
|
-
var listItemContent = function listItemContent(item) {
|
|
379
|
-
return React.createElement(React.Fragment, null, isMultiselect && React.createElement(Checkbox, {
|
|
380
|
-
"aria-hidden": "true",
|
|
381
|
-
checked: isItemSelected(item),
|
|
382
|
-
className: "eds-dropdown__list__item__checkbox",
|
|
383
|
-
tabIndex: -1,
|
|
384
|
-
onChange: function onChange() {
|
|
385
|
-
return undefined;
|
|
386
|
-
}
|
|
387
|
-
}), React.createElement("span", {
|
|
388
|
-
className: "eds-dropdown__list__item__text"
|
|
389
|
-
}, item.label, React.createElement(VisuallyHidden, null, isItemSelected(item) ? ariaLabelSelectedItem : '')), Array.isArray(item.icons) ? item.icons.filter(isReactComponent).map(function (Icon, index) {
|
|
390
|
-
var _ref2, _Icon$displayName;
|
|
391
|
-
var key = ((_ref2 = (_Icon$displayName = Icon.displayName) != null ? _Icon$displayName : Icon.name) != null ? _ref2 : Icon.name) + "-" + index;
|
|
392
|
-
return React.createElement(Icon, {
|
|
393
|
-
key: key,
|
|
394
|
-
inline: true,
|
|
395
|
-
className: "eds-dropdown__list__item__icon"
|
|
396
|
-
});
|
|
397
|
-
}) : null);
|
|
92
|
+
),
|
|
93
|
+
/* @__PURE__ */ jsxs("span", { className: "eds-dropdown__list__item__text", children: [
|
|
94
|
+
item.label,
|
|
95
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: isItemSelected(item) ? ariaLabelSelectedItem : "" })
|
|
96
|
+
] }),
|
|
97
|
+
Array.isArray(item.icons) ? item.icons.filter(isReactComponent).map((Icon, index) => {
|
|
98
|
+
const key = `${Icon.displayName ?? Icon.name ?? Icon.name}-${index}`;
|
|
99
|
+
return /* @__PURE__ */ jsx(
|
|
100
|
+
Icon,
|
|
101
|
+
{
|
|
102
|
+
inline: true,
|
|
103
|
+
className: "eds-dropdown__list__item__icon"
|
|
104
|
+
},
|
|
105
|
+
key
|
|
106
|
+
);
|
|
107
|
+
}) : null
|
|
108
|
+
] });
|
|
398
109
|
};
|
|
399
110
|
return (
|
|
400
111
|
// use popover from @entur/tooltip when that package upgrades to floating-ui
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
112
|
+
/* @__PURE__ */ jsx(
|
|
113
|
+
"ul",
|
|
114
|
+
{
|
|
115
|
+
...getMenuProps({
|
|
116
|
+
"aria-multiselectable": isMultiselect,
|
|
117
|
+
ref: setListRef,
|
|
118
|
+
className: "eds-dropdown__list",
|
|
119
|
+
style: {
|
|
120
|
+
...floatingStyles,
|
|
121
|
+
display: isOpen && !readOnly ? void 0 : "none",
|
|
122
|
+
...rest.style
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
children: (() => {
|
|
126
|
+
if (!isOpen || readOnly) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
if (loading) {
|
|
130
|
+
return /* @__PURE__ */ jsx(
|
|
131
|
+
"li",
|
|
132
|
+
{
|
|
133
|
+
className: "eds-dropdown__list__item",
|
|
134
|
+
children: loadingText
|
|
135
|
+
},
|
|
136
|
+
"dropdown-list-loading"
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (isNoMatches) {
|
|
140
|
+
return /* @__PURE__ */ jsx(
|
|
141
|
+
"li",
|
|
142
|
+
{
|
|
143
|
+
className: "eds-dropdown__list__item",
|
|
144
|
+
children: noMatchesText
|
|
145
|
+
},
|
|
146
|
+
"dropdown-list-no-match"
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return listItems.map((item, index) => {
|
|
150
|
+
const key = item.itemKey ?? `${item.label ?? ""}-${item.value ?? ""}-${(item.icons ?? []).map((icon) => icon?.displayName ?? icon?.name ?? "unknown").join("-")}`;
|
|
151
|
+
const itemIsSelectAll = item.value === selectAllItem?.value;
|
|
152
|
+
if (itemIsSelectAll && listItems.length <= 2) return null;
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
"li",
|
|
155
|
+
{
|
|
156
|
+
className: classNames("eds-dropdown__list__item", {
|
|
157
|
+
"eds-dropdown__list__item--select-all": itemIsSelectAll,
|
|
158
|
+
"eds-dropdown__list__item--highlighted": highlightedIndex === index,
|
|
159
|
+
"eds-dropdown__list__item--selected": !isMultiselect && isItemSelected(item)
|
|
160
|
+
}),
|
|
161
|
+
...getItemProps({
|
|
162
|
+
// @ts-expect-error Since getItemProps expects the same item type
|
|
163
|
+
// here as items, it throws error when selectAllItem is a string.
|
|
164
|
+
// This does, however, not cause any functional issues.
|
|
165
|
+
item,
|
|
166
|
+
index,
|
|
167
|
+
"aria-selected": itemIsSelectAll ? ariaValuesSelectAll().selected : isItemSelected(item)
|
|
168
|
+
}),
|
|
169
|
+
children: itemIsSelectAll ? selectAllListItemContent() : listItemContent(
|
|
170
|
+
item
|
|
171
|
+
)
|
|
172
|
+
},
|
|
173
|
+
key
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
})()
|
|
423
177
|
}
|
|
424
|
-
|
|
425
|
-
var _item$itemKey, _item$label, _item$value, _item$icons;
|
|
426
|
-
var key = (_item$itemKey = item.itemKey) != null ? _item$itemKey : ((_item$label = item.label) != null ? _item$label : '') + "-" + ((_item$value = item.value) != null ? _item$value : '') + "-" + ((_item$icons = item.icons) != null ? _item$icons : []).map(function (icon) {
|
|
427
|
-
var _ref3, _icon$displayName;
|
|
428
|
-
return (_ref3 = (_icon$displayName = icon == null ? void 0 : icon.displayName) != null ? _icon$displayName : icon == null ? void 0 : icon.name) != null ? _ref3 : 'unknown';
|
|
429
|
-
}).join('-');
|
|
430
|
-
var itemIsSelectAll = item.value === (selectAllItem == null ? void 0 : selectAllItem.value);
|
|
431
|
-
if (itemIsSelectAll && listItems.length <= 2) return null;
|
|
432
|
-
return React.createElement("li", _extends({
|
|
433
|
-
className: classNames('eds-dropdown__list__item', {
|
|
434
|
-
'eds-dropdown__list__item--select-all': itemIsSelectAll,
|
|
435
|
-
'eds-dropdown__list__item--highlighted': highlightedIndex === index,
|
|
436
|
-
'eds-dropdown__list__item--selected': !isMultiselect && isItemSelected(item)
|
|
437
|
-
}),
|
|
438
|
-
key: key
|
|
439
|
-
}, getItemProps({
|
|
440
|
-
// @ts-expect-error Since getItemProps expects the same item type
|
|
441
|
-
// here as items, it throws error when selectAllItem is a string.
|
|
442
|
-
// This does, however, not cause any functional issues.
|
|
443
|
-
item: item,
|
|
444
|
-
index: index,
|
|
445
|
-
'aria-selected': itemIsSelectAll ? ariaValuesSelectAll().selected : isItemSelected(item)
|
|
446
|
-
})), itemIsSelectAll ? selectAllListItemContent() : listItemContent(item));
|
|
447
|
-
});
|
|
448
|
-
}())
|
|
178
|
+
)
|
|
449
179
|
);
|
|
450
180
|
};
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
e.stopPropagation()
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
return e.stopPropagation();
|
|
181
|
+
const SelectedItemTag = ({
|
|
182
|
+
ariaLabelRemoveSelected,
|
|
183
|
+
ariaLabelChosen = "valgt",
|
|
184
|
+
disabled,
|
|
185
|
+
getSelectedItemProps,
|
|
186
|
+
index,
|
|
187
|
+
readOnly,
|
|
188
|
+
removeSelectedItem,
|
|
189
|
+
selectedItem
|
|
190
|
+
}) => {
|
|
191
|
+
const { tabIndex: _, ...selectedItemProps } = getSelectedItemProps?.({
|
|
192
|
+
selectedItem,
|
|
193
|
+
index
|
|
194
|
+
}) ?? {};
|
|
195
|
+
return /* @__PURE__ */ createElement(
|
|
196
|
+
TagChip,
|
|
197
|
+
{
|
|
198
|
+
size: "small",
|
|
199
|
+
className: classNames("eds-dropdown__selected-item-tag", {
|
|
200
|
+
"eds-dropdown__selected-item-tag--readonly": readOnly,
|
|
201
|
+
"eds-dropdown__selected-item-tag--disabled": disabled
|
|
202
|
+
}),
|
|
203
|
+
...selectedItemProps,
|
|
204
|
+
onClose: (e) => {
|
|
205
|
+
e.stopPropagation();
|
|
206
|
+
removeSelectedItem(selectedItem);
|
|
207
|
+
},
|
|
208
|
+
onClick: (e) => e.stopPropagation(),
|
|
209
|
+
closeButtonAriaLabel: `${selectedItem.label} ${ariaLabelChosen}, ${ariaLabelRemoveSelected} `,
|
|
210
|
+
key: selectedItem.value,
|
|
211
|
+
"aria-live": "polite"
|
|
483
212
|
},
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
213
|
+
/* @__PURE__ */ jsx(
|
|
214
|
+
"span",
|
|
215
|
+
{
|
|
216
|
+
"aria-hidden": "true",
|
|
217
|
+
className: "eds-dropdown__selected-item-tag__text",
|
|
218
|
+
children: selectedItem.label
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
);
|
|
491
222
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
clearable =
|
|
497
|
-
labelClearSelected
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
223
|
+
const DropdownFieldAppendix = forwardRef(
|
|
224
|
+
({
|
|
225
|
+
ariaLabelCloseList,
|
|
226
|
+
ariaLabelOpenList,
|
|
227
|
+
clearable = false,
|
|
228
|
+
labelClearSelected,
|
|
229
|
+
focusable = false,
|
|
230
|
+
disabled,
|
|
231
|
+
isOpen,
|
|
232
|
+
loading = false,
|
|
233
|
+
loadingText,
|
|
234
|
+
onClear,
|
|
235
|
+
itemIsSelected,
|
|
236
|
+
...rest
|
|
237
|
+
}, ref) => {
|
|
238
|
+
function getToggleAriaLabel() {
|
|
239
|
+
if (loading) return loadingText;
|
|
240
|
+
if (isOpen) return ariaLabelCloseList;
|
|
241
|
+
return ariaLabelOpenList;
|
|
242
|
+
}
|
|
243
|
+
return /* @__PURE__ */ jsx(Fragment, { children: !disabled && /* @__PURE__ */ jsxs("div", { className: "eds-dropdown__appendix", children: [
|
|
244
|
+
clearable && itemIsSelected && /* @__PURE__ */ jsx(
|
|
245
|
+
ClearableButton,
|
|
246
|
+
{
|
|
247
|
+
onClear,
|
|
248
|
+
focusable: true,
|
|
249
|
+
labelClearSelectedItems: labelClearSelected
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
/* @__PURE__ */ jsx(
|
|
253
|
+
IconButton,
|
|
254
|
+
{
|
|
255
|
+
className: classNames("eds-dropdown__appendix__toggle-button", {
|
|
256
|
+
"eds-dropdown__appendix__toggle-button--open": isOpen
|
|
257
|
+
}),
|
|
258
|
+
ref,
|
|
259
|
+
"aria-label": getToggleAriaLabel(),
|
|
260
|
+
...rest,
|
|
261
|
+
type: "button",
|
|
262
|
+
tabIndex: focusable ? 0 : -1,
|
|
263
|
+
children: !loading ? /* @__PURE__ */ jsx(DownArrowIcon, { "aria-hidden": "true" }) : /* @__PURE__ */ jsx(LoadingDots, { "aria-hidden": "true" })
|
|
264
|
+
}
|
|
265
|
+
)
|
|
266
|
+
] }) });
|
|
512
267
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
tabIndex: focusable ? 0 : -1,
|
|
549
|
-
// These events bubble up to the Dropdown container and trigger openMenu.
|
|
550
|
-
// To avoid this, stopPropagation and preventDefault are added.
|
|
551
|
-
onClick: function onClick(e) {
|
|
552
|
-
e.stopPropagation();
|
|
553
|
-
onClear();
|
|
554
|
-
},
|
|
555
|
-
onKeyDown: function onKeyDown(e) {
|
|
556
|
-
if (e.key === 'Enter' || e.key === ' ') {
|
|
557
|
-
e.preventDefault();
|
|
558
|
-
e.stopPropagation();
|
|
559
|
-
onClear();
|
|
268
|
+
);
|
|
269
|
+
const ClearableButton = ({
|
|
270
|
+
onClear,
|
|
271
|
+
labelClearSelectedItems = "Fjern valgte",
|
|
272
|
+
focusable = false
|
|
273
|
+
}) => {
|
|
274
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
275
|
+
/* @__PURE__ */ jsx(
|
|
276
|
+
Tooltip,
|
|
277
|
+
{
|
|
278
|
+
"aria-hidden": "true",
|
|
279
|
+
placement: "top",
|
|
280
|
+
content: labelClearSelectedItems,
|
|
281
|
+
className: "eds-dropdown__appendix__clear-button__tooltip",
|
|
282
|
+
children: /* @__PURE__ */ jsx(
|
|
283
|
+
IconButton,
|
|
284
|
+
{
|
|
285
|
+
className: "eds-dropdown__appendix__clear-button",
|
|
286
|
+
type: "button",
|
|
287
|
+
tabIndex: focusable ? 0 : -1,
|
|
288
|
+
onClick: (e) => {
|
|
289
|
+
e.stopPropagation();
|
|
290
|
+
onClear();
|
|
291
|
+
},
|
|
292
|
+
onKeyDown: (e) => {
|
|
293
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
294
|
+
e.preventDefault();
|
|
295
|
+
e.stopPropagation();
|
|
296
|
+
onClear();
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
"aria-label": labelClearSelectedItems,
|
|
300
|
+
children: /* @__PURE__ */ jsx(CloseSmallIcon, { "aria-hidden": "true" })
|
|
301
|
+
}
|
|
302
|
+
)
|
|
560
303
|
}
|
|
561
|
-
|
|
562
|
-
"
|
|
563
|
-
}
|
|
564
|
-
"aria-hidden": "true"
|
|
565
|
-
}))), React.createElement("div", {
|
|
566
|
-
className: "eds-dropdown__appendix__divider"
|
|
567
|
-
}));
|
|
304
|
+
),
|
|
305
|
+
/* @__PURE__ */ jsx("div", { className: "eds-dropdown__appendix__divider" })
|
|
306
|
+
] });
|
|
568
307
|
};
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
308
|
+
const useNormalizedItems = (items) => React.useMemo(
|
|
309
|
+
() => items.map((item) => {
|
|
310
|
+
if (typeof item == "string") {
|
|
311
|
+
return {
|
|
312
|
+
value: item,
|
|
313
|
+
label: item
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
if (item?.value === void 0) {
|
|
317
|
+
return {
|
|
318
|
+
...item,
|
|
319
|
+
value: item.label
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return { ...item, value: item.value };
|
|
323
|
+
}),
|
|
324
|
+
[items]
|
|
325
|
+
);
|
|
326
|
+
const useResolvedItems = (itemsOrItemsResolver, debounceTimeout = 250) => {
|
|
327
|
+
const itemsIsAFunction = typeof itemsOrItemsResolver === "function";
|
|
328
|
+
const [items, setItems] = React.useState(
|
|
329
|
+
itemsIsAFunction ? [] : itemsOrItemsResolver
|
|
330
|
+
);
|
|
331
|
+
const [loading, setLoading] = React.useState(false);
|
|
332
|
+
const abortControllerRef = React.useRef(
|
|
333
|
+
new AbortController()
|
|
334
|
+
);
|
|
335
|
+
const itemsResolver = React.useMemo(() => {
|
|
336
|
+
if (itemsIsAFunction)
|
|
337
|
+
return itemsOrItemsResolver;
|
|
338
|
+
return () => Promise.resolve(itemsOrItemsResolver);
|
|
339
|
+
}, [itemsOrItemsResolver, itemsIsAFunction]);
|
|
340
|
+
const updateItems = async (inputValue) => {
|
|
341
|
+
if (abortControllerRef?.current) abortControllerRef?.current?.abort();
|
|
342
|
+
const abortController = new AbortController();
|
|
343
|
+
abortControllerRef.current = abortController;
|
|
344
|
+
setLoading(true);
|
|
345
|
+
try {
|
|
346
|
+
const resolvedItems = await itemsResolver(
|
|
347
|
+
inputValue ?? "",
|
|
348
|
+
abortControllerRef
|
|
349
|
+
);
|
|
350
|
+
if (abortControllerRef?.current?.signal?.aborted) {
|
|
351
|
+
console.warn(
|
|
352
|
+
"Avbryt den asynkrone funksjonen din med signalet fra AbortController-en for å for å unngå minnelekkasje.",
|
|
353
|
+
'Funksjonen bør kaste en DOMException med navnet "AbortError" når den avbrytes.',
|
|
354
|
+
"",
|
|
355
|
+
"\n\nSe eksempel her: https://linje.entur.no/komponenter/skjemaelementer/dropdown#s%C3%B8kbar-dropdown-med-valg-fra-nettverkskall-bassert-p%C3%A5-tekstinput",
|
|
356
|
+
"\nLes mer om AbortController her: https://developer.mozilla.org/en-US/docs/Web/API/AbortController"
|
|
357
|
+
);
|
|
358
|
+
return;
|
|
578
359
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
360
|
+
setLoading(false);
|
|
361
|
+
setItems(resolvedItems);
|
|
362
|
+
} catch (error2) {
|
|
363
|
+
if (error2 && typeof error2 === "object" && "name" in error2 && error2.name === "AbortError") {
|
|
364
|
+
return;
|
|
583
365
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
if (debounceTimeout === void 0) {
|
|
595
|
-
debounceTimeout = 250;
|
|
596
|
-
}
|
|
597
|
-
var itemsIsAFunction = typeof itemsOrItemsResolver === 'function';
|
|
598
|
-
var _React$useState = React.useState(itemsIsAFunction ? [] : itemsOrItemsResolver),
|
|
599
|
-
items = _React$useState[0],
|
|
600
|
-
setItems = _React$useState[1];
|
|
601
|
-
var _React$useState2 = React.useState(false),
|
|
602
|
-
loading = _React$useState2[0],
|
|
603
|
-
setLoading = _React$useState2[1];
|
|
604
|
-
var abortControllerRef = React.useRef(new AbortController());
|
|
605
|
-
// We normalize the itemsResolver argument to an async function, so we
|
|
606
|
-
// can use it without thinking about the differences later
|
|
607
|
-
var itemsResolver = React.useMemo(function () {
|
|
608
|
-
if (itemsIsAFunction) return itemsOrItemsResolver;
|
|
609
|
-
return function () {
|
|
610
|
-
return Promise.resolve(itemsOrItemsResolver);
|
|
611
|
-
};
|
|
612
|
-
}, [itemsOrItemsResolver, itemsIsAFunction]);
|
|
613
|
-
// This should be called whenever the input value changes
|
|
614
|
-
var updateItems = /*#__PURE__*/function () {
|
|
615
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(inputValue) {
|
|
616
|
-
var _abortControllerRef$c;
|
|
617
|
-
var abortController, _abortControllerRef$c2, resolvedItems;
|
|
618
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
619
|
-
while (1) switch (_context.prev = _context.next) {
|
|
620
|
-
case 0:
|
|
621
|
-
// The abortController handles cleanup of the previous request and unmounting
|
|
622
|
-
if (abortControllerRef != null && abortControllerRef.current) abortControllerRef == null || (_abortControllerRef$c = abortControllerRef.current) == null || _abortControllerRef$c.abort();
|
|
623
|
-
abortController = new AbortController();
|
|
624
|
-
abortControllerRef.current = abortController;
|
|
625
|
-
setLoading(true);
|
|
626
|
-
_context.prev = 4;
|
|
627
|
-
_context.next = 7;
|
|
628
|
-
return itemsResolver(inputValue != null ? inputValue : '', abortControllerRef);
|
|
629
|
-
case 7:
|
|
630
|
-
resolvedItems = _context.sent;
|
|
631
|
-
if (!(abortControllerRef != null && (_abortControllerRef$c2 = abortControllerRef.current) != null && (_abortControllerRef$c2 = _abortControllerRef$c2.signal) != null && _abortControllerRef$c2.aborted)) {
|
|
632
|
-
_context.next = 11;
|
|
633
|
-
break;
|
|
634
|
-
}
|
|
635
|
-
console.warn('Avbryt den asynkrone funksjonen din med signalet fra AbortController-en for å for å unngå minnelekkasje.', 'Funksjonen bør kaste en DOMException med navnet "AbortError" når den avbrytes.', '', '\n\nSe eksempel her: https://linje.entur.no/komponenter/skjemaelementer/dropdown#s%C3%B8kbar-dropdown-med-valg-fra-nettverkskall-bassert-p%C3%A5-tekstinput', '\nLes mer om AbortController her: https://developer.mozilla.org/en-US/docs/Web/API/AbortController');
|
|
636
|
-
return _context.abrupt("return");
|
|
637
|
-
case 11:
|
|
638
|
-
setLoading(false);
|
|
639
|
-
setItems(resolvedItems);
|
|
640
|
-
_context.next = 21;
|
|
641
|
-
break;
|
|
642
|
-
case 15:
|
|
643
|
-
_context.prev = 15;
|
|
644
|
-
_context.t0 = _context["catch"](4);
|
|
645
|
-
if (!(_context.t0 && typeof _context.t0 === 'object' && 'name' in _context.t0 && _context.t0.name === 'AbortError')) {
|
|
646
|
-
_context.next = 19;
|
|
647
|
-
break;
|
|
648
|
-
}
|
|
649
|
-
return _context.abrupt("return");
|
|
650
|
-
case 19:
|
|
651
|
-
console.warn('The following error was received but not handled inside Entur Designsystems useResolvedItems hook:');
|
|
652
|
-
throw _context.t0;
|
|
653
|
-
case 21:
|
|
654
|
-
case "end":
|
|
655
|
-
return _context.stop();
|
|
656
|
-
}
|
|
657
|
-
}, _callee, null, [[4, 15]]);
|
|
658
|
-
}));
|
|
659
|
-
return function updateItems(_x) {
|
|
660
|
-
return _ref.apply(this, arguments);
|
|
661
|
-
};
|
|
662
|
-
}();
|
|
663
|
-
var debouncedFetchItems = useDebounce(updateItems, debounceTimeout);
|
|
664
|
-
var normalizedItems = useNormalizedItems(items);
|
|
665
|
-
React.useEffect(function () {
|
|
666
|
-
// send abort signal to previous request on unmount for cleanup
|
|
667
|
-
return function () {
|
|
668
|
-
var _abortControllerRef$c3;
|
|
669
|
-
return abortControllerRef == null || (_abortControllerRef$c3 = abortControllerRef.current) == null ? void 0 : _abortControllerRef$c3.abort('Component unmounted');
|
|
670
|
-
};
|
|
366
|
+
console.warn(
|
|
367
|
+
"The following error was received but not handled inside Entur Designsystems useResolvedItems hook:"
|
|
368
|
+
);
|
|
369
|
+
throw error2;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const debouncedFetchItems = useDebounce(updateItems, debounceTimeout);
|
|
373
|
+
const normalizedItems = useNormalizedItems(items);
|
|
374
|
+
React.useEffect(() => {
|
|
375
|
+
return () => abortControllerRef?.current?.abort("Component unmounted");
|
|
671
376
|
}, []);
|
|
672
|
-
React.useEffect(
|
|
673
|
-
// Let's fetch the list initially if it's specified
|
|
377
|
+
React.useEffect(() => {
|
|
674
378
|
if (itemsIsAFunction) {
|
|
675
|
-
debouncedFetchItems(
|
|
379
|
+
debouncedFetchItems("");
|
|
676
380
|
}
|
|
677
381
|
}, [itemsIsAFunction, itemsResolver]);
|
|
678
382
|
return {
|
|
@@ -681,79 +385,56 @@ debounceTimeout) {
|
|
|
681
385
|
fetchItems: debouncedFetchItems
|
|
682
386
|
};
|
|
683
387
|
};
|
|
684
|
-
|
|
685
|
-
/* start general utils */
|
|
686
|
-
var EMPTY_INPUT = '';
|
|
388
|
+
const EMPTY_INPUT = "";
|
|
687
389
|
function lowerCaseFilterTest(item, input) {
|
|
688
390
|
if (!input) {
|
|
689
391
|
return true;
|
|
690
392
|
}
|
|
691
|
-
|
|
692
|
-
|
|
393
|
+
const sanitizeEscapeCharacters = input.replace(
|
|
394
|
+
/[-/\\^$*+?.()|[\]{}]/g,
|
|
395
|
+
"\\$&"
|
|
396
|
+
);
|
|
397
|
+
const inputRegex = new RegExp(sanitizeEscapeCharacters, "i");
|
|
693
398
|
return inputRegex.test(item.label);
|
|
694
399
|
}
|
|
695
|
-
function noFilter(
|
|
696
|
-
//@ts-expect-error only here to comply with dropdown filter API
|
|
697
|
-
item,
|
|
698
|
-
//@ts-expect-error only here to comply with dropdown filter API
|
|
699
|
-
input) {
|
|
400
|
+
function noFilter(item, input) {
|
|
700
401
|
return true;
|
|
701
402
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
});
|
|
738
|
-
var someListItemsAreSelected = listItemsWithoutSelectAll.some(function (listItem) {
|
|
739
|
-
return selectedItems.some(function (selectedItem) {
|
|
740
|
-
return selectedItem.value === listItem.value;
|
|
741
|
-
});
|
|
742
|
-
});
|
|
743
|
-
var addClickedItemToSelectedItems = function addClickedItemToSelectedItems(clickedItem, onChange) {
|
|
744
|
-
return onChange([].concat(selectedItems, [clickedItem]));
|
|
745
|
-
};
|
|
746
|
-
var clickedItemIsInSelectedItems = function clickedItemIsInSelectedItems(clickedItem) {
|
|
747
|
-
return selectedItems.some(function (selectedItem) {
|
|
748
|
-
return selectedItem.value === clickedItem.value;
|
|
749
|
-
});
|
|
750
|
-
};
|
|
751
|
-
var clickedItemIsSelectAll = function clickedItemIsSelectAll(clickedItem) {
|
|
752
|
-
return clickedItem.value === selectAll.value;
|
|
753
|
-
};
|
|
754
|
-
var handleListItemClicked = function handleListItemClicked(_ref2) {
|
|
755
|
-
var clickedItem = _ref2.clickedItem,
|
|
756
|
-
onChange = _ref2.onChange;
|
|
403
|
+
const itemToString = (item) => item ? item.label : "";
|
|
404
|
+
const itemToKey = (item) => item?.label + item?.value;
|
|
405
|
+
const isFunctionWithQueryArgument = (object) => typeof object === "function" && object.length > 0;
|
|
406
|
+
const clamp = (val, min = 1, max = 10) => Math.min(Math.max(val, min), max);
|
|
407
|
+
const useMultiselectUtils = ({
|
|
408
|
+
listItems,
|
|
409
|
+
selectedItems,
|
|
410
|
+
selectAll
|
|
411
|
+
}) => {
|
|
412
|
+
const hasSelectedItems = selectedItems.length > 0;
|
|
413
|
+
const listItemsWithoutSelectAll = listItems.filter(
|
|
414
|
+
(item) => item.value !== selectAll.value
|
|
415
|
+
);
|
|
416
|
+
const unselectedItemsInListItems = listItemsWithoutSelectAll.filter(
|
|
417
|
+
(listItem) => !selectedItems.some(
|
|
418
|
+
(selectedItem) => selectedItem.value === listItem.value
|
|
419
|
+
)
|
|
420
|
+
);
|
|
421
|
+
const allListItemsAreSelected = !listItemsWithoutSelectAll.some(
|
|
422
|
+
(listItem) => !selectedItems.some(
|
|
423
|
+
(selectedItem) => selectedItem.value === listItem.value
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
const someListItemsAreSelected = listItemsWithoutSelectAll.some(
|
|
427
|
+
(listItem) => selectedItems.some((selectedItem) => selectedItem.value === listItem.value)
|
|
428
|
+
);
|
|
429
|
+
const addClickedItemToSelectedItems = (clickedItem, onChange) => onChange([...selectedItems, clickedItem]);
|
|
430
|
+
const clickedItemIsInSelectedItems = (clickedItem) => selectedItems.some(
|
|
431
|
+
(selectedItem) => selectedItem.value === clickedItem.value
|
|
432
|
+
);
|
|
433
|
+
const clickedItemIsSelectAll = (clickedItem) => clickedItem.value === selectAll.value;
|
|
434
|
+
const handleListItemClicked = ({
|
|
435
|
+
clickedItem,
|
|
436
|
+
onChange
|
|
437
|
+
}) => {
|
|
757
438
|
if (clickedItemIsSelectAll(clickedItem)) {
|
|
758
439
|
if (allListItemsAreSelected) {
|
|
759
440
|
return unselectAllListItems(onChange);
|
|
@@ -765,1054 +446,1020 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
765
446
|
}
|
|
766
447
|
addClickedItemToSelectedItems(clickedItem, onChange);
|
|
767
448
|
};
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
449
|
+
const removeClickedItemFromSelectedItems = (clickedItem, onChange) => onChange(
|
|
450
|
+
selectedItems.filter(
|
|
451
|
+
(selectedItem) => selectedItem.value !== clickedItem.value
|
|
452
|
+
)
|
|
453
|
+
);
|
|
454
|
+
const selectAllCheckboxState = () => {
|
|
774
455
|
if (allListItemsAreSelected) return true;
|
|
775
|
-
if (someListItemsAreSelected) return
|
|
456
|
+
if (someListItemsAreSelected) return "indeterminate";
|
|
776
457
|
return false;
|
|
777
458
|
};
|
|
778
|
-
|
|
779
|
-
onChange([
|
|
459
|
+
const selectAllUnselectedItemsInListItems = (onChange) => {
|
|
460
|
+
onChange([...selectedItems, ...unselectedItemsInListItems]);
|
|
780
461
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
462
|
+
const unselectAllListItems = (onChange) => {
|
|
463
|
+
const selectedItemsWithoutItemsInListItems = selectedItems.filter(
|
|
464
|
+
(selectedItem) => !listItemsWithoutSelectAll.some(
|
|
465
|
+
(listItem) => listItem.value === selectedItem.value
|
|
466
|
+
)
|
|
467
|
+
);
|
|
787
468
|
onChange(selectedItemsWithoutItemsInListItems);
|
|
788
469
|
};
|
|
789
470
|
return {
|
|
790
|
-
addClickedItemToSelectedItems
|
|
791
|
-
allListItemsAreSelected
|
|
792
|
-
clickedItemIsInSelectedItems
|
|
793
|
-
clickedItemIsSelectAll
|
|
794
|
-
handleListItemClicked
|
|
795
|
-
hasSelectedItems
|
|
796
|
-
listItemsWithoutSelectAll
|
|
797
|
-
removeClickedItemFromSelectedItems
|
|
798
|
-
selectAllCheckboxState
|
|
799
|
-
selectAllUnselectedItemsInListItems
|
|
800
|
-
someListItemsAreSelected
|
|
801
|
-
unselectAllListItems
|
|
471
|
+
addClickedItemToSelectedItems,
|
|
472
|
+
allListItemsAreSelected,
|
|
473
|
+
clickedItemIsInSelectedItems,
|
|
474
|
+
clickedItemIsSelectAll,
|
|
475
|
+
handleListItemClicked,
|
|
476
|
+
hasSelectedItems,
|
|
477
|
+
listItemsWithoutSelectAll,
|
|
478
|
+
removeClickedItemFromSelectedItems,
|
|
479
|
+
selectAllCheckboxState,
|
|
480
|
+
selectAllUnselectedItemsInListItems,
|
|
481
|
+
someListItemsAreSelected,
|
|
482
|
+
unselectAllListItems
|
|
802
483
|
};
|
|
803
484
|
};
|
|
804
|
-
/* end multiselect utils */
|
|
805
|
-
/* start a11y utils */
|
|
806
|
-
// called when the state changes:
|
|
807
|
-
// selectedItem, highlightedIndex, inputValue or isOpen.
|
|
808
485
|
function getA11yStatusMessage(options) {
|
|
809
|
-
|
|
810
|
-
_options$selectAllIte = options.selectAllItemIncluded,
|
|
811
|
-
selectAllItemIncluded = _options$selectAllIte === void 0 ? false : _options$selectAllIte,
|
|
812
|
-
resultCount = options.resultCount;
|
|
486
|
+
const { isOpen, selectAllItemIncluded = false, resultCount } = options;
|
|
813
487
|
if (!isOpen) {
|
|
814
|
-
return
|
|
488
|
+
return "";
|
|
815
489
|
}
|
|
816
|
-
|
|
490
|
+
const resultCountWithoutSelectAll = selectAllItemIncluded ? resultCount - 1 : resultCount;
|
|
817
491
|
if (resultCountWithoutSelectAll === 0) {
|
|
818
|
-
return
|
|
492
|
+
return "Ingen resultater";
|
|
819
493
|
}
|
|
820
|
-
return resultCountWithoutSelectAll
|
|
494
|
+
return `${resultCountWithoutSelectAll} resultat${resultCountWithoutSelectAll === 1 ? "" : "er"} tilgjengelig, naviger med pil opp eller ned, velg elementer med Enter.`;
|
|
821
495
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
setLastHighlightedIndex = _useState2[1];
|
|
878
|
-
var inputRef = useRef(null);
|
|
879
|
-
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
880
|
-
normalizedItems = _useResolvedItems.items,
|
|
881
|
-
resolvedItemsLoading = _useResolvedItems.loading,
|
|
882
|
-
fetchItems = _useResolvedItems.fetchItems;
|
|
883
|
-
var _useState3 = useState(normalizedItems),
|
|
884
|
-
listItems = _useState3[0],
|
|
885
|
-
setListItems = _useState3[1];
|
|
886
|
-
var filterListItems = function filterListItems(_ref2) {
|
|
887
|
-
var inputValue = _ref2.inputValue;
|
|
888
|
-
return setListItems(normalizedItems.filter(function (item) {
|
|
889
|
-
return itemFilter(item, inputValue);
|
|
890
|
-
}));
|
|
891
|
-
};
|
|
892
|
-
var updateListItems = function updateListItems(_ref3) {
|
|
893
|
-
var inputValue = _ref3.inputValue;
|
|
894
|
-
var shouldRefetchItems = isFunctionWithQueryArgument(initialItems);
|
|
895
|
-
if (shouldRefetchItems) fetchItems(inputValue != null ? inputValue : EMPTY_INPUT);
|
|
896
|
-
filterListItems({
|
|
897
|
-
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
898
|
-
});
|
|
899
|
-
};
|
|
900
|
-
var resetInputState = function resetInputState(_ref4) {
|
|
901
|
-
var changes = _ref4.changes;
|
|
902
|
-
updateListItems({
|
|
903
|
-
inputValue: EMPTY_INPUT
|
|
904
|
-
});
|
|
905
|
-
return _extends({}, changes, {
|
|
906
|
-
inputValue: EMPTY_INPUT
|
|
907
|
-
});
|
|
908
|
-
};
|
|
909
|
-
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
910
|
-
useEffect(function () {
|
|
911
|
-
filterListItems({
|
|
912
|
-
inputValue: inputValue
|
|
913
|
-
});
|
|
914
|
-
}, [normalizedItems]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
915
|
-
useEffect(function () {
|
|
916
|
-
// sync internal state on initial render
|
|
917
|
-
if (selectedItem !== null && !inputHasFocus) {
|
|
918
|
-
setShowSelectedItem(true);
|
|
919
|
-
updateListItems({
|
|
496
|
+
const SearchableDropdown = React.forwardRef(
|
|
497
|
+
({
|
|
498
|
+
ariaLabelChosenSingular,
|
|
499
|
+
ariaLabelCloseList = "Lukk liste med valg",
|
|
500
|
+
ariaLabelOpenList = "Åpne liste med valg",
|
|
501
|
+
ariaLabelSelectedItem,
|
|
502
|
+
className,
|
|
503
|
+
clearable = true,
|
|
504
|
+
debounceTimeout,
|
|
505
|
+
disabled = false,
|
|
506
|
+
disableLabelAnimation = false,
|
|
507
|
+
feedback,
|
|
508
|
+
items: initialItems,
|
|
509
|
+
itemFilter = isFunctionWithQueryArgument(initialItems) ? noFilter : lowerCaseFilterTest,
|
|
510
|
+
label,
|
|
511
|
+
labelClearSelectedItem = "fjern valgt",
|
|
512
|
+
labelTooltip,
|
|
513
|
+
listStyle,
|
|
514
|
+
loading,
|
|
515
|
+
loadingText = "Laster resultater …",
|
|
516
|
+
noMatchesText = "Ingen tilgjengelige valg …",
|
|
517
|
+
onChange = () => void 0,
|
|
518
|
+
placeholder,
|
|
519
|
+
prepend,
|
|
520
|
+
readOnly = false,
|
|
521
|
+
selectedItem: value,
|
|
522
|
+
selectOnBlur = false,
|
|
523
|
+
selectOnTab = false,
|
|
524
|
+
style,
|
|
525
|
+
variant = "info",
|
|
526
|
+
...rest
|
|
527
|
+
}, ref) => {
|
|
528
|
+
const [showSelectedItem, setShowSelectedItem] = useState(value !== null);
|
|
529
|
+
const [lastHighlightedIndex, setLastHighlightedIndex] = useState(0);
|
|
530
|
+
const inputRef = useRef(null);
|
|
531
|
+
const {
|
|
532
|
+
items: normalizedItems,
|
|
533
|
+
loading: resolvedItemsLoading,
|
|
534
|
+
fetchItems
|
|
535
|
+
} = useResolvedItems(initialItems, debounceTimeout);
|
|
536
|
+
const [listItems, setListItems] = useState(normalizedItems);
|
|
537
|
+
const filterListItems = ({ inputValue: inputValue2 }) => setListItems(
|
|
538
|
+
normalizedItems.filter((item) => itemFilter(item, inputValue2))
|
|
539
|
+
);
|
|
540
|
+
const updateListItems = ({ inputValue: inputValue2 }) => {
|
|
541
|
+
const shouldRefetchItems = isFunctionWithQueryArgument(initialItems);
|
|
542
|
+
if (shouldRefetchItems) fetchItems(inputValue2 ?? EMPTY_INPUT);
|
|
543
|
+
filterListItems({ inputValue: inputValue2 ?? EMPTY_INPUT });
|
|
544
|
+
};
|
|
545
|
+
const resetInputState = ({
|
|
546
|
+
changes
|
|
547
|
+
}) => {
|
|
548
|
+
updateListItems({ inputValue: EMPTY_INPUT });
|
|
549
|
+
return {
|
|
550
|
+
...changes,
|
|
920
551
|
inputValue: EMPTY_INPUT
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
552
|
+
};
|
|
553
|
+
};
|
|
554
|
+
const inputHasFocus = typeof document !== "undefined" ? inputRef?.current === document?.activeElement : false;
|
|
555
|
+
useEffect(() => {
|
|
556
|
+
filterListItems({ inputValue });
|
|
557
|
+
}, [normalizedItems]);
|
|
558
|
+
useEffect(() => {
|
|
559
|
+
if (selectedItem !== null && !inputHasFocus) {
|
|
560
|
+
setShowSelectedItem(true);
|
|
561
|
+
updateListItems({ inputValue: EMPTY_INPUT });
|
|
562
|
+
setInputValue(EMPTY_INPUT);
|
|
563
|
+
}
|
|
564
|
+
}, []);
|
|
565
|
+
const stateReducer = useCallback(
|
|
566
|
+
(state, {
|
|
567
|
+
type,
|
|
568
|
+
changes
|
|
569
|
+
}) => {
|
|
570
|
+
if (changes.highlightedIndex !== void 0 && changes?.highlightedIndex >= 0) {
|
|
571
|
+
setLastHighlightedIndex(changes?.highlightedIndex);
|
|
572
|
+
}
|
|
573
|
+
switch (type) {
|
|
574
|
+
// empty input to show selected item and reset dropdown list on item selection
|
|
575
|
+
case useCombobox.stateChangeTypes.ItemClick:
|
|
576
|
+
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
577
|
+
case useCombobox.stateChangeTypes.InputBlur:
|
|
578
|
+
return resetInputState({ changes });
|
|
579
|
+
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
580
|
+
if (changes.selectedItem !== null && !inputHasFocus)
|
|
581
|
+
setShowSelectedItem(true);
|
|
582
|
+
return resetInputState({ changes });
|
|
583
|
+
// remove leading whitespace, select element with spacebar on empty input
|
|
584
|
+
case useCombobox.stateChangeTypes.InputChange: {
|
|
585
|
+
const leadingWhitespaceTest = /^\s+/g;
|
|
586
|
+
const isSpacePressedOnEmptyInput = changes.inputValue === " ";
|
|
587
|
+
if (!isSpacePressedOnEmptyInput) setLastHighlightedIndex(0);
|
|
588
|
+
if (changes.inputValue?.match(leadingWhitespaceTest)) {
|
|
589
|
+
const sanitizedInputValue = changes.inputValue.replace(
|
|
590
|
+
leadingWhitespaceTest,
|
|
591
|
+
EMPTY_INPUT
|
|
592
|
+
);
|
|
593
|
+
if (isSpacePressedOnEmptyInput) {
|
|
594
|
+
if (!state.isOpen)
|
|
595
|
+
return {
|
|
596
|
+
...changes,
|
|
597
|
+
inputValue: sanitizedInputValue,
|
|
598
|
+
isOpen: true
|
|
599
|
+
};
|
|
600
|
+
if (changes.highlightedIndex !== void 0) {
|
|
601
|
+
return {
|
|
602
|
+
...changes,
|
|
603
|
+
inputValue: sanitizedInputValue,
|
|
604
|
+
selectedItem: listItems[changes.highlightedIndex]
|
|
605
|
+
};
|
|
606
|
+
}
|
|
963
607
|
}
|
|
964
608
|
}
|
|
609
|
+
return { ...changes, highlightedIndex: 0 };
|
|
965
610
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
});
|
|
611
|
+
default:
|
|
612
|
+
return changes;
|
|
969
613
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
614
|
+
},
|
|
615
|
+
[fetchItems, filterListItems, inputHasFocus, resetInputState]
|
|
616
|
+
);
|
|
617
|
+
const {
|
|
618
|
+
isOpen,
|
|
619
|
+
getToggleButtonProps,
|
|
620
|
+
getLabelProps,
|
|
621
|
+
getMenuProps,
|
|
622
|
+
getInputProps,
|
|
623
|
+
highlightedIndex,
|
|
624
|
+
getItemProps,
|
|
625
|
+
selectedItem,
|
|
626
|
+
inputValue,
|
|
627
|
+
setInputValue,
|
|
628
|
+
selectItem,
|
|
629
|
+
reset
|
|
630
|
+
} = useCombobox({
|
|
975
631
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
976
632
|
items: listItems,
|
|
977
|
-
itemToString
|
|
633
|
+
itemToString,
|
|
978
634
|
selectedItem: value,
|
|
979
|
-
stateReducer
|
|
980
|
-
onInputValueChange
|
|
981
|
-
updateListItems({
|
|
982
|
-
inputValue: changes.inputValue
|
|
983
|
-
});
|
|
635
|
+
stateReducer,
|
|
636
|
+
onInputValueChange(changes) {
|
|
637
|
+
updateListItems({ inputValue: changes.inputValue });
|
|
984
638
|
},
|
|
985
|
-
onSelectedItemChange:
|
|
986
|
-
var newSelectedItem = _ref6.selectedItem;
|
|
639
|
+
onSelectedItemChange({ selectedItem: newSelectedItem }) {
|
|
987
640
|
onChange(newSelectedItem);
|
|
988
641
|
},
|
|
989
642
|
// Accessibility
|
|
990
|
-
getA11yStatusMessage:
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}));
|
|
994
|
-
}
|
|
995
|
-
}),
|
|
996
|
-
isOpen = _useCombobox.isOpen,
|
|
997
|
-
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
998
|
-
getLabelProps = _useCombobox.getLabelProps,
|
|
999
|
-
getMenuProps = _useCombobox.getMenuProps,
|
|
1000
|
-
getInputProps = _useCombobox.getInputProps,
|
|
1001
|
-
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1002
|
-
getItemProps = _useCombobox.getItemProps,
|
|
1003
|
-
selectedItem = _useCombobox.selectedItem,
|
|
1004
|
-
inputValue = _useCombobox.inputValue,
|
|
1005
|
-
setInputValue = _useCombobox.setInputValue,
|
|
1006
|
-
selectItem = _useCombobox.selectItem,
|
|
1007
|
-
reset = _useCombobox.reset;
|
|
1008
|
-
// calculations for floating-UI popover position
|
|
1009
|
-
var _useFloating = useFloating({
|
|
643
|
+
getA11yStatusMessage: (options) => getA11yStatusMessage({ ...options, resultCount: listItems.length })
|
|
644
|
+
});
|
|
645
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
1010
646
|
open: isOpen,
|
|
1011
|
-
placement:
|
|
1012
|
-
middleware: [
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
elements
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1036
|
-
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1037
|
-
useEffect(function () {
|
|
1038
|
-
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1039
|
-
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1040
|
-
}
|
|
1041
|
-
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1042
|
-
var handleOnClear = function handleOnClear() {
|
|
1043
|
-
var _inputRef$current;
|
|
1044
|
-
(_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
|
|
1045
|
-
reset();
|
|
1046
|
-
};
|
|
1047
|
-
return React.createElement(BaseFormControl, _extends({
|
|
1048
|
-
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
1049
|
-
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1050
|
-
}),
|
|
1051
|
-
disabled: disabled,
|
|
1052
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
1053
|
-
feedback: feedback,
|
|
1054
|
-
isFilled: selectedItem !== null || inputValue !== EMPTY_INPUT,
|
|
1055
|
-
label: label,
|
|
1056
|
-
labelId: getLabelProps().id,
|
|
1057
|
-
labelProps: getLabelProps(),
|
|
1058
|
-
labelTooltip: labelTooltip,
|
|
1059
|
-
onClick: function onClick(e) {
|
|
1060
|
-
if (e.target === e.currentTarget) {
|
|
1061
|
-
var _getInputProps;
|
|
1062
|
-
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1063
|
-
}
|
|
1064
|
-
},
|
|
1065
|
-
prepend: prepend,
|
|
1066
|
-
readOnly: readOnly,
|
|
1067
|
-
ref: refs.setReference,
|
|
1068
|
-
style: style,
|
|
1069
|
-
tabIndex: disabled || readOnly ? -1 : undefined,
|
|
1070
|
-
variant: variant,
|
|
1071
|
-
after: React.createElement(DropdownList, {
|
|
1072
|
-
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1073
|
-
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1074
|
-
floatingStyles: floatingStyles,
|
|
1075
|
-
getItemProps: getItemProps,
|
|
1076
|
-
getMenuProps: getMenuProps,
|
|
1077
|
-
highlightedIndex: highlightedIndex,
|
|
1078
|
-
isOpen: isOpen,
|
|
1079
|
-
listItems: listItems,
|
|
1080
|
-
style: listStyle,
|
|
1081
|
-
setListRef: refs.setFloating,
|
|
1082
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1083
|
-
loadingText: loadingText,
|
|
1084
|
-
noMatchesText: noMatchesText,
|
|
1085
|
-
selectedItems: selectedItem !== null ? [selectedItem] : [],
|
|
1086
|
-
readOnly: readOnly
|
|
1087
|
-
})
|
|
1088
|
-
}, rest, {
|
|
1089
|
-
// Append is not supported as of now
|
|
1090
|
-
append: undefined
|
|
1091
|
-
}), React.createElement("span", {
|
|
1092
|
-
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1093
|
-
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1094
|
-
}),
|
|
1095
|
-
onClick: function onClick(event) {
|
|
1096
|
-
if (!disabled && !readOnly) {
|
|
1097
|
-
var _inputRef$current2, _getInputProps2;
|
|
1098
|
-
(_inputRef$current2 = inputRef.current) == null || _inputRef$current2.focus();
|
|
1099
|
-
(_getInputProps2 = getInputProps()) == null || _getInputProps2.onClick == null || _getInputProps2.onClick(event);
|
|
1100
|
-
}
|
|
1101
|
-
},
|
|
1102
|
-
tabIndex: readOnly ? 0 : -1
|
|
1103
|
-
}, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
|
|
1104
|
-
className: classNames('eds-dropdown__input eds-form-control', {
|
|
1105
|
-
'eds-dropdown__input--hidden': showSelectedItem
|
|
1106
|
-
})
|
|
1107
|
-
}, getInputProps({
|
|
1108
|
-
onKeyDown: function onKeyDown(e) {
|
|
1109
|
-
if (isOpen && e.key === 'Tab') {
|
|
1110
|
-
var highlitedItem = listItems[highlightedIndex];
|
|
1111
|
-
// we don't want to clear selection with tab
|
|
1112
|
-
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1113
|
-
selectItem(highlitedItem);
|
|
1114
|
-
}
|
|
647
|
+
placement: "bottom-start",
|
|
648
|
+
middleware: [
|
|
649
|
+
offset(space.extraSmall2),
|
|
650
|
+
shift({ padding: space.extraSmall }),
|
|
651
|
+
size({
|
|
652
|
+
apply({ rects, elements, availableHeight }) {
|
|
653
|
+
Object.assign(elements.floating.style, {
|
|
654
|
+
width: `${rects.reference.width}px`,
|
|
655
|
+
// Floating will flip when smaller than 10*16 px
|
|
656
|
+
// and never exceed 20*16 px.
|
|
657
|
+
maxHeight: `${clamp(10 * 16, availableHeight, 20 * 16)}px`
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}),
|
|
661
|
+
flip({ fallbackStrategy: "initialPlacement" })
|
|
662
|
+
]
|
|
663
|
+
});
|
|
664
|
+
useEffect(() => {
|
|
665
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
666
|
+
return autoUpdate(
|
|
667
|
+
refs.reference.current,
|
|
668
|
+
refs.floating.current,
|
|
669
|
+
update
|
|
670
|
+
);
|
|
1115
671
|
}
|
|
1116
|
-
},
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
672
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
673
|
+
const handleOnClear = () => {
|
|
674
|
+
inputRef.current?.focus();
|
|
675
|
+
reset();
|
|
676
|
+
};
|
|
677
|
+
return /* @__PURE__ */ jsxs(
|
|
678
|
+
BaseFormControl,
|
|
679
|
+
{
|
|
680
|
+
className: classNames(
|
|
681
|
+
"eds-dropdown",
|
|
682
|
+
"eds-dropdown--searchable",
|
|
683
|
+
className,
|
|
684
|
+
{ "eds-dropdown--has-tooltip": labelTooltip !== void 0 }
|
|
685
|
+
),
|
|
686
|
+
disabled,
|
|
687
|
+
disableLabelAnimation,
|
|
688
|
+
feedback,
|
|
689
|
+
isFilled: selectedItem !== null || inputValue !== EMPTY_INPUT,
|
|
690
|
+
label,
|
|
691
|
+
labelId: getLabelProps().id,
|
|
692
|
+
labelProps: getLabelProps(),
|
|
693
|
+
labelTooltip,
|
|
694
|
+
onClick: (e) => {
|
|
695
|
+
if (e.target === e.currentTarget) {
|
|
696
|
+
getInputProps()?.onClick?.(e);
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
prepend,
|
|
700
|
+
readOnly,
|
|
701
|
+
ref: refs.setReference,
|
|
702
|
+
style,
|
|
703
|
+
tabIndex: disabled || readOnly ? -1 : void 0,
|
|
704
|
+
variant,
|
|
705
|
+
after: /* @__PURE__ */ jsx(
|
|
706
|
+
DropdownList,
|
|
707
|
+
{
|
|
708
|
+
ariaLabelChosenSingular,
|
|
709
|
+
ariaLabelSelectedItem,
|
|
710
|
+
floatingStyles,
|
|
711
|
+
getItemProps,
|
|
712
|
+
getMenuProps,
|
|
713
|
+
highlightedIndex,
|
|
714
|
+
isOpen,
|
|
715
|
+
listItems,
|
|
716
|
+
style: listStyle,
|
|
717
|
+
setListRef: refs.setFloating,
|
|
718
|
+
loading: loading ?? resolvedItemsLoading,
|
|
719
|
+
loadingText,
|
|
720
|
+
noMatchesText,
|
|
721
|
+
selectedItems: selectedItem !== null ? [selectedItem] : [],
|
|
722
|
+
readOnly
|
|
723
|
+
}
|
|
724
|
+
),
|
|
725
|
+
...rest,
|
|
726
|
+
append: void 0,
|
|
727
|
+
children: [
|
|
728
|
+
/* @__PURE__ */ jsx(
|
|
729
|
+
"span",
|
|
730
|
+
{
|
|
731
|
+
className: classNames("eds-dropdown--searchable__selected-item", {
|
|
732
|
+
"eds-dropdown--searchable__selected-item--hidden": !showSelectedItem
|
|
733
|
+
}),
|
|
734
|
+
onClick: (event) => {
|
|
735
|
+
if (!disabled && !readOnly) {
|
|
736
|
+
inputRef.current?.focus();
|
|
737
|
+
getInputProps()?.onClick?.(event);
|
|
738
|
+
}
|
|
739
|
+
},
|
|
740
|
+
tabIndex: readOnly ? 0 : -1,
|
|
741
|
+
children: showSelectedItem ? selectedItem?.label : ""
|
|
742
|
+
}
|
|
743
|
+
),
|
|
744
|
+
/* @__PURE__ */ jsx(
|
|
745
|
+
"input",
|
|
746
|
+
{
|
|
747
|
+
className: classNames("eds-dropdown__input eds-form-control", {
|
|
748
|
+
"eds-dropdown__input--hidden": showSelectedItem
|
|
749
|
+
}),
|
|
750
|
+
...getInputProps({
|
|
751
|
+
onKeyDown(e) {
|
|
752
|
+
if (isOpen && e.key === "Tab") {
|
|
753
|
+
const highlitedItem = listItems[highlightedIndex];
|
|
754
|
+
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
755
|
+
selectItem(highlitedItem);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
},
|
|
759
|
+
onBlur() {
|
|
760
|
+
if (selectedItem !== null) setShowSelectedItem(true);
|
|
761
|
+
},
|
|
762
|
+
onFocus() {
|
|
763
|
+
if (!readOnly) {
|
|
764
|
+
setShowSelectedItem(false);
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
disabled,
|
|
768
|
+
readOnly,
|
|
769
|
+
placeholder: selectedItem?.label ?? placeholder,
|
|
770
|
+
tabIndex: disabled || readOnly ? -1 : void 0,
|
|
771
|
+
ref: mergeRefs(inputRef, ref)
|
|
772
|
+
})
|
|
773
|
+
}
|
|
774
|
+
),
|
|
775
|
+
/* @__PURE__ */ jsx(
|
|
776
|
+
DropdownFieldAppendix,
|
|
777
|
+
{
|
|
778
|
+
...getToggleButtonProps({
|
|
779
|
+
"aria-busy": !(loading ?? resolvedItemsLoading) ? void 0 : "true"
|
|
780
|
+
}),
|
|
781
|
+
ariaLabelCloseList,
|
|
782
|
+
ariaLabelOpenList,
|
|
783
|
+
clearable,
|
|
784
|
+
disabled: disabled || readOnly,
|
|
785
|
+
onClear: handleOnClear,
|
|
786
|
+
focusable: false,
|
|
787
|
+
labelClearSelected: labelClearSelectedItem,
|
|
788
|
+
isOpen,
|
|
789
|
+
itemIsSelected: selectedItem !== null,
|
|
790
|
+
loadingText,
|
|
791
|
+
loading: loading ?? resolvedItemsLoading
|
|
792
|
+
}
|
|
793
|
+
)
|
|
794
|
+
]
|
|
1123
795
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
} : _ref$onChange,
|
|
1184
|
-
placeholder = _ref.placeholder,
|
|
1185
|
-
_ref$readOnly = _ref.readOnly,
|
|
1186
|
-
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1187
|
-
_ref$selectedItems = _ref.selectedItems,
|
|
1188
|
-
selectedItems = _ref$selectedItems === void 0 ? [] : _ref$selectedItems,
|
|
1189
|
-
_ref$selectOnTab = _ref.selectOnTab,
|
|
1190
|
-
selectOnTab = _ref$selectOnTab === void 0 ? false : _ref$selectOnTab,
|
|
1191
|
-
style = _ref.style,
|
|
1192
|
-
_ref$variant = _ref.variant,
|
|
1193
|
-
variant = _ref$variant === void 0 ? 'information' : _ref$variant,
|
|
1194
|
-
ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
1195
|
-
_ref$ariaLabelChosenP = _ref.ariaLabelChosenPlural,
|
|
1196
|
-
ariaLabelChosenPlural = _ref$ariaLabelChosenP === void 0 ? 'valgte' : _ref$ariaLabelChosenP,
|
|
1197
|
-
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
1198
|
-
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
1199
|
-
_ref$ariaLabelJumpToI = _ref.ariaLabelJumpToInput,
|
|
1200
|
-
ariaLabelJumpToInput = _ref$ariaLabelJumpToI === void 0 ? selectedItems.length + " valgte elementer, trykk for \xE5 hoppe til tekstfeltet" : _ref$ariaLabelJumpToI,
|
|
1201
|
-
_ref$ariaLabelOpenLis = _ref.ariaLabelOpenList,
|
|
1202
|
-
ariaLabelOpenList = _ref$ariaLabelOpenLis === void 0 ? 'Åpne liste med valg' : _ref$ariaLabelOpenLis,
|
|
1203
|
-
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1204
|
-
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1205
|
-
ariaLabelSelectedItem = _ref.ariaLabelSelectedItem,
|
|
1206
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
1207
|
-
var _React$useState = React.useState(0),
|
|
1208
|
-
lastHighlightedIndex = _React$useState[0],
|
|
1209
|
-
setLastHighlightedIndex = _React$useState[1];
|
|
1210
|
-
var inputRef = useRef(null);
|
|
1211
|
-
useEffect(function () {
|
|
1212
|
-
//@ts-expect-error this is done to aid developers debug wrong prop usage
|
|
1213
|
-
if (rest.selectedItem !== undefined) console.warn("Incorrect 'selectedItem' prop found, did you mean to use 'selectedItems?");
|
|
1214
|
-
//@ts-expect-error selectedItem should not actually exist in rest
|
|
1215
|
-
}, [rest.selectedItem]);
|
|
1216
|
-
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
1217
|
-
normalizedItems = _useResolvedItems.items,
|
|
1218
|
-
resolvedItemsLoading = _useResolvedItems.loading,
|
|
1219
|
-
fetchItems = _useResolvedItems.fetchItems;
|
|
1220
|
-
var isAllNonAsyncItemsSelected = typeof initialItems !== 'function' && selectedItems.length === normalizedItems.length;
|
|
1221
|
-
// special 'item' used as Select All entry in the dropdown list
|
|
1222
|
-
var selectAll = {
|
|
1223
|
-
value: useRandomId('select-all'),
|
|
1224
|
-
label: labelSelectAll
|
|
1225
|
-
};
|
|
1226
|
-
// special 'item' used as a replacement selected item tag for when
|
|
1227
|
-
// there are more selected element than maxChips
|
|
1228
|
-
var summarySelectedItems = React.useMemo(function () {
|
|
1229
|
-
return {
|
|
1230
|
-
value: EMPTY_INPUT,
|
|
1231
|
-
label: isAllNonAsyncItemsSelected ? labelAllItemsSelected : selectedItems.length + ' ' + ariaLabelChosenPlural
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
);
|
|
799
|
+
const MultiSelect = React.forwardRef(
|
|
800
|
+
({
|
|
801
|
+
className,
|
|
802
|
+
clearable = true,
|
|
803
|
+
clearInputOnSelect = false,
|
|
804
|
+
debounceTimeout,
|
|
805
|
+
disabled = false,
|
|
806
|
+
disableLabelAnimation,
|
|
807
|
+
feedback,
|
|
808
|
+
hideSelectAll = false,
|
|
809
|
+
items: initialItems,
|
|
810
|
+
itemFilter = isFunctionWithQueryArgument(initialItems) ? noFilter : lowerCaseFilterTest,
|
|
811
|
+
label,
|
|
812
|
+
labelAllItemsSelected = "Alle valgt",
|
|
813
|
+
labelClearAllItems = "Fjern valgte",
|
|
814
|
+
labelSelectAll = "Velg alle",
|
|
815
|
+
labelTooltip,
|
|
816
|
+
listStyle,
|
|
817
|
+
loading,
|
|
818
|
+
loadingText = "Laster resultater …",
|
|
819
|
+
maxChips = 10,
|
|
820
|
+
noMatchesText,
|
|
821
|
+
onChange = () => void 0,
|
|
822
|
+
placeholder,
|
|
823
|
+
readOnly = false,
|
|
824
|
+
selectedItems = [],
|
|
825
|
+
selectOnBlur = false,
|
|
826
|
+
selectOnTab = false,
|
|
827
|
+
style,
|
|
828
|
+
variant = "information",
|
|
829
|
+
ariaLabelChosenSingular,
|
|
830
|
+
ariaLabelChosenPlural = "valgte",
|
|
831
|
+
ariaLabelCloseList = "Lukk liste med valg",
|
|
832
|
+
ariaLabelJumpToInput = `${selectedItems.length} valgte elementer, trykk for å hoppe til tekstfeltet`,
|
|
833
|
+
ariaLabelOpenList = "Åpne liste med valg",
|
|
834
|
+
ariaLabelRemoveSelected = "trykk for å fjerne valg",
|
|
835
|
+
ariaLabelSelectedItem,
|
|
836
|
+
...rest
|
|
837
|
+
}, ref) => {
|
|
838
|
+
const [lastHighlightedIndex, setLastHighlightedIndex] = React.useState(0);
|
|
839
|
+
const inputRef = useRef(null);
|
|
840
|
+
useEffect(() => {
|
|
841
|
+
if (rest.selectedItem !== void 0)
|
|
842
|
+
console.warn(
|
|
843
|
+
"Incorrect 'selectedItem' prop found, did you mean to use 'selectedItems?"
|
|
844
|
+
);
|
|
845
|
+
}, [rest.selectedItem]);
|
|
846
|
+
const {
|
|
847
|
+
items: normalizedItems,
|
|
848
|
+
loading: resolvedItemsLoading,
|
|
849
|
+
fetchItems
|
|
850
|
+
} = useResolvedItems(initialItems, debounceTimeout);
|
|
851
|
+
const isAllNonAsyncItemsSelected = typeof initialItems !== "function" && selectedItems.length === normalizedItems.length;
|
|
852
|
+
const selectAll = {
|
|
853
|
+
value: useRandomId("select-all"),
|
|
854
|
+
label: labelSelectAll
|
|
1232
855
|
};
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
})
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
856
|
+
const summarySelectedItems = React.useMemo(
|
|
857
|
+
() => ({
|
|
858
|
+
value: EMPTY_INPUT,
|
|
859
|
+
label: isAllNonAsyncItemsSelected ? labelAllItemsSelected : selectedItems.length + " " + ariaLabelChosenPlural
|
|
860
|
+
}),
|
|
861
|
+
[
|
|
862
|
+
isAllNonAsyncItemsSelected,
|
|
863
|
+
selectedItems,
|
|
864
|
+
labelAllItemsSelected,
|
|
865
|
+
ariaLabelChosenPlural
|
|
866
|
+
]
|
|
867
|
+
);
|
|
868
|
+
const [listItems, setListItems] = useState([
|
|
869
|
+
...!hideSelectAll ? [selectAll] : [],
|
|
870
|
+
...normalizedItems
|
|
871
|
+
]);
|
|
872
|
+
const filterListItems = ({ inputValue: inputValue2 }) => setListItems([
|
|
873
|
+
...!hideSelectAll ? [selectAll] : [],
|
|
874
|
+
...normalizedItems.filter((item) => itemFilter(item, inputValue2))
|
|
875
|
+
]);
|
|
876
|
+
const updateListItems = ({ inputValue: inputValue2 }) => {
|
|
877
|
+
const shouldRefetchItems = isFunctionWithQueryArgument(initialItems);
|
|
878
|
+
if (shouldRefetchItems) fetchItems(inputValue2 ?? EMPTY_INPUT);
|
|
879
|
+
filterListItems({ inputValue: inputValue2 ?? EMPTY_INPUT });
|
|
880
|
+
};
|
|
881
|
+
React.useEffect(() => {
|
|
882
|
+
filterListItems({ inputValue });
|
|
883
|
+
}, [normalizedItems]);
|
|
884
|
+
const {
|
|
885
|
+
hasSelectedItems,
|
|
886
|
+
handleListItemClicked,
|
|
887
|
+
selectAllCheckboxState,
|
|
888
|
+
clickedItemIsInSelectedItems,
|
|
889
|
+
clickedItemIsSelectAll
|
|
890
|
+
} = useMultiselectUtils({
|
|
891
|
+
listItems,
|
|
892
|
+
selectAll,
|
|
893
|
+
selectedItems
|
|
1254
894
|
});
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
selectAllCheckboxState = _useMultiselectUtils.selectAllCheckboxState,
|
|
1264
|
-
clickedItemIsInSelectedItems = _useMultiselectUtils.clickedItemIsInSelectedItems,
|
|
1265
|
-
clickedItemIsSelectAll = _useMultiselectUtils.clickedItemIsSelectAll;
|
|
1266
|
-
var _useMultipleSelection = useMultipleSelection({
|
|
1267
|
-
selectedItems: selectedItems,
|
|
895
|
+
const {
|
|
896
|
+
getSelectedItemProps,
|
|
897
|
+
getDropdownProps,
|
|
898
|
+
reset,
|
|
899
|
+
removeSelectedItem,
|
|
900
|
+
setSelectedItems
|
|
901
|
+
} = useMultipleSelection({
|
|
902
|
+
selectedItems,
|
|
1268
903
|
// @ts-expect-error prop missing from library types
|
|
1269
|
-
itemToString
|
|
1270
|
-
itemToKey
|
|
1271
|
-
onSelectedItemsChange:
|
|
1272
|
-
var newSelectedItems = _ref4.selectedItems;
|
|
904
|
+
itemToString,
|
|
905
|
+
itemToKey,
|
|
906
|
+
onSelectedItemsChange({ selectedItems: newSelectedItems }) {
|
|
1273
907
|
onChange(newSelectedItems);
|
|
1274
908
|
}
|
|
1275
|
-
})
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
type = _ref5.type;
|
|
1284
|
-
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
1285
|
-
setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1286
|
-
}
|
|
1287
|
-
switch (type) {
|
|
1288
|
-
// reset input value when leaving input field
|
|
1289
|
-
case useCombobox.stateChangeTypes.InputBlur:
|
|
1290
|
-
return _extends({}, changes, {
|
|
1291
|
-
inputValue: EMPTY_INPUT
|
|
1292
|
-
});
|
|
1293
|
-
// keep menu open and edit input value on item selection
|
|
1294
|
-
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1295
|
-
case useCombobox.stateChangeTypes.ItemClick:
|
|
1296
|
-
{
|
|
1297
|
-
var _inputRef$current$val, _inputRef$current;
|
|
1298
|
-
return _extends({}, changes, {
|
|
1299
|
-
isOpen: true,
|
|
1300
|
-
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : EMPTY_INPUT
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1303
|
-
// edit input value when selected items is updated outside component
|
|
1304
|
-
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1305
|
-
{
|
|
1306
|
-
var _inputRef$current$val2, _inputRef$current2;
|
|
1307
|
-
return _extends({}, changes, {
|
|
1308
|
-
inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val2 : EMPTY_INPUT
|
|
1309
|
-
});
|
|
909
|
+
});
|
|
910
|
+
const stateReducer = React.useCallback(
|
|
911
|
+
(state, {
|
|
912
|
+
changes,
|
|
913
|
+
type
|
|
914
|
+
}) => {
|
|
915
|
+
if (changes.highlightedIndex !== void 0 && changes?.highlightedIndex >= 0) {
|
|
916
|
+
setLastHighlightedIndex(changes?.highlightedIndex);
|
|
1310
917
|
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
918
|
+
switch (type) {
|
|
919
|
+
// reset input value when leaving input field
|
|
920
|
+
case useCombobox.stateChangeTypes.InputBlur:
|
|
921
|
+
return {
|
|
922
|
+
...changes,
|
|
923
|
+
inputValue: EMPTY_INPUT
|
|
924
|
+
};
|
|
925
|
+
// keep menu open and edit input value on item selection
|
|
926
|
+
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
927
|
+
case useCombobox.stateChangeTypes.ItemClick: {
|
|
928
|
+
return {
|
|
929
|
+
...changes,
|
|
930
|
+
isOpen: true,
|
|
931
|
+
inputValue: clearInputOnSelect ? EMPTY_INPUT : inputRef?.current?.value ?? EMPTY_INPUT
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
// edit input value when selected items is updated outside component
|
|
935
|
+
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem: {
|
|
936
|
+
return {
|
|
937
|
+
...changes,
|
|
938
|
+
inputValue: inputRef?.current?.value ?? EMPTY_INPUT
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
// remove leading whitespace, select item with spacebar if input is empty and filter list items
|
|
942
|
+
case useCombobox.stateChangeTypes.InputChange: {
|
|
943
|
+
const leadingWhitespaceTest = /^\s+/g;
|
|
944
|
+
const isSpacePressedOnEmptyInput = changes.inputValue === " ";
|
|
945
|
+
if (changes.inputValue?.match(leadingWhitespaceTest)) {
|
|
946
|
+
const sanitizedInputValue = changes.inputValue.replace(
|
|
947
|
+
leadingWhitespaceTest,
|
|
948
|
+
EMPTY_INPUT
|
|
949
|
+
);
|
|
950
|
+
if (isSpacePressedOnEmptyInput) {
|
|
951
|
+
if (!state.isOpen)
|
|
952
|
+
return {
|
|
953
|
+
...changes,
|
|
954
|
+
inputValue: sanitizedInputValue,
|
|
955
|
+
isOpen: true
|
|
956
|
+
};
|
|
957
|
+
if (changes.highlightedIndex !== void 0) {
|
|
958
|
+
return {
|
|
959
|
+
...changes,
|
|
960
|
+
inputValue: sanitizedInputValue,
|
|
961
|
+
selectedItem: listItems[changes.highlightedIndex]
|
|
962
|
+
};
|
|
963
|
+
}
|
|
1329
964
|
}
|
|
1330
965
|
}
|
|
966
|
+
return changes;
|
|
1331
967
|
}
|
|
1332
|
-
|
|
968
|
+
default:
|
|
969
|
+
return changes;
|
|
1333
970
|
}
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
971
|
+
},
|
|
972
|
+
[hideSelectAll, normalizedItems, filterListItems, initialItems]
|
|
973
|
+
);
|
|
974
|
+
const {
|
|
975
|
+
getInputProps,
|
|
976
|
+
getItemProps,
|
|
977
|
+
getLabelProps,
|
|
978
|
+
getMenuProps,
|
|
979
|
+
getToggleButtonProps,
|
|
980
|
+
highlightedIndex,
|
|
981
|
+
setHighlightedIndex,
|
|
982
|
+
inputValue,
|
|
983
|
+
isOpen,
|
|
984
|
+
setInputValue
|
|
985
|
+
} = useCombobox({
|
|
1339
986
|
defaultHighlightedIndex: lastHighlightedIndex,
|
|
1340
987
|
// after selection, highlight previously selected item.
|
|
1341
988
|
items: listItems,
|
|
1342
|
-
itemToString
|
|
989
|
+
itemToString,
|
|
1343
990
|
selectedItem: null,
|
|
1344
|
-
stateReducer
|
|
1345
|
-
onInputValueChange
|
|
1346
|
-
updateListItems({
|
|
1347
|
-
inputValue: changes.inputValue
|
|
1348
|
-
});
|
|
1349
|
-
// set highlighted item to first item after search
|
|
991
|
+
stateReducer,
|
|
992
|
+
onInputValueChange(changes) {
|
|
993
|
+
updateListItems({ inputValue: changes.inputValue });
|
|
1350
994
|
setHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1351
995
|
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1352
996
|
},
|
|
1353
|
-
onSelectedItemChange:
|
|
1354
|
-
var clickedItem = _ref6.selectedItem;
|
|
1355
|
-
// clickedItem means item chosen either via mouse or keyboard
|
|
997
|
+
onSelectedItemChange({ selectedItem: clickedItem }) {
|
|
1356
998
|
if (!clickedItem) return;
|
|
1357
999
|
handleListItemClicked({
|
|
1358
|
-
clickedItem
|
|
1000
|
+
clickedItem,
|
|
1359
1001
|
onChange: setSelectedItems
|
|
1360
1002
|
});
|
|
1361
1003
|
},
|
|
1362
1004
|
// Accessibility
|
|
1363
|
-
getA11yStatusMessage:
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
getItemProps = _useCombobox.getItemProps,
|
|
1372
|
-
getLabelProps = _useCombobox.getLabelProps,
|
|
1373
|
-
getMenuProps = _useCombobox.getMenuProps,
|
|
1374
|
-
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1375
|
-
highlightedIndex = _useCombobox.highlightedIndex,
|
|
1376
|
-
setHighlightedIndex = _useCombobox.setHighlightedIndex,
|
|
1377
|
-
inputValue = _useCombobox.inputValue,
|
|
1378
|
-
isOpen = _useCombobox.isOpen,
|
|
1379
|
-
setInputValue = _useCombobox.setInputValue;
|
|
1380
|
-
// calculations for floating-UI popover position
|
|
1381
|
-
var _useFloating = useFloating({
|
|
1005
|
+
getA11yStatusMessage: (options) => getA11yStatusMessage({
|
|
1006
|
+
...options,
|
|
1007
|
+
selectAllItemIncluded: !hideSelectAll,
|
|
1008
|
+
resultCount: listItems.length
|
|
1009
|
+
}),
|
|
1010
|
+
...rest
|
|
1011
|
+
});
|
|
1012
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
1382
1013
|
open: isOpen,
|
|
1383
|
-
placement:
|
|
1384
|
-
middleware: [
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
elements
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
}
|
|
1398
|
-
|
|
1399
|
-
fallbackStrategy: 'initialPlacement'
|
|
1400
|
-
})]
|
|
1401
|
-
}),
|
|
1402
|
-
refs = _useFloating.refs,
|
|
1403
|
-
floatingStyles = _useFloating.floatingStyles,
|
|
1404
|
-
update = _useFloating.update;
|
|
1405
|
-
// Update floating-ui position on scroll etc. Floating-ui's autoupdate is usually used inside
|
|
1406
|
-
// the useFloating hook but this requires the floating element to be conditionally rendered.
|
|
1407
|
-
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1408
|
-
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1409
|
-
useEffect(function () {
|
|
1410
|
-
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1411
|
-
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1412
|
-
}
|
|
1413
|
-
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1414
|
-
var handleOnClear = function handleOnClear() {
|
|
1415
|
-
var _inputRef$current3;
|
|
1416
|
-
(_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
|
|
1417
|
-
reset();
|
|
1418
|
-
};
|
|
1419
|
-
return React.createElement(BaseFormControl, _extends({
|
|
1420
|
-
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
1421
|
-
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1422
|
-
}),
|
|
1423
|
-
disabled: disabled,
|
|
1424
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
1425
|
-
feedback: feedback,
|
|
1426
|
-
isFilled: hasSelectedItems || inputValue !== EMPTY_INPUT,
|
|
1427
|
-
label: label,
|
|
1428
|
-
labelId: getLabelProps().id,
|
|
1429
|
-
labelProps: getLabelProps(),
|
|
1430
|
-
labelTooltip: labelTooltip,
|
|
1431
|
-
onBlur: function onBlur() {
|
|
1432
|
-
return setInputValue('');
|
|
1433
|
-
},
|
|
1434
|
-
onClick: function onClick(e) {
|
|
1435
|
-
if (e.target === e.currentTarget) {
|
|
1436
|
-
var _getInputProps;
|
|
1437
|
-
(_getInputProps = getInputProps()) == null || _getInputProps.onClick == null || _getInputProps.onClick(e);
|
|
1438
|
-
}
|
|
1439
|
-
},
|
|
1440
|
-
readOnly: readOnly,
|
|
1441
|
-
ref: refs.setReference,
|
|
1442
|
-
style: style,
|
|
1443
|
-
variant: variant,
|
|
1444
|
-
after: React.createElement(DropdownList, {
|
|
1445
|
-
ariaLabelChosenSingular: ariaLabelChosenSingular,
|
|
1446
|
-
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1447
|
-
floatingStyles: floatingStyles,
|
|
1448
|
-
getItemProps: getItemProps,
|
|
1449
|
-
getMenuProps: getMenuProps,
|
|
1450
|
-
highlightedIndex: highlightedIndex,
|
|
1451
|
-
isOpen: isOpen,
|
|
1452
|
-
listItems: listItems,
|
|
1453
|
-
style: listStyle,
|
|
1454
|
-
setListRef: refs.setFloating,
|
|
1455
|
-
loading: loading != null ? loading : resolvedItemsLoading,
|
|
1456
|
-
loadingText: loadingText,
|
|
1457
|
-
noMatchesText: noMatchesText,
|
|
1458
|
-
selectAllCheckboxState: selectAllCheckboxState,
|
|
1459
|
-
selectAllItem: selectAll,
|
|
1460
|
-
selectedItems: selectedItems,
|
|
1461
|
-
readOnly: readOnly
|
|
1462
|
-
})
|
|
1463
|
-
}, rest), React.createElement("div", {
|
|
1464
|
-
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
1465
|
-
'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
|
|
1466
|
-
})
|
|
1467
|
-
}, selectedItems.length > 1 ? React.createElement(VisuallyHidden, {
|
|
1468
|
-
onClick: (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus
|
|
1469
|
-
}, ariaLabelJumpToInput) : null, selectedItems.length <= maxChips ? selectedItems.map(function (selectedItem, index) {
|
|
1470
|
-
return React.createElement(SelectedItemTag, {
|
|
1471
|
-
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1472
|
-
ariaLabelRemoveSelected: ariaLabelRemoveSelected,
|
|
1473
|
-
disabled: disabled,
|
|
1474
|
-
getSelectedItemProps: getSelectedItemProps,
|
|
1475
|
-
index: index,
|
|
1476
|
-
key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
|
|
1477
|
-
readOnly: readOnly,
|
|
1478
|
-
removeSelectedItem: function removeSelectedItem() {
|
|
1479
|
-
var _inputRef$current5;
|
|
1480
|
-
_removeSelectedItem(selectedItem);
|
|
1481
|
-
inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
|
|
1482
|
-
},
|
|
1483
|
-
selectedItem: selectedItem
|
|
1014
|
+
placement: "bottom-start",
|
|
1015
|
+
middleware: [
|
|
1016
|
+
offset(space.extraSmall2),
|
|
1017
|
+
shift({ padding: space.extraSmall }),
|
|
1018
|
+
size({
|
|
1019
|
+
apply({ rects, elements, availableHeight }) {
|
|
1020
|
+
Object.assign(elements.floating.style, {
|
|
1021
|
+
width: `${rects.reference.width}px`,
|
|
1022
|
+
// Floating will flip when smaller than 10*16 px
|
|
1023
|
+
// and never exceed 20*16 px.
|
|
1024
|
+
maxHeight: `${clamp(10 * 16, availableHeight, 20 * 16)}px`
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
}),
|
|
1028
|
+
flip({ fallbackStrategy: "initialPlacement" })
|
|
1029
|
+
]
|
|
1484
1030
|
});
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}), React.createElement("input", _extends({}, getInputProps(_extends({
|
|
1493
|
-
onKeyDown: function onKeyDown(e) {
|
|
1494
|
-
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1495
|
-
var highlitedItem = listItems[highlightedIndex];
|
|
1496
|
-
if (!highlitedItem) return;
|
|
1497
|
-
// Skip tab selection for select all or if item already is selected
|
|
1498
|
-
var shouldSkipTabSelection = clickedItemIsSelectAll(highlitedItem) || !clickedItemIsSelectAll(highlitedItem) && clickedItemIsInSelectedItems(highlitedItem);
|
|
1499
|
-
if (shouldSkipTabSelection) return;
|
|
1500
|
-
handleListItemClicked({
|
|
1501
|
-
clickedItem: highlitedItem,
|
|
1502
|
-
onChange: setSelectedItems
|
|
1503
|
-
});
|
|
1031
|
+
useEffect(() => {
|
|
1032
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1033
|
+
return autoUpdate(
|
|
1034
|
+
refs.reference.current,
|
|
1035
|
+
refs.floating.current,
|
|
1036
|
+
update
|
|
1037
|
+
);
|
|
1504
1038
|
}
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1039
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1040
|
+
const handleOnClear = () => {
|
|
1041
|
+
inputRef.current?.focus();
|
|
1042
|
+
reset();
|
|
1043
|
+
};
|
|
1044
|
+
return /* @__PURE__ */ jsxs(
|
|
1045
|
+
BaseFormControl,
|
|
1046
|
+
{
|
|
1047
|
+
className: classNames(
|
|
1048
|
+
"eds-dropdown",
|
|
1049
|
+
"eds-dropdown--multiselect",
|
|
1050
|
+
className,
|
|
1051
|
+
{ "eds-dropdown--has-tooltip": labelTooltip !== void 0 }
|
|
1052
|
+
),
|
|
1053
|
+
disabled,
|
|
1054
|
+
disableLabelAnimation,
|
|
1055
|
+
feedback,
|
|
1056
|
+
isFilled: hasSelectedItems || inputValue !== EMPTY_INPUT,
|
|
1057
|
+
label,
|
|
1058
|
+
labelId: getLabelProps().id,
|
|
1059
|
+
labelProps: getLabelProps(),
|
|
1060
|
+
labelTooltip,
|
|
1061
|
+
onBlur: () => setInputValue(""),
|
|
1062
|
+
onClick: (e) => {
|
|
1063
|
+
if (e.target === e.currentTarget) {
|
|
1064
|
+
getInputProps()?.onClick?.(e);
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
readOnly,
|
|
1068
|
+
ref: refs.setReference,
|
|
1069
|
+
style,
|
|
1070
|
+
variant,
|
|
1071
|
+
after: /* @__PURE__ */ jsx(
|
|
1072
|
+
DropdownList,
|
|
1073
|
+
{
|
|
1074
|
+
ariaLabelChosenSingular,
|
|
1075
|
+
ariaLabelSelectedItem,
|
|
1076
|
+
floatingStyles,
|
|
1077
|
+
getItemProps,
|
|
1078
|
+
getMenuProps,
|
|
1079
|
+
highlightedIndex,
|
|
1080
|
+
isOpen,
|
|
1081
|
+
listItems,
|
|
1082
|
+
style: listStyle,
|
|
1083
|
+
setListRef: refs.setFloating,
|
|
1084
|
+
loading: loading ?? resolvedItemsLoading,
|
|
1085
|
+
loadingText,
|
|
1086
|
+
noMatchesText,
|
|
1087
|
+
selectAllCheckboxState,
|
|
1088
|
+
selectAllItem: selectAll,
|
|
1089
|
+
selectedItems,
|
|
1090
|
+
readOnly
|
|
1091
|
+
}
|
|
1092
|
+
),
|
|
1093
|
+
...rest,
|
|
1094
|
+
children: [
|
|
1095
|
+
/* @__PURE__ */ jsxs(
|
|
1096
|
+
"div",
|
|
1097
|
+
{
|
|
1098
|
+
className: classNames(
|
|
1099
|
+
"eds-dropdown--multiselect__selected-items-and-input",
|
|
1100
|
+
{
|
|
1101
|
+
"eds-dropdown--multiselect__selected-items-and-input--filled": hasSelectedItems
|
|
1102
|
+
}
|
|
1103
|
+
),
|
|
1104
|
+
children: [
|
|
1105
|
+
selectedItems.length > 1 ? /* @__PURE__ */ jsx(VisuallyHidden, { onClick: inputRef.current?.focus, children: ariaLabelJumpToInput }) : null,
|
|
1106
|
+
selectedItems.length <= maxChips ? selectedItems.map((selectedItem, index) => /* @__PURE__ */ jsx(
|
|
1107
|
+
SelectedItemTag,
|
|
1108
|
+
{
|
|
1109
|
+
ariaLabelChosen: ariaLabelChosenSingular,
|
|
1110
|
+
ariaLabelRemoveSelected,
|
|
1111
|
+
disabled,
|
|
1112
|
+
getSelectedItemProps,
|
|
1113
|
+
index,
|
|
1114
|
+
readOnly,
|
|
1115
|
+
removeSelectedItem: () => {
|
|
1116
|
+
removeSelectedItem(selectedItem);
|
|
1117
|
+
inputRef?.current?.focus();
|
|
1118
|
+
},
|
|
1119
|
+
selectedItem
|
|
1120
|
+
},
|
|
1121
|
+
selectedItem?.label + (typeof selectedItem?.value === "string" ? selectedItem.value : "")
|
|
1122
|
+
)) : /* @__PURE__ */ jsx(
|
|
1123
|
+
SelectedItemTag,
|
|
1124
|
+
{
|
|
1125
|
+
ariaLabelRemoveSelected: labelClearAllItems,
|
|
1126
|
+
ariaLabelChosen: "",
|
|
1127
|
+
disabled,
|
|
1128
|
+
readOnly,
|
|
1129
|
+
removeSelectedItem: handleOnClear,
|
|
1130
|
+
selectedItem: summarySelectedItems
|
|
1131
|
+
}
|
|
1132
|
+
),
|
|
1133
|
+
/* @__PURE__ */ jsx(
|
|
1134
|
+
"input",
|
|
1135
|
+
{
|
|
1136
|
+
...getInputProps({
|
|
1137
|
+
onKeyDown: (e) => {
|
|
1138
|
+
if (selectOnTab && isOpen && e.key === "Tab") {
|
|
1139
|
+
const highlitedItem = listItems[highlightedIndex];
|
|
1140
|
+
if (!highlitedItem) return;
|
|
1141
|
+
const shouldSkipTabSelection = clickedItemIsSelectAll(highlitedItem) || !clickedItemIsSelectAll(highlitedItem) && clickedItemIsInSelectedItems(highlitedItem);
|
|
1142
|
+
if (shouldSkipTabSelection) return;
|
|
1143
|
+
handleListItemClicked({
|
|
1144
|
+
clickedItem: highlitedItem,
|
|
1145
|
+
onChange: setSelectedItems
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
},
|
|
1149
|
+
...getDropdownProps({
|
|
1150
|
+
preventKeyAction: isOpen,
|
|
1151
|
+
value: inputValue ?? EMPTY_INPUT,
|
|
1152
|
+
ref: mergeRefs(inputRef, ref)
|
|
1153
|
+
}),
|
|
1154
|
+
className: "eds-dropdown__input eds-form-control",
|
|
1155
|
+
disabled: readOnly || disabled,
|
|
1156
|
+
placeholder,
|
|
1157
|
+
tabIndex: disabled || readOnly ? -1 : void 0
|
|
1158
|
+
})
|
|
1159
|
+
}
|
|
1160
|
+
)
|
|
1161
|
+
]
|
|
1162
|
+
}
|
|
1163
|
+
),
|
|
1164
|
+
/* @__PURE__ */ jsx(
|
|
1165
|
+
DropdownFieldAppendix,
|
|
1166
|
+
{
|
|
1167
|
+
...getToggleButtonProps({
|
|
1168
|
+
"aria-busy": !(loading ?? resolvedItemsLoading) ? void 0 : "true"
|
|
1169
|
+
}),
|
|
1170
|
+
ariaLabelCloseList,
|
|
1171
|
+
ariaLabelOpenList,
|
|
1172
|
+
clearable,
|
|
1173
|
+
disabled: disabled || readOnly,
|
|
1174
|
+
onClear: handleOnClear,
|
|
1175
|
+
focusable: false,
|
|
1176
|
+
labelClearSelected: labelClearAllItems,
|
|
1177
|
+
isOpen,
|
|
1178
|
+
itemIsSelected: selectedItems.length > 0,
|
|
1179
|
+
loadingText,
|
|
1180
|
+
loading: loading ?? resolvedItemsLoading
|
|
1181
|
+
}
|
|
1182
|
+
)
|
|
1183
|
+
]
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
);
|
|
1188
|
+
const Dropdown = React.forwardRef(
|
|
1189
|
+
({
|
|
1190
|
+
ariaLabelChosenSingular,
|
|
1191
|
+
ariaLabelCloseList = "Lukk liste med valg",
|
|
1192
|
+
ariaLabelOpenList = "Åpne liste med valg",
|
|
1193
|
+
ariaLabelSelectedItem,
|
|
1194
|
+
className,
|
|
1195
|
+
clearable = false,
|
|
1196
|
+
disabled = false,
|
|
1197
|
+
disableLabelAnimation,
|
|
1198
|
+
feedback,
|
|
1199
|
+
items: initialItems,
|
|
1200
|
+
label,
|
|
1201
|
+
labelClearSelectedItem = "fjern valgt",
|
|
1202
|
+
labelTooltip,
|
|
1203
|
+
listStyle,
|
|
1204
|
+
loading,
|
|
1205
|
+
loadingText = "Laster resultater …",
|
|
1206
|
+
noMatchesText = "Ingen tilgjengelige valg …",
|
|
1207
|
+
onChange,
|
|
1208
|
+
placeholder,
|
|
1209
|
+
prepend,
|
|
1210
|
+
readOnly = false,
|
|
1211
|
+
selectedItem,
|
|
1212
|
+
selectOnBlur = false,
|
|
1213
|
+
selectOnTab = false,
|
|
1214
|
+
style,
|
|
1215
|
+
variant = "information",
|
|
1216
|
+
...rest
|
|
1217
|
+
}, ref) => {
|
|
1218
|
+
const { items: normalizedItems, loading: resolvedItemsLoading } = useResolvedItems(initialItems);
|
|
1219
|
+
const isFilled = selectedItem !== null || placeholder !== void 0;
|
|
1220
|
+
const {
|
|
1221
|
+
isOpen,
|
|
1222
|
+
getItemProps,
|
|
1223
|
+
getLabelProps,
|
|
1224
|
+
getMenuProps,
|
|
1225
|
+
getToggleButtonProps,
|
|
1226
|
+
highlightedIndex,
|
|
1227
|
+
selectItem,
|
|
1228
|
+
reset
|
|
1229
|
+
} = useSelect({
|
|
1578
1230
|
items: normalizedItems,
|
|
1579
|
-
defaultHighlightedIndex: selectedItem ?
|
|
1580
|
-
selectedItem
|
|
1581
|
-
stateReducer
|
|
1582
|
-
|
|
1583
|
-
type = _ref2.type;
|
|
1584
|
-
var toggleButtonIsFocused = typeof document !== 'undefined' && document.activeElement === refs.reference.current;
|
|
1231
|
+
defaultHighlightedIndex: selectedItem ? void 0 : 0,
|
|
1232
|
+
selectedItem,
|
|
1233
|
+
stateReducer(_, { changes, type }) {
|
|
1234
|
+
const toggleButtonIsFocused = typeof document !== "undefined" && document.activeElement === refs.reference.current;
|
|
1585
1235
|
switch (type) {
|
|
1586
1236
|
case useSelect.stateChangeTypes.ToggleButtonKeyDownArrowDown:
|
|
1587
1237
|
case useSelect.stateChangeTypes.ToggleButtonKeyDownArrowUp:
|
|
1588
|
-
if (!toggleButtonIsFocused) return
|
|
1589
|
-
isOpen: false
|
|
1590
|
-
});
|
|
1238
|
+
if (!toggleButtonIsFocused) return { ...changes, isOpen: false };
|
|
1591
1239
|
}
|
|
1592
1240
|
return changes;
|
|
1593
1241
|
},
|
|
1594
|
-
onStateChange:
|
|
1595
|
-
var type = _ref3.type,
|
|
1596
|
-
newSelectedItem = _ref3.selectedItem;
|
|
1242
|
+
onStateChange({ type, selectedItem: newSelectedItem }) {
|
|
1597
1243
|
switch (type) {
|
|
1598
1244
|
case useSelect.stateChangeTypes.ToggleButtonBlur:
|
|
1599
1245
|
if (!selectOnBlur) return;
|
|
1600
1246
|
}
|
|
1601
|
-
if (newSelectedItem ===
|
|
1602
|
-
onChange
|
|
1247
|
+
if (newSelectedItem === void 0) return;
|
|
1248
|
+
onChange?.(newSelectedItem ?? null);
|
|
1603
1249
|
},
|
|
1604
|
-
itemToString
|
|
1605
|
-
})
|
|
1606
|
-
|
|
1607
|
-
getItemProps = _useSelect.getItemProps,
|
|
1608
|
-
getLabelProps = _useSelect.getLabelProps,
|
|
1609
|
-
getMenuProps = _useSelect.getMenuProps,
|
|
1610
|
-
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1611
|
-
highlightedIndex = _useSelect.highlightedIndex,
|
|
1612
|
-
selectItem = _useSelect.selectItem,
|
|
1613
|
-
reset = _useSelect.reset;
|
|
1614
|
-
// calculations for floating-UI popover position
|
|
1615
|
-
var _useFloating = useFloating({
|
|
1250
|
+
itemToString
|
|
1251
|
+
});
|
|
1252
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
1616
1253
|
open: isOpen,
|
|
1617
|
-
placement:
|
|
1618
|
-
middleware: [
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
elements
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
// Downshift doesn't work correctly when conditionally rendered since props and refs aren't correctly
|
|
1642
|
-
// spread to the component. We therefor use this useEffect to update position. See https://floating-ui.com/docs/autoupdate#usage
|
|
1643
|
-
useEffect(function () {
|
|
1644
|
-
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1645
|
-
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
1646
|
-
}
|
|
1647
|
-
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1648
|
-
var handleOnClear = function handleOnClear() {
|
|
1649
|
-
var _refs$reference$curre;
|
|
1650
|
-
reset();
|
|
1651
|
-
(_refs$reference$curre = refs.reference.current) == null || _refs$reference$curre.focus();
|
|
1652
|
-
};
|
|
1653
|
-
return React.createElement(BaseFormControl, _extends({
|
|
1654
|
-
className: classNames('eds-dropdown', className, {
|
|
1655
|
-
'eds-dropdown--has-tooltip': labelTooltip !== undefined
|
|
1656
|
-
}),
|
|
1657
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
1658
|
-
feedback: feedback,
|
|
1659
|
-
isFilled: isFilled,
|
|
1660
|
-
labelProps: getLabelProps(),
|
|
1661
|
-
labelTooltip: labelTooltip,
|
|
1662
|
-
prepend: prepend,
|
|
1663
|
-
style: style,
|
|
1664
|
-
variant: variant
|
|
1665
|
-
}, getToggleButtonProps({
|
|
1666
|
-
ref: mergeRefs(ref, refs.setReference),
|
|
1667
|
-
'aria-disabled': disabled,
|
|
1668
|
-
'aria-label': disabled ? 'Disabled dropdown' : '',
|
|
1669
|
-
disabled: disabled,
|
|
1670
|
-
readOnly: readOnly,
|
|
1671
|
-
label: label,
|
|
1672
|
-
labelId: (_getLabelProps = getLabelProps()) == null ? void 0 : _getLabelProps.id,
|
|
1673
|
-
children: undefined,
|
|
1674
|
-
tabIndex: disabled || readOnly ? -1 : 0,
|
|
1675
|
-
onKeyDown: function onKeyDown(e) {
|
|
1676
|
-
if (isOpen && e.key === 'Tab') {
|
|
1677
|
-
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1678
|
-
// we don't want to clear selection with tab
|
|
1679
|
-
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1680
|
-
selectItem(highlitedItem);
|
|
1681
|
-
}
|
|
1254
|
+
placement: "bottom-start",
|
|
1255
|
+
middleware: [
|
|
1256
|
+
offset(space.extraSmall2),
|
|
1257
|
+
shift({ padding: space.extraSmall }),
|
|
1258
|
+
size({
|
|
1259
|
+
apply({ rects, elements, availableHeight }) {
|
|
1260
|
+
Object.assign(elements.floating.style, {
|
|
1261
|
+
width: `${rects.reference.width}px`,
|
|
1262
|
+
// Floating will flip when smaller than 10*16 px
|
|
1263
|
+
// and never exceed 20*16 px.
|
|
1264
|
+
maxHeight: `${clamp(10 * 16, availableHeight, 20 * 16)}px`
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
}),
|
|
1268
|
+
flip({ fallbackStrategy: "initialPlacement" })
|
|
1269
|
+
]
|
|
1270
|
+
});
|
|
1271
|
+
useEffect(() => {
|
|
1272
|
+
if (isOpen && refs.reference.current && refs.floating.current) {
|
|
1273
|
+
return autoUpdate(
|
|
1274
|
+
refs.reference.current,
|
|
1275
|
+
refs.floating.current,
|
|
1276
|
+
update
|
|
1277
|
+
);
|
|
1682
1278
|
}
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1279
|
+
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1280
|
+
const handleOnClear = () => {
|
|
1281
|
+
reset();
|
|
1282
|
+
refs.reference.current?.focus();
|
|
1283
|
+
};
|
|
1284
|
+
return /* @__PURE__ */ jsxs(
|
|
1285
|
+
BaseFormControl,
|
|
1286
|
+
{
|
|
1287
|
+
className: classNames("eds-dropdown", className, {
|
|
1288
|
+
"eds-dropdown--has-tooltip": labelTooltip !== void 0
|
|
1289
|
+
}),
|
|
1290
|
+
disableLabelAnimation,
|
|
1291
|
+
feedback,
|
|
1292
|
+
isFilled,
|
|
1293
|
+
labelProps: getLabelProps(),
|
|
1294
|
+
labelTooltip,
|
|
1295
|
+
prepend,
|
|
1296
|
+
style,
|
|
1297
|
+
variant,
|
|
1298
|
+
...getToggleButtonProps({
|
|
1299
|
+
ref: mergeRefs(ref, refs.setReference),
|
|
1300
|
+
"aria-disabled": disabled,
|
|
1301
|
+
"aria-label": disabled ? "Disabled dropdown" : "",
|
|
1302
|
+
disabled,
|
|
1303
|
+
readOnly,
|
|
1304
|
+
label,
|
|
1305
|
+
labelId: getLabelProps()?.id,
|
|
1306
|
+
children: void 0,
|
|
1307
|
+
tabIndex: disabled || readOnly ? -1 : 0,
|
|
1308
|
+
onKeyDown(e) {
|
|
1309
|
+
if (isOpen && e.key === "Tab") {
|
|
1310
|
+
const highlitedItem = normalizedItems[highlightedIndex];
|
|
1311
|
+
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1312
|
+
selectItem(highlitedItem);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}),
|
|
1317
|
+
after: /* @__PURE__ */ jsx(
|
|
1318
|
+
DropdownList,
|
|
1319
|
+
{
|
|
1320
|
+
ariaLabelChosenSingular,
|
|
1321
|
+
ariaLabelSelectedItem,
|
|
1322
|
+
floatingStyles,
|
|
1323
|
+
getItemProps,
|
|
1324
|
+
getMenuProps,
|
|
1325
|
+
highlightedIndex,
|
|
1326
|
+
isOpen,
|
|
1327
|
+
listItems: normalizedItems,
|
|
1328
|
+
noMatchesText,
|
|
1329
|
+
style: listStyle,
|
|
1330
|
+
setListRef: refs.setFloating,
|
|
1331
|
+
loading: loading ?? resolvedItemsLoading,
|
|
1332
|
+
loadingText,
|
|
1333
|
+
selectedItems: selectedItem !== null ? [selectedItem] : [],
|
|
1334
|
+
readOnly
|
|
1335
|
+
}
|
|
1336
|
+
),
|
|
1337
|
+
...rest,
|
|
1338
|
+
append: void 0,
|
|
1339
|
+
children: [
|
|
1340
|
+
/* @__PURE__ */ jsx("div", { className: "eds-dropdown__selected-item", children: selectedItem?.label ?? /* @__PURE__ */ jsx(
|
|
1341
|
+
"div",
|
|
1342
|
+
{
|
|
1343
|
+
className: classNames(
|
|
1344
|
+
"eds-dropdown__selected-item__placeholder",
|
|
1345
|
+
{
|
|
1346
|
+
"eds-dropdown__selected-item__placeholder--readonly": readOnly
|
|
1347
|
+
}
|
|
1348
|
+
),
|
|
1349
|
+
children: placeholder
|
|
1350
|
+
}
|
|
1351
|
+
) }),
|
|
1352
|
+
/* @__PURE__ */ jsx(
|
|
1353
|
+
DropdownFieldAppendix,
|
|
1354
|
+
{
|
|
1355
|
+
"aria-busy": !(loading ?? resolvedItemsLoading) ? void 0 : "true",
|
|
1356
|
+
"aria-expanded": isOpen,
|
|
1357
|
+
clearable,
|
|
1358
|
+
onClear: handleOnClear,
|
|
1359
|
+
disabled: disabled || readOnly,
|
|
1360
|
+
focusable: false,
|
|
1361
|
+
labelClearSelected: labelClearSelectedItem,
|
|
1362
|
+
isOpen,
|
|
1363
|
+
itemIsSelected: selectedItem !== null,
|
|
1364
|
+
ariaLabelCloseList,
|
|
1365
|
+
ariaLabelOpenList,
|
|
1366
|
+
loading: false,
|
|
1367
|
+
loadingText: void 0
|
|
1368
|
+
}
|
|
1369
|
+
)
|
|
1370
|
+
]
|
|
1371
|
+
}
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
);
|
|
1375
|
+
const error = "error";
|
|
1376
|
+
const NativeDropdown = forwardRef(
|
|
1377
|
+
({
|
|
1378
|
+
className,
|
|
1379
|
+
disabled = false,
|
|
1380
|
+
disableLabelAnimation,
|
|
1381
|
+
feedback,
|
|
1382
|
+
items,
|
|
1383
|
+
label,
|
|
1384
|
+
loadingText,
|
|
1385
|
+
onChange,
|
|
1386
|
+
prepend,
|
|
1387
|
+
readOnly = false,
|
|
1388
|
+
selectedItem,
|
|
1389
|
+
style,
|
|
1390
|
+
value,
|
|
1391
|
+
variant,
|
|
1392
|
+
...rest
|
|
1393
|
+
}, ref) => {
|
|
1394
|
+
const { items: normalizedItems, loading } = useResolvedItems(items);
|
|
1395
|
+
const nativeDropdownId = useRandomId("eds-dropdown-native");
|
|
1396
|
+
return /* @__PURE__ */ jsx(
|
|
1397
|
+
BaseFormControl,
|
|
1398
|
+
{
|
|
1399
|
+
disabled,
|
|
1400
|
+
readOnly,
|
|
1401
|
+
prepend,
|
|
1402
|
+
append: /* @__PURE__ */ jsx(
|
|
1403
|
+
FieldAppend,
|
|
1404
|
+
{
|
|
1405
|
+
hidden: disabled || readOnly,
|
|
1406
|
+
loading,
|
|
1407
|
+
loadingText
|
|
1408
|
+
}
|
|
1409
|
+
),
|
|
1410
|
+
className,
|
|
1411
|
+
style,
|
|
1412
|
+
label,
|
|
1413
|
+
labelId: nativeDropdownId,
|
|
1414
|
+
variant,
|
|
1415
|
+
feedback,
|
|
1416
|
+
disableLabelAnimation,
|
|
1417
|
+
isFilled: true,
|
|
1418
|
+
children: /* @__PURE__ */ jsx(
|
|
1419
|
+
"select",
|
|
1420
|
+
{
|
|
1421
|
+
"aria-invalid": variant === "negative" || variant === error,
|
|
1422
|
+
"aria-labelledby": nativeDropdownId,
|
|
1423
|
+
"aria-busy": loading,
|
|
1424
|
+
className: "eds-form-control eds-dropdown--native",
|
|
1425
|
+
disabled: disabled || readOnly,
|
|
1426
|
+
onChange: (event) => {
|
|
1427
|
+
onChange?.({
|
|
1428
|
+
value: event.target.value,
|
|
1429
|
+
selectedItem: normalizedItems.find(
|
|
1430
|
+
(item) => item.value === event.target.value
|
|
1431
|
+
) ?? null,
|
|
1432
|
+
target: event.target
|
|
1433
|
+
});
|
|
1434
|
+
},
|
|
1435
|
+
value: value ?? selectedItem?.value ?? void 0,
|
|
1436
|
+
ref,
|
|
1437
|
+
...rest,
|
|
1438
|
+
children: normalizedItems.map((item) => /* @__PURE__ */ jsx("option", { value: item.value, children: item.label }, item.value))
|
|
1439
|
+
}
|
|
1440
|
+
)
|
|
1441
|
+
}
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
);
|
|
1445
|
+
const FieldAppend = ({
|
|
1446
|
+
loading,
|
|
1447
|
+
loadingText,
|
|
1448
|
+
hidden
|
|
1449
|
+
}) => {
|
|
1800
1450
|
if (loading) {
|
|
1801
|
-
return
|
|
1802
|
-
className: "eds-dropdown-native__loading-dots"
|
|
1803
|
-
}, React.createElement(LoadingDots, {
|
|
1804
|
-
"aria-label": loadingText
|
|
1805
|
-
}));
|
|
1451
|
+
return /* @__PURE__ */ jsx("div", { className: "eds-dropdown-native__loading-dots", children: /* @__PURE__ */ jsx(LoadingDots, { "aria-label": loadingText }) });
|
|
1806
1452
|
}
|
|
1807
1453
|
if (hidden) {
|
|
1808
|
-
return
|
|
1454
|
+
return /* @__PURE__ */ jsx(Fragment, {});
|
|
1809
1455
|
}
|
|
1810
|
-
return
|
|
1811
|
-
|
|
1812
|
-
|
|
1456
|
+
return /* @__PURE__ */ jsx(DownArrowIcon, { inline: true });
|
|
1457
|
+
};
|
|
1458
|
+
warnAboutMissingStyles("dropdown", "form", "a11y", "chip");
|
|
1459
|
+
export {
|
|
1460
|
+
Dropdown,
|
|
1461
|
+
MultiSelect,
|
|
1462
|
+
NativeDropdown,
|
|
1463
|
+
SearchableDropdown
|
|
1813
1464
|
};
|
|
1814
|
-
|
|
1815
|
-
warnAboutMissingStyles('dropdown', 'form', 'a11y', 'chip');
|
|
1816
|
-
|
|
1817
|
-
export { Dropdown, MultiSelect, NativeDropdown, SearchableDropdown };
|
|
1818
1465
|
//# sourceMappingURL=dropdown.esm.js.map
|