@navikt/ds-react 5.15.0 → 5.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_docs.json +145 -1
- package/cjs/form/combobox/Combobox.js +1 -1
- package/cjs/form/combobox/ComboboxProvider.js +2 -1
- package/cjs/form/combobox/ComboboxWrapper.js +1 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +59 -41
- package/cjs/form/combobox/FilteredOptions/filtered-options-util.js +3 -1
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +15 -3
- package/cjs/form/combobox/FilteredOptions/useVirtualFocus.js +52 -32
- package/cjs/form/combobox/Input/Input.js +3 -1
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +3 -1
- package/cjs/help-text/HelpText.js +1 -1
- package/cjs/util/create-context.js +72 -0
- package/cjs/util/hooks/descendants/descendant.js +117 -0
- package/cjs/util/hooks/descendants/useDescendant.js +108 -0
- package/cjs/util/hooks/descendants/utils.js +53 -0
- package/esm/form/combobox/Combobox.js +1 -1
- package/esm/form/combobox/Combobox.js.map +1 -1
- package/esm/form/combobox/ComboboxProvider.js +2 -1
- package/esm/form/combobox/ComboboxProvider.js.map +1 -1
- package/esm/form/combobox/ComboboxWrapper.js +1 -1
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +59 -41
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/filtered-options-util.d.ts +2 -1
- package/esm/form/combobox/FilteredOptions/filtered-options-util.js +3 -1
- package/esm/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +15 -3
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.d.ts +2 -4
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.js +52 -32
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.js.map +1 -1
- package/esm/form/combobox/Input/Input.js +3 -1
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.d.ts +5 -2
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +3 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/esm/form/combobox/types.d.ts +14 -0
- package/esm/help-text/HelpText.js +1 -1
- package/esm/help-text/HelpText.js.map +1 -1
- package/esm/util/create-context.d.ts +23 -0
- package/esm/util/create-context.js +46 -0
- package/esm/util/create-context.js.map +1 -0
- package/esm/util/hooks/descendants/descendant.d.ts +47 -0
- package/esm/util/hooks/descendants/descendant.js +114 -0
- package/esm/util/hooks/descendants/descendant.js.map +1 -0
- package/esm/util/hooks/descendants/useDescendant.d.ts +14 -0
- package/esm/util/hooks/descendants/useDescendant.js +82 -0
- package/esm/util/hooks/descendants/useDescendant.js.map +1 -0
- package/esm/util/hooks/descendants/utils.d.ts +12 -0
- package/esm/util/hooks/descendants/utils.js +46 -0
- package/esm/util/hooks/descendants/utils.js.map +1 -0
- package/package.json +3 -3
- package/src/form/combobox/Combobox.tsx +1 -1
- package/src/form/combobox/ComboboxProvider.tsx +2 -0
- package/src/form/combobox/ComboboxWrapper.tsx +0 -1
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +131 -92
- package/src/form/combobox/FilteredOptions/filtered-options-util.ts +9 -2
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +22 -3
- package/src/form/combobox/FilteredOptions/useVirtualFocus.ts +63 -45
- package/src/form/combobox/Input/Input.tsx +3 -1
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +11 -1
- package/src/form/combobox/combobox.stories.tsx +36 -1
- package/src/form/combobox/combobox.test.tsx +1 -3
- package/src/form/combobox/types.ts +15 -0
- package/src/help-text/HelpText.tsx +1 -1
- package/src/util/create-context.tsx +67 -0
- package/src/util/hooks/descendants/descendant.stories.tsx +147 -0
- package/src/util/hooks/descendants/descendant.ts +161 -0
- package/src/util/hooks/descendants/useDescendant.tsx +111 -0
- package/src/util/hooks/descendants/utils.ts +56 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DescendantsManager = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* https://github.com/chakra-ui/chakra-ui/tree/5ec0be610b5a69afba01a9c22365155c1b519136/packages/components/descendant
|
|
6
|
+
*/
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*
|
|
11
|
+
* Class to manage descendants and their relative indices in the DOM.
|
|
12
|
+
* It uses `node.compareDocumentPosition(...)` under the hood
|
|
13
|
+
*/
|
|
14
|
+
class DescendantsManager {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.descendants = new Map();
|
|
17
|
+
this.register = (nodeOrOptions) => {
|
|
18
|
+
if (nodeOrOptions == null)
|
|
19
|
+
return;
|
|
20
|
+
if ((0, utils_1.isElement)(nodeOrOptions)) {
|
|
21
|
+
return this.registerNode(nodeOrOptions);
|
|
22
|
+
}
|
|
23
|
+
return (node) => {
|
|
24
|
+
this.registerNode(node, nodeOrOptions);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
this.unregister = (node) => {
|
|
28
|
+
this.descendants.delete(node);
|
|
29
|
+
const sorted = (0, utils_1.sortNodes)(Array.from(this.descendants.keys()));
|
|
30
|
+
this.assignIndex(sorted);
|
|
31
|
+
};
|
|
32
|
+
this.destroy = () => {
|
|
33
|
+
this.descendants.clear();
|
|
34
|
+
};
|
|
35
|
+
this.assignIndex = (descendants) => {
|
|
36
|
+
this.descendants.forEach((descendant) => {
|
|
37
|
+
const index = descendants.indexOf(descendant.node);
|
|
38
|
+
descendant.index = index;
|
|
39
|
+
descendant.node.dataset["index"] = descendant.index.toString();
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
this.count = () => this.descendants.size;
|
|
43
|
+
this.enabledCount = () => this.enabledValues().length;
|
|
44
|
+
this.values = () => {
|
|
45
|
+
const values = Array.from(this.descendants.values());
|
|
46
|
+
return values.sort((a, b) => a.index - b.index);
|
|
47
|
+
};
|
|
48
|
+
this.enabledValues = () => {
|
|
49
|
+
return this.values().filter((descendant) => !descendant.disabled);
|
|
50
|
+
};
|
|
51
|
+
this.item = (index) => {
|
|
52
|
+
if (this.count() === 0)
|
|
53
|
+
return undefined;
|
|
54
|
+
return this.values()[index];
|
|
55
|
+
};
|
|
56
|
+
this.enabledItem = (index) => {
|
|
57
|
+
if (this.enabledCount() === 0)
|
|
58
|
+
return undefined;
|
|
59
|
+
return this.enabledValues()[index];
|
|
60
|
+
};
|
|
61
|
+
this.first = () => this.item(0);
|
|
62
|
+
this.firstEnabled = () => this.enabledItem(0);
|
|
63
|
+
this.last = () => this.item(this.descendants.size - 1);
|
|
64
|
+
this.lastEnabled = () => {
|
|
65
|
+
const lastIndex = this.enabledValues().length - 1;
|
|
66
|
+
return this.enabledItem(lastIndex);
|
|
67
|
+
};
|
|
68
|
+
this.indexOf = (node) => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
if (!node)
|
|
71
|
+
return -1;
|
|
72
|
+
return (_b = (_a = this.descendants.get(node)) === null || _a === void 0 ? void 0 : _a.index) !== null && _b !== void 0 ? _b : -1;
|
|
73
|
+
};
|
|
74
|
+
this.enabledIndexOf = (node) => {
|
|
75
|
+
if (node == null)
|
|
76
|
+
return -1;
|
|
77
|
+
return this.enabledValues().findIndex((i) => i.node.isSameNode(node));
|
|
78
|
+
};
|
|
79
|
+
this.next = (index, loop = true) => {
|
|
80
|
+
const next = (0, utils_1.getNextIndex)(index, this.count(), loop);
|
|
81
|
+
return this.item(next);
|
|
82
|
+
};
|
|
83
|
+
this.nextEnabled = (index, loop = true) => {
|
|
84
|
+
const item = this.item(index);
|
|
85
|
+
if (!item)
|
|
86
|
+
return;
|
|
87
|
+
const enabledIndex = this.enabledIndexOf(item.node);
|
|
88
|
+
const nextEnabledIndex = (0, utils_1.getNextIndex)(enabledIndex, this.enabledCount(), loop);
|
|
89
|
+
return this.enabledItem(nextEnabledIndex);
|
|
90
|
+
};
|
|
91
|
+
this.prev = (index, loop = true) => {
|
|
92
|
+
const prev = (0, utils_1.getPrevIndex)(index, this.count() - 1, loop);
|
|
93
|
+
return this.item(prev);
|
|
94
|
+
};
|
|
95
|
+
this.prevEnabled = (index, loop = true) => {
|
|
96
|
+
const item = this.item(index);
|
|
97
|
+
if (!item)
|
|
98
|
+
return;
|
|
99
|
+
const enabledIndex = this.enabledIndexOf(item.node);
|
|
100
|
+
const prevEnabledIndex = (0, utils_1.getPrevIndex)(enabledIndex, this.enabledCount() - 1, loop);
|
|
101
|
+
return this.enabledItem(prevEnabledIndex);
|
|
102
|
+
};
|
|
103
|
+
this.registerNode = (node, options) => {
|
|
104
|
+
if (!node || this.descendants.has(node))
|
|
105
|
+
return;
|
|
106
|
+
const keys = Array.from(this.descendants.keys()).concat(node);
|
|
107
|
+
const sorted = (0, utils_1.sortNodes)(keys);
|
|
108
|
+
if (options === null || options === void 0 ? void 0 : options.disabled) {
|
|
109
|
+
options.disabled = !!options.disabled;
|
|
110
|
+
}
|
|
111
|
+
const descendant = Object.assign({ node, index: -1 }, options);
|
|
112
|
+
this.descendants.set(node, descendant);
|
|
113
|
+
this.assignIndex(sorted);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.DescendantsManager = DescendantsManager;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createDescendantContext = void 0;
|
|
27
|
+
/**
|
|
28
|
+
* https://github.com/chakra-ui/chakra-ui/tree/5ec0be610b5a69afba01a9c22365155c1b519136/packages/components/descendant
|
|
29
|
+
*/
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const create_context_1 = require("../../create-context");
|
|
32
|
+
const useClientLayoutEffect_1 = require("../useClientLayoutEffect");
|
|
33
|
+
const useMergeRefs_1 = require("../useMergeRefs");
|
|
34
|
+
const descendant_1 = require("./descendant");
|
|
35
|
+
const utils_1 = require("./utils");
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
* Initializing DescendantsManager
|
|
39
|
+
*/
|
|
40
|
+
function useDescendants() {
|
|
41
|
+
const descendants = (0, react_1.useRef)(new descendant_1.DescendantsManager()).current;
|
|
42
|
+
(0, useClientLayoutEffect_1.useClientLayoutEffect)(() => {
|
|
43
|
+
return () => {
|
|
44
|
+
descendants.destroy();
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
return descendants;
|
|
48
|
+
}
|
|
49
|
+
const [DescendantsContextProvider, useDescendantsContext] = (0, create_context_1.createContext)({
|
|
50
|
+
name: "DescendantsProvider",
|
|
51
|
+
errorMessage: "useDescendantsContext must be used within DescendantsProvider",
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
* This hook provides information to descendant component:
|
|
56
|
+
* - Index compared to other descendants
|
|
57
|
+
* - ref callback to register the descendant
|
|
58
|
+
* - Its enabled index compared to other enabled descendants
|
|
59
|
+
*/
|
|
60
|
+
function useDescendant(options) {
|
|
61
|
+
const descendants = useDescendantsContext();
|
|
62
|
+
const [index, setIndex] = (0, react_1.useState)(-1);
|
|
63
|
+
const ref = (0, react_1.useRef)(null);
|
|
64
|
+
(0, useClientLayoutEffect_1.useClientLayoutEffect)(() => {
|
|
65
|
+
return () => {
|
|
66
|
+
if (!ref.current)
|
|
67
|
+
return;
|
|
68
|
+
descendants.unregister(ref.current);
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
(0, useClientLayoutEffect_1.useClientLayoutEffect)(() => {
|
|
72
|
+
if (!ref.current)
|
|
73
|
+
return;
|
|
74
|
+
const dataIndex = Number(ref.current.dataset["index"]);
|
|
75
|
+
if (index != dataIndex && !Number.isNaN(dataIndex)) {
|
|
76
|
+
setIndex(dataIndex);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const refCallback = options
|
|
80
|
+
? (0, utils_1.cast)(descendants.register(options))
|
|
81
|
+
: (0, utils_1.cast)(descendants.register);
|
|
82
|
+
return {
|
|
83
|
+
descendants,
|
|
84
|
+
index,
|
|
85
|
+
enabledIndex: descendants.enabledIndexOf(ref.current),
|
|
86
|
+
register: (0, useMergeRefs_1.mergeRefs)([refCallback, ref]),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Provides strongly typed versions of the context provider and hooks above.
|
|
91
|
+
*/
|
|
92
|
+
function createDescendantContext() {
|
|
93
|
+
const ContextProvider = (0, utils_1.cast)((props) => (react_1.default.createElement(DescendantsContextProvider, Object.assign({}, props.value), props.children)));
|
|
94
|
+
const _useDescendantsContext = () => (0, utils_1.cast)(useDescendantsContext());
|
|
95
|
+
const _useDescendant = (options) => useDescendant(options);
|
|
96
|
+
const _useDescendants = () => useDescendants();
|
|
97
|
+
return [
|
|
98
|
+
// context provider
|
|
99
|
+
ContextProvider,
|
|
100
|
+
// call this when you need to read from context
|
|
101
|
+
_useDescendantsContext,
|
|
102
|
+
// descendants state information, to be called and passed to `ContextProvider`
|
|
103
|
+
_useDescendants,
|
|
104
|
+
// descendant index information
|
|
105
|
+
_useDescendant,
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
exports.createDescendantContext = createDescendantContext;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cast = exports.getPrevIndex = exports.getNextIndex = exports.isElement = exports.sortNodes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sort an array of DOM nodes according to the HTML tree order
|
|
6
|
+
* @see http://www.w3.org/TR/html5/infrastructure.html#tree-order
|
|
7
|
+
* Inspired by
|
|
8
|
+
* - https://github.com/floating-ui/floating-ui/blob/8e449abb0bfda143c6a6eb01d3e6943c095b744f/packages/react/src/components/FloatingList.tsx#L8
|
|
9
|
+
* - https://github.com/chakra-ui/chakra-ui/tree/5ec0be610b5a69afba01a9c22365155c1b519136/packages/components/descendant
|
|
10
|
+
*/
|
|
11
|
+
function sortNodes(nodes) {
|
|
12
|
+
return nodes.sort((a, b) => {
|
|
13
|
+
const compare = a.compareDocumentPosition(b);
|
|
14
|
+
if (compare & Node.DOCUMENT_POSITION_FOLLOWING ||
|
|
15
|
+
compare & Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
16
|
+
// a < b
|
|
17
|
+
return -1;
|
|
18
|
+
}
|
|
19
|
+
if (compare & Node.DOCUMENT_POSITION_PRECEDING ||
|
|
20
|
+
compare & Node.DOCUMENT_POSITION_CONTAINS) {
|
|
21
|
+
// a > b
|
|
22
|
+
return 1;
|
|
23
|
+
}
|
|
24
|
+
if (compare & Node.DOCUMENT_POSITION_DISCONNECTED ||
|
|
25
|
+
compare & Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC) {
|
|
26
|
+
throw Error("Cannot sort the given nodes.");
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.sortNodes = sortNodes;
|
|
34
|
+
const isElement = (el) => typeof el == "object" &&
|
|
35
|
+
"nodeType" in el &&
|
|
36
|
+
el.nodeType === Node.ELEMENT_NODE;
|
|
37
|
+
exports.isElement = isElement;
|
|
38
|
+
function getNextIndex(current, max, loop) {
|
|
39
|
+
let next = current + 1;
|
|
40
|
+
if (loop && next >= max)
|
|
41
|
+
next = 0;
|
|
42
|
+
return next;
|
|
43
|
+
}
|
|
44
|
+
exports.getNextIndex = getNextIndex;
|
|
45
|
+
function getPrevIndex(current, max, loop) {
|
|
46
|
+
let next = current - 1;
|
|
47
|
+
if (loop && next < 0)
|
|
48
|
+
next = max;
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
exports.getPrevIndex = getPrevIndex;
|
|
52
|
+
const cast = (value) => value;
|
|
53
|
+
exports.cast = cast;
|
|
@@ -38,7 +38,7 @@ export const Combobox = forwardRef((props, ref) => {
|
|
|
38
38
|
}), id: inputDescriptionId, size: size }, description)),
|
|
39
39
|
React.createElement("div", { className: "navds-combobox__wrapper" },
|
|
40
40
|
React.createElement("div", { className: cl("navds-combobox__wrapper-inner navds-text-field__input", {
|
|
41
|
-
"navds-combobox__wrapper-inner--virtually-unfocused": activeDecendantId !==
|
|
41
|
+
"navds-combobox__wrapper-inner--virtually-unfocused": activeDecendantId !== undefined,
|
|
42
42
|
}), onClick: focusInput },
|
|
43
43
|
!shouldShowSelectedOptions ? (React.createElement(Input, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName }, rest))) : (React.createElement(SelectedOptions, { selectedOptions: selectedOptions, size: size },
|
|
44
44
|
React.createElement(Input, Object.assign({ id: inputProps.id, ref: mergedInputRef, inputClassName: inputClassName }, rest)))),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.js","sourceRoot":"","sources":["../../../src/form/combobox/Combobox.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,eAAe,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,eAAe,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AACrF,OAAO,gBAAgB,MAAM,oBAAoB,CAAC;AAGlD,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAGhC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACf,MAAM,EACJ,SAAS,EACT,SAAS,GAAG,KAAK,EACjB,WAAW,EACX,KAAK,EACL,WAAW,GAAG,IAAI,EAClB,gBAAgB,EAChB,gBAAg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AAC,CACF,oBAAC,eAAe,IAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI;oBAC3D,oBAAC,KAAK,kBACJ,EAAE,EAAE,UAAU,CAAC,EAAE,EACjB,GAAG,EAAE,cAAc,EACnB,cAAc,EAAE,cAAc,IAC1B,IAAI,EACR,CACc,CACnB;gBACD;oBACG,KAAK,IAAI,WAAW,IAAI,CACvB,oBAAC,WAAW,IACV,WAAW,EAAE,UAAU,EACvB,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,CAAC,CAAC,GACZ,CACH;oBACA,gBAAgB,IAAI,CACnB,oBAAC,gBAAgB,IACf,qBAAqB,EAAE,qBAAqB,EAC5C,GAAG,EAAE,mBAAmB,GACxB,CACH,CACG,CACF;YACN,oBAAC,eAAe,OAAG,CACf;QACN,6BACE,SAAS,EAAC,yBAAyB,EACnC,EAAE,EAAE,OAAO,mBACG,oBAAoB,eACxB,QAAQ,IAEjB,YAAY,IAAI,oBAAC,YAAY,IAAC,IAAI,EAAE,IAAI,IAAG,KAAK,CAAgB,CAC7D,CACU,CACnB,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,eAAe,QAAQ,CAAC"}
|
|
@@ -38,7 +38,7 @@ import { CustomOptionsProvider } from "./customOptionsContext";
|
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
const ComboboxProvider = forwardRef((props, ref) => {
|
|
41
|
-
const { allowNewValues = false, children, defaultValue, error, errorId, filteredOptions, id, isListOpen, isLoading = false, isMultiSelect, onToggleSelected, selectedOptions, options, value, onChange, onClear, shouldAutocomplete, size } = props, rest = __rest(props, ["allowNewValues", "children", "defaultValue", "error", "errorId", "filteredOptions", "id", "isListOpen", "isLoading", "isMultiSelect", "onToggleSelected", "selectedOptions", "options", "value", "onChange", "onClear", "shouldAutocomplete", "size"]);
|
|
41
|
+
const { allowNewValues = false, children, defaultValue, error, errorId, filteredOptions, id, isListOpen, isLoading = false, isMultiSelect, onToggleSelected, selectedOptions, maxSelected, options, value, onChange, onClear, shouldAutocomplete, size } = props, rest = __rest(props, ["allowNewValues", "children", "defaultValue", "error", "errorId", "filteredOptions", "id", "isListOpen", "isLoading", "isMultiSelect", "onToggleSelected", "selectedOptions", "maxSelected", "options", "value", "onChange", "onClear", "shouldAutocomplete", "size"]);
|
|
42
42
|
return (React.createElement(InputContextProvider, { value: {
|
|
43
43
|
defaultValue,
|
|
44
44
|
error,
|
|
@@ -55,6 +55,7 @@ const ComboboxProvider = forwardRef((props, ref) => {
|
|
|
55
55
|
allowNewValues,
|
|
56
56
|
isMultiSelect,
|
|
57
57
|
selectedOptions,
|
|
58
|
+
maxSelected,
|
|
58
59
|
onToggleSelected,
|
|
59
60
|
options,
|
|
60
61
|
} },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxProvider.js","sourceRoot":"","sources":["../../../src/form/combobox/ComboboxProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACb,MAAM,EACJ,cAAc,GAAG,KAAK,EACtB,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,eAAe,EACf,EAAE,EACF,UAAU,EACV,SAAS,GAAG,KAAK,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,OAAO,EACP,KAAK,EACL,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,IAAI,KAEF,KAAK,EADJ,IAAI,UACL,KAAK,
|
|
1
|
+
{"version":3,"file":"ComboboxProvider.js","sourceRoot":"","sources":["../../../src/form/combobox/ComboboxProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,gBAAgB,GAAG,UAAU,CACjC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACb,MAAM,EACJ,cAAc,GAAG,KAAK,EACtB,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,eAAe,EACf,EAAE,EACF,UAAU,EACV,SAAS,GAAG,KAAK,EACjB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,OAAO,EACP,KAAK,EACL,QAAQ,EACR,OAAO,EACP,kBAAkB,EAClB,IAAI,KAEF,KAAK,EADJ,IAAI,UACL,KAAK,EArBH,sQAqBL,CAAQ,CAAC;IACV,OAAO,CACL,oBAAC,oBAAoB,IACnB,KAAK,EAAE;YACL,YAAY;YACZ,KAAK;YACL,OAAO;YACP,EAAE;YACF,KAAK;YACL,QAAQ;YACR,OAAO;YACP,kBAAkB;YAClB,IAAI;SACL;QAED,oBAAC,qBAAqB,IAAC,KAAK,EAAE,EAAE,aAAa,EAAE;YAC7C,oBAAC,uBAAuB,IACtB,KAAK,EAAE;oBACL,cAAc;oBACd,aAAa;oBACb,eAAe;oBACf,WAAW;oBACX,gBAAgB;oBAChB,OAAO;iBACR;gBAED,oBAAC,uBAAuB,IACtB,KAAK,EAAE;wBACL,cAAc;wBACd,eAAe;wBACf,UAAU;wBACV,SAAS;wBACT,OAAO;qBACR;oBAED,oBAAC,QAAQ,kBAAC,GAAG,EAAE,GAAG,IAAM,IAAI,GACzB,QAAQ,CACA,CACa,CACF,CACJ,CACH,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -22,7 +22,7 @@ const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize,
|
|
|
22
22
|
"navds-combobox--error": hasError,
|
|
23
23
|
"navds-combobox--disabled": !!inputProps.disabled,
|
|
24
24
|
"navds-combobox--focused": hasFocusWithin,
|
|
25
|
-
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper
|
|
25
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper }, children));
|
|
26
26
|
};
|
|
27
27
|
export default ComboboxWrapper;
|
|
28
28
|
//# sourceMappingURL=ComboboxWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxWrapper.js","sourceRoot":"","sources":["../../../src/form/combobox/ComboboxWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAchD,MAAM,eAAe,GAAG,CAAC,EACvB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACE,EAAE,EAAE;IACzB,MAAM,UAAU,GAAG,MAAM,CAAwB,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,oBAAoB,CAAC,CAAC;;QAC7B,IACE,CAAC,CAAA,MAAA,UAAU,CAAC,OA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QAAQ,CAAC,KAAK,CAAC,CAAC;IAE5D,SAAS,oBAAoB,CAAC,CAAC;;QAC7B,IACE,CAAC,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;YAC9C,CAAA,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,OAAO,MAAK,CAAC,CAAC,MAAM,EACzC,CAAC;YACD,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvB,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,SAAS,aAAa,CAAC,CAAC;;QACtB,IAAI,CAAC,CAAA,MAAA,UAAU,CAAC,OAAO,0CAAE,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA,EAAE,CAAC;YACnD,gBAAgB,CAAC,KAAK,CAAC,CAAC;YACxB,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,OAAO,CACL,6BACE,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,EAAE,CACX,SAAS,EACT,kBAAkB,EAClB,qBAAqB,SAAS,EAAE,EAChC;YACE,uBAAuB,EAAE,QAAQ;YACjC,0BAA0B,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ;YACjD,yBAAyB,EAAE,cAAc;SAC1C,CACF,EACD,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,aAAa,IAEpB,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -8,51 +8,69 @@ import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsCon
|
|
|
8
8
|
import filteredOptionsUtil from "./filtered-options-util";
|
|
9
9
|
import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
|
10
10
|
const FilteredOptions = () => {
|
|
11
|
+
var _a;
|
|
11
12
|
const { inputProps: { id }, size, value, } = useInputContext();
|
|
12
13
|
const { allowNewValues, isLoading, isListOpen, filteredOptions, setFilteredOptionsRef, isMouseLastUsedInputDevice, setIsMouseLastUsedInputDevice, isValueNew, toggleIsListOpen, activeDecendantId, virtualFocus, } = useFilteredOptionsContext();
|
|
13
|
-
const { isMultiSelect, selectedOptions, toggleOption } = useSelectedOptionsContext();
|
|
14
|
-
|
|
14
|
+
const { isMultiSelect, selectedOptions, toggleOption, maxSelected } = useSelectedOptionsContext();
|
|
15
|
+
const isDisabled = (option) => (maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached) && !selectedOptions.includes(option);
|
|
16
|
+
const shouldRenderNonSelectables = (maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached) || // Render maxSelected message
|
|
17
|
+
isLoading || // Render loading message
|
|
18
|
+
(!isLoading && filteredOptions.length === 0); // Render no hits message
|
|
19
|
+
const shouldRenderFilteredOptionsList = (allowNewValues && isValueNew && !(maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached)) || // Render add new option
|
|
20
|
+
filteredOptions.length > 0; // Render filtered options
|
|
21
|
+
return (React.createElement("div", { className: cl("navds-combobox__list", {
|
|
15
22
|
"navds-combobox__list--closed": !isListOpen,
|
|
16
23
|
"navds-combobox__list--with-hover": isMouseLastUsedInputDevice,
|
|
17
|
-
}), id: filteredOptionsUtil.getFilteredOptionsId(id),
|
|
18
|
-
|
|
19
|
-
React.createElement(
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
24
|
+
}), id: filteredOptionsUtil.getFilteredOptionsId(id), tabIndex: -1 },
|
|
25
|
+
shouldRenderNonSelectables && (React.createElement("div", { className: "navds-combobox__list_non-selectables", role: "status" },
|
|
26
|
+
(maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached) && (React.createElement("div", { className: "navds-combobox__list-item--max-selected", id: filteredOptionsUtil.getMaxSelectedOptionsId(id) }, (_a = maxSelected.message) !== null && _a !== void 0 ? _a : `${selectedOptions.length} av ${maxSelected.limit} er valgt.`)),
|
|
27
|
+
isLoading && (React.createElement("div", { className: "navds-combobox__list-item--loading", id: filteredOptionsUtil.getIsLoadingId(id) },
|
|
28
|
+
React.createElement(Loader, { title: "S\u00F8ker..." }))),
|
|
29
|
+
!isLoading && filteredOptions.length === 0 && (React.createElement("div", { className: "navds-combobox__list-item--no-options", id: filteredOptionsUtil.getNoHitsId(id) }, "Ingen s\u00F8ketreff")))),
|
|
30
|
+
shouldRenderFilteredOptionsList && (React.createElement("ul", { ref: setFilteredOptionsRef, role: "listbox", className: "navds-combobox__list-options" },
|
|
31
|
+
isValueNew && !(maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached) && allowNewValues && (React.createElement("li", { tabIndex: -1, onMouseMove: () => {
|
|
32
|
+
if (activeDecendantId !==
|
|
33
|
+
filteredOptionsUtil.getAddNewOptionId(id)) {
|
|
34
|
+
virtualFocus.moveFocusToElement(filteredOptionsUtil.getAddNewOptionId(id));
|
|
35
|
+
setIsMouseLastUsedInputDevice(true);
|
|
36
|
+
}
|
|
37
|
+
}, onPointerUp: (event) => {
|
|
38
|
+
toggleOption(value, event);
|
|
39
|
+
if (!isMultiSelect && !selectedOptions.includes(value))
|
|
40
|
+
toggleIsListOpen(false);
|
|
41
|
+
}, id: filteredOptionsUtil.getAddNewOptionId(id), className: cl("navds-combobox__list-item navds-combobox__list-item--new-option", {
|
|
42
|
+
"navds-combobox__list-item--new-option--focus": activeDecendantId ===
|
|
43
|
+
filteredOptionsUtil.getAddNewOptionId(id),
|
|
44
|
+
}), role: "option", "aria-selected": false },
|
|
45
|
+
React.createElement(PlusIcon, { "aria-hidden": true }),
|
|
46
|
+
React.createElement(BodyShort, { size: size },
|
|
47
|
+
"Legg til",
|
|
48
|
+
" ",
|
|
49
|
+
React.createElement(Label, { as: "span", size: size },
|
|
50
|
+
"\u201C",
|
|
51
|
+
value,
|
|
52
|
+
"\u201D")))),
|
|
53
|
+
filteredOptions.map((option) => (React.createElement("li", { className: cl("navds-combobox__list-item", {
|
|
54
|
+
"navds-combobox__list-item--focus": activeDecendantId ===
|
|
55
|
+
filteredOptionsUtil.getOptionId(id, option),
|
|
56
|
+
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
57
|
+
}), "data-no-focus": isDisabled(option) || undefined, id: filteredOptionsUtil.getOptionId(id, option), key: option, tabIndex: -1, onMouseMove: () => {
|
|
58
|
+
if (activeDecendantId !==
|
|
59
|
+
filteredOptionsUtil.getOptionId(id, option)) {
|
|
60
|
+
virtualFocus.moveFocusToElement(filteredOptionsUtil.getOptionId(id, option));
|
|
61
|
+
setIsMouseLastUsedInputDevice(true);
|
|
62
|
+
}
|
|
63
|
+
}, onPointerUp: (event) => {
|
|
64
|
+
if (isDisabled(option)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
toggleOption(option, event);
|
|
68
|
+
if (!isMultiSelect && !selectedOptions.includes(option)) {
|
|
69
|
+
toggleIsListOpen(false);
|
|
70
|
+
}
|
|
71
|
+
}, role: "option", "aria-selected": selectedOptions.includes(option), "aria-disabled": isDisabled(option) || undefined },
|
|
72
|
+
React.createElement(BodyShort, { size: size }, option),
|
|
73
|
+
selectedOptions.includes(option) && React.createElement(CheckmarkIcon, null))))))));
|
|
56
74
|
};
|
|
57
75
|
export default FilteredOptions;
|
|
58
76
|
//# sourceMappingURL=FilteredOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,mBAAmB,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,eAAe,GAAG,GAAG,EAAE
|
|
1
|
+
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,mBAAmB,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,eAAe,GAAG,GAAG,EAAE;;IAC3B,MAAM,EAC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AAC,EACD,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;oBACrB,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;wBACvB,OAAO;oBACT,CAAC;oBACD,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;oBAC5B,IAAI,CAAC,aAAa,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;wBACxD,gBAAgB,CAAC,KAAK,CAAC,CAAC;oBAC1B,CAAC;gBACH,CAAC,EACD,IAAI,EAAC,QAAQ,mBACE,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,mBAChC,UAAU,CAAC,MAAM,CAAC,IAAI,SAAS;gBAE9C,oBAAC,SAAS,IAAC,IAAI,EAAE,IAAI,IAAG,MAAM,CAAa;gBAC1C,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,oBAAC,aAAa,OAAG,CACnD,CACN,CAAC,CACC,CACN,CACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -2,11 +2,12 @@ declare const _default: {
|
|
|
2
2
|
normalizeText: (text: string) => string;
|
|
3
3
|
isPartOfText: (value: any, text: any) => boolean;
|
|
4
4
|
isValueInList: (value: any, list: any) => any;
|
|
5
|
-
getMatchingValuesFromList: (value: any, list: any) => any;
|
|
5
|
+
getMatchingValuesFromList: (value: any, list: any, alwaysIncluded: any) => any;
|
|
6
6
|
getFilteredOptionsId: (comboboxId: string) => string;
|
|
7
7
|
getAddNewOptionId: (comboboxId: string) => string;
|
|
8
8
|
getOptionId: (comboboxId: string, option: string) => string;
|
|
9
9
|
getIsLoadingId: (comboboxId: string) => string;
|
|
10
10
|
getNoHitsId: (comboboxId: string) => string;
|
|
11
|
+
getMaxSelectedOptionsId: (comboboxId: string) => string;
|
|
11
12
|
};
|
|
12
13
|
export default _default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const normalizeText = (text) => typeof text === "string" ? text.toLocaleLowerCase().trim() : "";
|
|
2
2
|
const isPartOfText = (value, text) => normalizeText(text).startsWith(normalizeText(value !== null && value !== void 0 ? value : ""));
|
|
3
3
|
const isValueInList = (value, list) => list === null || list === void 0 ? void 0 : list.find((listItem) => normalizeText(value) === normalizeText(listItem));
|
|
4
|
-
const getMatchingValuesFromList = (value, list) => list === null || list === void 0 ? void 0 : list.filter((listItem) => isPartOfText(value, listItem));
|
|
4
|
+
const getMatchingValuesFromList = (value, list, alwaysIncluded) => list === null || list === void 0 ? void 0 : list.filter((listItem) => isPartOfText(value, listItem) || alwaysIncluded.includes(listItem));
|
|
5
5
|
const getFilteredOptionsId = (comboboxId) => `${comboboxId}-filtered-options`;
|
|
6
6
|
const getOptionId = (comboboxId, option) => `${comboboxId.toLocaleLowerCase()}-option-${option
|
|
7
7
|
.replace(" ", "-")
|
|
@@ -9,6 +9,7 @@ const getOptionId = (comboboxId, option) => `${comboboxId.toLocaleLowerCase()}-o
|
|
|
9
9
|
const getAddNewOptionId = (comboboxId) => `${comboboxId}-combobox-new-option`;
|
|
10
10
|
const getIsLoadingId = (comboboxId) => `${comboboxId}-is-loading`;
|
|
11
11
|
const getNoHitsId = (comboboxId) => `${comboboxId}-no-hits`;
|
|
12
|
+
const getMaxSelectedOptionsId = (comboboxId) => `${comboboxId}-max-selected-options`;
|
|
12
13
|
export default {
|
|
13
14
|
normalizeText,
|
|
14
15
|
isPartOfText,
|
|
@@ -19,5 +20,6 @@ export default {
|
|
|
19
20
|
getOptionId,
|
|
20
21
|
getIsLoadingId,
|
|
21
22
|
getNoHitsId,
|
|
23
|
+
getMaxSelectedOptionsId,
|
|
22
24
|
};
|
|
23
25
|
//# sourceMappingURL=filtered-options-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filtered-options-util.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/filtered-options-util.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU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,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE7E,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,CAChE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CACV,CAAC,QAAQ,EAAE,EAAE,CACX,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACrE,CAAC;AAEJ,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAE,EAAE,CAClD,GAAG,UAAU,mBAAmB,CAAC;AAEnC,MAAM,WAAW,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAE,EAAE,CACzD,GAAG,UAAU,CAAC,iBAAiB,EAAE,WAAW,MAAM;KAC/C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;KACjB,iBAAiB,EAAE,EAAE,CAAC;AAE3B,MAAM,iBAAiB,GAAG,CAAC,UAAkB,EAAE,EAAE,CAC/C,GAAG,UAAU,sBAAsB,CAAC;AAEtC,MAAM,cAAc,GAAG,CAAC,UAAkB,EAAE,EAAE,CAAC,GAAG,UAAU,aAAa,CAAC;AAE1E,MAAM,WAAW,GAAG,CAAC,UAAkB,EAAE,EAAE,CAAC,GAAG,UAAU,UAAU,CAAC;AAEpE,MAAM,uBAAuB,GAAG,CAAC,UAAkB,EAAE,EAAE,CACrD,GAAG,UAAU,uBAAuB,CAAC;AAEvC,eAAe;IACb,aAAa;IACb,YAAY;IACZ,aAAa;IACb,yBAAyB;IACzB,oBAAoB;IACpB,iBAAiB;IACjB,WAAW;IACX,cAAc;IACd,WAAW;IACX,uBAAuB;CACxB,CAAC"}
|
|
@@ -2,6 +2,7 @@ import cl from "clsx";
|
|
|
2
2
|
import React, { createContext, useCallback, useContext, useMemo, useState, } from "react";
|
|
3
3
|
import { useClientLayoutEffect, usePrevious } from "../../../util/hooks";
|
|
4
4
|
import { useInputContext } from "../Input/inputContext";
|
|
5
|
+
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
5
6
|
import { useCustomOptionsContext } from "../customOptionsContext";
|
|
6
7
|
import filteredOptionsUtils from "./filtered-options-util";
|
|
7
8
|
import useVirtualFocus from "./useVirtualFocus";
|
|
@@ -11,6 +12,7 @@ export const FilteredOptionsProvider = ({ children, value: props, }) => {
|
|
|
11
12
|
const [filteredOptionsRef, setFilteredOptionsRef] = useState(null);
|
|
12
13
|
const virtualFocus = useVirtualFocus(filteredOptionsRef);
|
|
13
14
|
const { inputProps: { "aria-describedby": partialAriaDescribedBy, id }, value, searchTerm, setValue, setSearchTerm, shouldAutocomplete, } = useInputContext();
|
|
15
|
+
const { selectedOptions, maxSelected } = useSelectedOptionsContext();
|
|
14
16
|
const [isInternalListOpen, setInternalListOpen] = useState(false);
|
|
15
17
|
const { customOptions } = useCustomOptionsContext();
|
|
16
18
|
const filteredOptions = useMemo(() => {
|
|
@@ -18,8 +20,14 @@ export const FilteredOptionsProvider = ({ children, value: props, }) => {
|
|
|
18
20
|
return externalFilteredOptions;
|
|
19
21
|
}
|
|
20
22
|
const opts = [...customOptions, ...options];
|
|
21
|
-
return filteredOptionsUtils.getMatchingValuesFromList(searchTerm, opts);
|
|
22
|
-
}, [
|
|
23
|
+
return filteredOptionsUtils.getMatchingValuesFromList(searchTerm, opts, selectedOptions);
|
|
24
|
+
}, [
|
|
25
|
+
customOptions,
|
|
26
|
+
externalFilteredOptions,
|
|
27
|
+
options,
|
|
28
|
+
searchTerm,
|
|
29
|
+
selectedOptions,
|
|
30
|
+
]);
|
|
23
31
|
const previousSearchTerm = usePrevious(searchTerm);
|
|
24
32
|
const [isMouseLastUsedInputDevice, setIsMouseLastUsedInputDevice] = useState(false);
|
|
25
33
|
const filteredOptionsMap = useMemo(() => options.reduce((map, _option) => (Object.assign(Object.assign({}, map), { [filteredOptionsUtils.getOptionId(id, _option)]: _option })), {
|
|
@@ -65,10 +73,14 @@ export const FilteredOptionsProvider = ({ children, value: props, }) => {
|
|
|
65
73
|
activeOption = filteredOptionsUtils.getIsLoadingId(id);
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
|
-
|
|
76
|
+
const maybeMaxSelectedOptionsId = (maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached) &&
|
|
77
|
+
filteredOptionsUtils.getMaxSelectedOptionsId(id);
|
|
78
|
+
return (cl(activeOption, maybeMaxSelectedOptionsId, partialAriaDescribedBy) ||
|
|
79
|
+
undefined);
|
|
69
80
|
}, [
|
|
70
81
|
isListOpen,
|
|
71
82
|
isLoading,
|
|
83
|
+
maxSelected === null || maxSelected === void 0 ? void 0 : maxSelected.isLimitReached,
|
|
72
84
|
value,
|
|
73
85
|
partialAriaDescribedBy,
|
|
74
86
|
shouldAutocomplete,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filteredOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/filteredOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAEZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,eAAqC,MAAM,mBAAmB,CAAC;AAgCtE,MAAM,sBAAsB,GAAG,aAAa,CAC1C,EAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,EACR,KAAK,EAAE,KAAK,GACS,EAAE,EAAE;IACzB,MAAM,EACJ,cAAc,EACd,eAAe,EAAE,uBAAuB,EACxC,UAAU,EAAE,kBAAkB,EAC9B,SAAS,EACT,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAC/C,QAAQ,CAA0B,IAAI,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAAC;IACzD,MAAM,EACJ,UAAU,EAAE,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,EAAE,EAAE,EAC9D,KAAK,EACL,UAAU,EACV,QAAQ,EACR,aAAa,EACb,kBAAkB,GACnB,GAAG,eAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"filteredOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/filteredOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAEZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,eAAqC,MAAM,mBAAmB,CAAC;AAgCtE,MAAM,sBAAsB,GAAG,aAAa,CAC1C,EAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,EACR,KAAK,EAAE,KAAK,GACS,EAAE,EAAE;IACzB,MAAM,EACJ,cAAc,EACd,eAAe,EAAE,uBAAuB,EACxC,UAAU,EAAE,kBAAkB,EAC9B,SAAS,EACT,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,kBAA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