@digdir/designsystemet-react 0.54.0 → 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/form/Combobox/Combobox.js +12 -13
- package/dist/cjs/components/form/Combobox/internal/ComboboxClearButton.js +2 -2
- package/dist/cjs/components/form/Combobox/internal/ComboboxInput.js +3 -2
- package/dist/cjs/components/form/Combobox/useCombobox.js +24 -33
- package/dist/cjs/react-css-modules.css +1 -0
- package/dist/esm/components/form/Combobox/Combobox.js +12 -13
- package/dist/esm/components/form/Combobox/internal/ComboboxClearButton.js +2 -2
- package/dist/esm/components/form/Combobox/internal/ComboboxInput.js +3 -2
- package/dist/esm/components/form/Combobox/useCombobox.js +26 -17
- package/dist/esm/react-css-modules.css +1 -0
- package/dist/types/components/form/Combobox/Combobox.d.ts +32 -1
- package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/useCombobox.d.ts +13 -9
- package/dist/types/components/form/Combobox/useCombobox.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -21,7 +21,7 @@ var floatingUi_dom = require('../../../node_modules/@floating-ui/dom/dist/floati
|
|
|
21
21
|
var floatingUi_core = require('../../../node_modules/@floating-ui/core/dist/floating-ui.core.js');
|
|
22
22
|
var objectUtils = require('../../../utilities/objectUtils.js');
|
|
23
23
|
|
|
24
|
-
const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = false, description, multiple = false, size = 'medium', disabled = false, readOnly = false, hideChips = false, cleanButtonLabel = 'Fjern alt', error, errorId, id, name, portal = true, htmlSize = 0, virtual = false, children, style, loading, loadingLabel = 'Laster...', filter = (inputValue, option) => {
|
|
24
|
+
const Combobox = React.forwardRef(({ value, initialValue = [], onValueChange, label, hideLabel = false, description, multiple = false, size = 'medium', disabled = false, readOnly = false, hideChips = false, cleanButtonLabel = 'Fjern alt', clearButtonLabel = 'Fjern alt', hideClearButton = false, error, errorId, id, name, portal = true, htmlSize = 0, virtual = false, children, style, loading, loadingLabel = 'Laster...', filter = (inputValue, option) => {
|
|
25
25
|
return option.label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
26
26
|
}, chipSrLabel = (option) => 'Slett ' + option.label, className, ...rest }, forwareddRef) => {
|
|
27
27
|
const inputRef = React.useRef(null);
|
|
@@ -30,9 +30,14 @@ const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = fa
|
|
|
30
30
|
const [open, setOpen] = React.useState(false);
|
|
31
31
|
const [inputValue, setInputValue] = React.useState(rest.inputValue || '');
|
|
32
32
|
const [activeIndex, setActiveIndex] = React.useState(null);
|
|
33
|
-
const
|
|
33
|
+
const { selectedOptions, setSelectedOptions, options, optionsChildren, restChildren, optionValues, customIds, prevSelectedHash, setPrevSelectedHash, } = useCombobox.default({
|
|
34
|
+
children,
|
|
35
|
+
inputValue,
|
|
36
|
+
filter,
|
|
37
|
+
multiple,
|
|
38
|
+
initialValue,
|
|
39
|
+
});
|
|
34
40
|
const [activeDescendant, setActiveDescendant] = React.useState(undefined);
|
|
35
|
-
const [prevSelectedHash, setPrevSelectedHash] = React.useState(JSON.stringify(selectedOptions));
|
|
36
41
|
React.useEffect(() => {
|
|
37
42
|
if (rest.inputValue !== undefined) {
|
|
38
43
|
setInputValue(rest.inputValue);
|
|
@@ -48,13 +53,6 @@ const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = fa
|
|
|
48
53
|
id,
|
|
49
54
|
}, 'combobox');
|
|
50
55
|
const listRef = React.useRef([]);
|
|
51
|
-
const { options, optionsChildren, restChildren, optionValues, customIds } = useCombobox.default({
|
|
52
|
-
children,
|
|
53
|
-
inputValue,
|
|
54
|
-
filter,
|
|
55
|
-
multiple,
|
|
56
|
-
selectedOptions,
|
|
57
|
-
});
|
|
58
56
|
// if value is set, set input value to the label of the value
|
|
59
57
|
React.useEffect(() => {
|
|
60
58
|
if (value && value.length > 0 && !multiple) {
|
|
@@ -110,7 +108,7 @@ const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = fa
|
|
|
110
108
|
const values = selectedOptions.map((option) => option.value);
|
|
111
109
|
onValueChange?.(values);
|
|
112
110
|
setPrevSelectedHash(selectedHash);
|
|
113
|
-
}, [onValueChange, selectedOptions, prevSelectedHash]);
|
|
111
|
+
}, [onValueChange, selectedOptions, prevSelectedHash, setPrevSelectedHash]);
|
|
114
112
|
React.useEffect(() => {
|
|
115
113
|
if (value && options.length > 0) {
|
|
116
114
|
const updatedSelectedOptions = value.map((option) => {
|
|
@@ -119,7 +117,7 @@ const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = fa
|
|
|
119
117
|
});
|
|
120
118
|
setSelectedOptions(updatedSelectedOptions);
|
|
121
119
|
}
|
|
122
|
-
}, [multiple, prevSelectedHash, value, options]);
|
|
120
|
+
}, [multiple, prevSelectedHash, value, options, setSelectedOptions]);
|
|
123
121
|
// handle click on option, either select or deselect - Handles single or multiple
|
|
124
122
|
const handleSelectOption = (option) => {
|
|
125
123
|
// if option is already selected, remove it
|
|
@@ -250,7 +248,8 @@ const Combobox = React.forwardRef(({ value, onValueChange, label, hideLabel = fa
|
|
|
250
248
|
htmlSize,
|
|
251
249
|
optionValues,
|
|
252
250
|
hideChips,
|
|
253
|
-
cleanButtonLabel,
|
|
251
|
+
clearButtonLabel: cleanButtonLabel || clearButtonLabel,
|
|
252
|
+
hideClearButton,
|
|
254
253
|
listId,
|
|
255
254
|
setInputValue,
|
|
256
255
|
setActiveIndex,
|
|
@@ -16,7 +16,7 @@ const ComboboxClearButton = () => {
|
|
|
16
16
|
if (!context) {
|
|
17
17
|
throw new Error('ComboboxContext is missing');
|
|
18
18
|
}
|
|
19
|
-
const { size, readOnly, disabled,
|
|
19
|
+
const { size, readOnly, disabled, clearButtonLabel, inputRef, setSelectedOptions, setInputValue, } = context;
|
|
20
20
|
return (jsxRuntime.jsx("button", { disabled: disabled, className: clsx.clsx(Combobox_module.clearButton, Combobox_module[size], utility_module.focusable), onClick: () => {
|
|
21
21
|
if (readOnly)
|
|
22
22
|
return;
|
|
@@ -35,7 +35,7 @@ const ComboboxClearButton = () => {
|
|
|
35
35
|
setInputValue('');
|
|
36
36
|
inputRef.current?.focus();
|
|
37
37
|
}
|
|
38
|
-
}, type: 'button', "aria-label":
|
|
38
|
+
}, type: 'button', "aria-label": clearButtonLabel, children: jsxRuntime.jsx(akselIcons.XMarkIcon, { fontSize: '1.5em', title: 'Clear selection' }) }));
|
|
39
39
|
};
|
|
40
40
|
ComboboxClearButton.displayName = 'ComboboxClearButton';
|
|
41
41
|
var ComboboxClearButton$1 = ComboboxClearButton;
|
|
@@ -21,7 +21,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
21
21
|
if (!context) {
|
|
22
22
|
throw new Error('ComboboxContext is missing');
|
|
23
23
|
}
|
|
24
|
-
const { forwareddRef, listId, size, readOnly, disabled, open, inputRef, refs, inputValue, activeDescendant, error, multiple, selectedOptions, formFieldProps, htmlSize, options, hideChips, setOpen, setActiveIndex, handleKeyDown, getReferenceProps, setInputValue, handleSelectOption, } = context;
|
|
24
|
+
const { forwareddRef, listId, size, readOnly, disabled, open, inputRef, refs, inputValue, activeDescendant, error, multiple, selectedOptions, formFieldProps, htmlSize, options, hideChips, hideClearButton, setOpen, setActiveIndex, handleKeyDown, getReferenceProps, setInputValue, handleSelectOption, } = context;
|
|
25
25
|
const mergedRefs = floatingUi_react.useMergeRefs([forwareddRef, inputRef]);
|
|
26
26
|
// we need to check if input is in focus, to add focus styles to the wrapper
|
|
27
27
|
const [inputInFocus, setInputInFocus] = React.useState(false);
|
|
@@ -68,6 +68,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
68
68
|
}, 0);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
+
const showClearButton = multiple && !hideClearButton && selectedOptions.length > 0;
|
|
71
72
|
return (jsxRuntime.jsxs(Box.Box
|
|
72
73
|
/* Props from floating-ui */
|
|
73
74
|
, { ...getReferenceProps({
|
|
@@ -99,7 +100,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
99
100
|
}), "aria-disabled": disabled, className: clsx.clsx(Textfield_module.input, Combobox_module.inputWrapper, Combobox_module[size], inputInFocus && Combobox_module.inFocus, readOnly && Combobox_module.readonly, error && Combobox_module.error), children: [jsxRuntime.jsxs("div", { className: Combobox_module.chipAndInput, children: [multiple && !hideChips && jsxRuntime.jsx(ComboboxChips.default, {}), jsxRuntime.jsx("input", { ref: mergedRefs, "aria-activedescendant": activeDescendant, readOnly: readOnly, "aria-autocomplete": 'list', role: 'combobox', "aria-expanded": open, "aria-controls": listId, autoComplete: 'off', size: htmlSize, value: inputValue, ...objectUtils.omit(['style', 'className'], rest), ...formFieldProps.inputProps, onChange: (e) => {
|
|
100
101
|
onChange(e);
|
|
101
102
|
rest.onChange && rest.onChange(e);
|
|
102
|
-
} })] }),
|
|
103
|
+
} })] }), showClearButton && jsxRuntime.jsx(ComboboxClearButton.default, {}), jsxRuntime.jsx("div", { className: Combobox_module.arrow, children: open ? (jsxRuntime.jsx(akselIcons.ChevronUpIcon, { title: 'arrow up', fontSize: '1.5em' })) : (jsxRuntime.jsx(akselIcons.ChevronDownIcon, { title: 'arrow down', fontSize: '1.5em' })) })] }));
|
|
103
104
|
};
|
|
104
105
|
ComboboxInput.displayName = 'ComboboxInput';
|
|
105
106
|
var ComboboxInput$1 = ComboboxInput;
|
|
@@ -7,36 +7,27 @@ var React = require('react');
|
|
|
7
7
|
var Option = require('./Option/Option.js');
|
|
8
8
|
var Custom = require('./Custom/Custom.js');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.keys(e).forEach(function (k) {
|
|
14
|
-
if (k !== 'default') {
|
|
15
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () { return e[k]; }
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
n.default = e;
|
|
24
|
-
return Object.freeze(n);
|
|
10
|
+
const isOption = (option) => !!option;
|
|
11
|
+
function isComboboxOption(child) {
|
|
12
|
+
return React.isValidElement(child) && child.type === Option.ComboboxOption;
|
|
25
13
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
14
|
+
function isComboboxCustom(child) {
|
|
15
|
+
return React.isValidElement(child) && child.type === Custom.default;
|
|
16
|
+
}
|
|
17
|
+
function isInteractiveComboboxCustom(child) {
|
|
18
|
+
return isComboboxCustom(child) && child.props.interactive === true;
|
|
19
|
+
}
|
|
20
|
+
function useCombobox({ children, inputValue, multiple, filter, initialValue, }) {
|
|
30
21
|
const options = React.useMemo(() => {
|
|
31
22
|
const allOptions = [];
|
|
32
|
-
|
|
23
|
+
React.Children.forEach(children, (child) => {
|
|
33
24
|
if (isComboboxOption(child)) {
|
|
34
25
|
const props = child.props;
|
|
35
26
|
let label = props.displayValue || '';
|
|
36
27
|
if (!props.displayValue) {
|
|
37
28
|
let childrenLabel = '';
|
|
38
29
|
// go over children and find all strings
|
|
39
|
-
|
|
30
|
+
React.Children.forEach(props.children, (child) => {
|
|
40
31
|
if (typeof child === 'string') {
|
|
41
32
|
childrenLabel += child;
|
|
42
33
|
}
|
|
@@ -56,9 +47,14 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
56
47
|
});
|
|
57
48
|
return allOptions;
|
|
58
49
|
}, [children]);
|
|
50
|
+
const preSelectedOptions = (initialValue || [])
|
|
51
|
+
.map((value) => options.find((option) => option.value === value))
|
|
52
|
+
.filter(isOption);
|
|
53
|
+
const [selectedOptions, setSelectedOptions] = React.useState(preSelectedOptions);
|
|
54
|
+
const [prevSelectedHash, setPrevSelectedHash] = React.useState(JSON.stringify(selectedOptions));
|
|
59
55
|
const optionsChildren = React.useMemo(() => {
|
|
60
56
|
const valuesArray = Array.from(options);
|
|
61
|
-
const children_ =
|
|
57
|
+
const children_ = React.Children.toArray(children).filter((child) => isComboboxOption(child));
|
|
62
58
|
const activeValue = valuesArray.find((item) => item.label === inputValue);
|
|
63
59
|
if (activeValue && !multiple)
|
|
64
60
|
return children_;
|
|
@@ -76,7 +72,7 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
76
72
|
}, [options, children, multiple, inputValue, selectedOptions, filter]);
|
|
77
73
|
const customIds = React.useMemo(() => {
|
|
78
74
|
// find all custom components with `interactive=true` and generate random values for them
|
|
79
|
-
const children_ =
|
|
75
|
+
const children_ = React.Children.toArray(children).filter((child) => {
|
|
80
76
|
return isInteractiveComboboxCustom(child);
|
|
81
77
|
});
|
|
82
78
|
// return all ids
|
|
@@ -95,7 +91,7 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
95
91
|
return [...customIds, ...options];
|
|
96
92
|
}, [customIds, optionsChildren]);
|
|
97
93
|
const restChildren = React.useMemo(() => {
|
|
98
|
-
return
|
|
94
|
+
return React.Children.toArray(children).filter((child) => {
|
|
99
95
|
return !isComboboxOption(child);
|
|
100
96
|
});
|
|
101
97
|
}, [children]);
|
|
@@ -105,17 +101,12 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
105
101
|
restChildren,
|
|
106
102
|
options,
|
|
107
103
|
customIds,
|
|
104
|
+
selectedOptions,
|
|
105
|
+
setSelectedOptions,
|
|
106
|
+
prevSelectedHash,
|
|
107
|
+
setPrevSelectedHash,
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
|
-
function isComboboxOption(child) {
|
|
111
|
-
return React__namespace.isValidElement(child) && child.type === Option.ComboboxOption;
|
|
112
|
-
}
|
|
113
|
-
function isComboboxCustom(child) {
|
|
114
|
-
return React__namespace.isValidElement(child) && child.type === Custom.default;
|
|
115
|
-
}
|
|
116
|
-
function isInteractiveComboboxCustom(child) {
|
|
117
|
-
return isComboboxCustom(child) && child.props.interactive === true;
|
|
118
|
-
}
|
|
119
110
|
|
|
120
111
|
exports.default = useCombobox;
|
|
121
112
|
exports.isComboboxCustom = isComboboxCustom;
|
|
@@ -19,7 +19,7 @@ import { autoUpdate } from '../../../node_modules/@floating-ui/dom/dist/floating
|
|
|
19
19
|
import { flip, size, offset } from '../../../node_modules/@floating-ui/core/dist/floating-ui.core.js';
|
|
20
20
|
import { omit } from '../../../utilities/objectUtils.js';
|
|
21
21
|
|
|
22
|
-
const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, description, multiple = false, size: size$1 = 'medium', disabled = false, readOnly = false, hideChips = false, cleanButtonLabel = 'Fjern alt', error, errorId, id, name, portal = true, htmlSize = 0, virtual = false, children, style, loading, loadingLabel = 'Laster...', filter = (inputValue, option) => {
|
|
22
|
+
const Combobox = forwardRef(({ value, initialValue = [], onValueChange, label, hideLabel = false, description, multiple = false, size: size$1 = 'medium', disabled = false, readOnly = false, hideChips = false, cleanButtonLabel = 'Fjern alt', clearButtonLabel = 'Fjern alt', hideClearButton = false, error, errorId, id, name, portal = true, htmlSize = 0, virtual = false, children, style, loading, loadingLabel = 'Laster...', filter = (inputValue, option) => {
|
|
23
23
|
return option.label.toLowerCase().startsWith(inputValue.toLowerCase());
|
|
24
24
|
}, chipSrLabel = (option) => 'Slett ' + option.label, className, ...rest }, forwareddRef) => {
|
|
25
25
|
const inputRef = useRef(null);
|
|
@@ -28,9 +28,14 @@ const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, d
|
|
|
28
28
|
const [open, setOpen] = useState(false);
|
|
29
29
|
const [inputValue, setInputValue] = useState(rest.inputValue || '');
|
|
30
30
|
const [activeIndex, setActiveIndex] = useState(null);
|
|
31
|
-
const
|
|
31
|
+
const { selectedOptions, setSelectedOptions, options, optionsChildren, restChildren, optionValues, customIds, prevSelectedHash, setPrevSelectedHash, } = useCombobox({
|
|
32
|
+
children,
|
|
33
|
+
inputValue,
|
|
34
|
+
filter,
|
|
35
|
+
multiple,
|
|
36
|
+
initialValue,
|
|
37
|
+
});
|
|
32
38
|
const [activeDescendant, setActiveDescendant] = useState(undefined);
|
|
33
|
-
const [prevSelectedHash, setPrevSelectedHash] = useState(JSON.stringify(selectedOptions));
|
|
34
39
|
useEffect(() => {
|
|
35
40
|
if (rest.inputValue !== undefined) {
|
|
36
41
|
setInputValue(rest.inputValue);
|
|
@@ -46,13 +51,6 @@ const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, d
|
|
|
46
51
|
id,
|
|
47
52
|
}, 'combobox');
|
|
48
53
|
const listRef = useRef([]);
|
|
49
|
-
const { options, optionsChildren, restChildren, optionValues, customIds } = useCombobox({
|
|
50
|
-
children,
|
|
51
|
-
inputValue,
|
|
52
|
-
filter,
|
|
53
|
-
multiple,
|
|
54
|
-
selectedOptions,
|
|
55
|
-
});
|
|
56
54
|
// if value is set, set input value to the label of the value
|
|
57
55
|
useEffect(() => {
|
|
58
56
|
if (value && value.length > 0 && !multiple) {
|
|
@@ -108,7 +106,7 @@ const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, d
|
|
|
108
106
|
const values = selectedOptions.map((option) => option.value);
|
|
109
107
|
onValueChange?.(values);
|
|
110
108
|
setPrevSelectedHash(selectedHash);
|
|
111
|
-
}, [onValueChange, selectedOptions, prevSelectedHash]);
|
|
109
|
+
}, [onValueChange, selectedOptions, prevSelectedHash, setPrevSelectedHash]);
|
|
112
110
|
useEffect(() => {
|
|
113
111
|
if (value && options.length > 0) {
|
|
114
112
|
const updatedSelectedOptions = value.map((option) => {
|
|
@@ -117,7 +115,7 @@ const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, d
|
|
|
117
115
|
});
|
|
118
116
|
setSelectedOptions(updatedSelectedOptions);
|
|
119
117
|
}
|
|
120
|
-
}, [multiple, prevSelectedHash, value, options]);
|
|
118
|
+
}, [multiple, prevSelectedHash, value, options, setSelectedOptions]);
|
|
121
119
|
// handle click on option, either select or deselect - Handles single or multiple
|
|
122
120
|
const handleSelectOption = (option) => {
|
|
123
121
|
// if option is already selected, remove it
|
|
@@ -248,7 +246,8 @@ const Combobox = forwardRef(({ value, onValueChange, label, hideLabel = false, d
|
|
|
248
246
|
htmlSize,
|
|
249
247
|
optionValues,
|
|
250
248
|
hideChips,
|
|
251
|
-
cleanButtonLabel,
|
|
249
|
+
clearButtonLabel: cleanButtonLabel || clearButtonLabel,
|
|
250
|
+
hideClearButton,
|
|
252
251
|
listId,
|
|
253
252
|
setInputValue,
|
|
254
253
|
setActiveIndex,
|
|
@@ -12,7 +12,7 @@ const ComboboxClearButton = () => {
|
|
|
12
12
|
if (!context) {
|
|
13
13
|
throw new Error('ComboboxContext is missing');
|
|
14
14
|
}
|
|
15
|
-
const { size, readOnly, disabled,
|
|
15
|
+
const { size, readOnly, disabled, clearButtonLabel, inputRef, setSelectedOptions, setInputValue, } = context;
|
|
16
16
|
return (jsx("button", { disabled: disabled, className: clsx(classes.clearButton, classes[size], utilityClasses.focusable), onClick: () => {
|
|
17
17
|
if (readOnly)
|
|
18
18
|
return;
|
|
@@ -31,7 +31,7 @@ const ComboboxClearButton = () => {
|
|
|
31
31
|
setInputValue('');
|
|
32
32
|
inputRef.current?.focus();
|
|
33
33
|
}
|
|
34
|
-
}, type: 'button', "aria-label":
|
|
34
|
+
}, type: 'button', "aria-label": clearButtonLabel, children: jsx(XMarkIcon, { fontSize: '1.5em', title: 'Clear selection' }) }));
|
|
35
35
|
};
|
|
36
36
|
ComboboxClearButton.displayName = 'ComboboxClearButton';
|
|
37
37
|
var ComboboxClearButton$1 = ComboboxClearButton;
|
|
@@ -17,7 +17,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
17
17
|
if (!context) {
|
|
18
18
|
throw new Error('ComboboxContext is missing');
|
|
19
19
|
}
|
|
20
|
-
const { forwareddRef, listId, size, readOnly, disabled, open, inputRef, refs, inputValue, activeDescendant, error, multiple, selectedOptions, formFieldProps, htmlSize, options, hideChips, setOpen, setActiveIndex, handleKeyDown, getReferenceProps, setInputValue, handleSelectOption, } = context;
|
|
20
|
+
const { forwareddRef, listId, size, readOnly, disabled, open, inputRef, refs, inputValue, activeDescendant, error, multiple, selectedOptions, formFieldProps, htmlSize, options, hideChips, hideClearButton, setOpen, setActiveIndex, handleKeyDown, getReferenceProps, setInputValue, handleSelectOption, } = context;
|
|
21
21
|
const mergedRefs = useMergeRefs([forwareddRef, inputRef]);
|
|
22
22
|
// we need to check if input is in focus, to add focus styles to the wrapper
|
|
23
23
|
const [inputInFocus, setInputInFocus] = useState(false);
|
|
@@ -64,6 +64,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
64
64
|
}, 0);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
+
const showClearButton = multiple && !hideClearButton && selectedOptions.length > 0;
|
|
67
68
|
return (jsxs(Box
|
|
68
69
|
/* Props from floating-ui */
|
|
69
70
|
, { ...getReferenceProps({
|
|
@@ -95,7 +96,7 @@ const ComboboxInput = ({ ...rest }) => {
|
|
|
95
96
|
}), "aria-disabled": disabled, className: clsx(textFieldClasses.input, classes.inputWrapper, classes[size], inputInFocus && classes.inFocus, readOnly && classes.readonly, error && classes.error), children: [jsxs("div", { className: classes.chipAndInput, children: [multiple && !hideChips && jsx(ComboboxChips, {}), jsx("input", { ref: mergedRefs, "aria-activedescendant": activeDescendant, readOnly: readOnly, "aria-autocomplete": 'list', role: 'combobox', "aria-expanded": open, "aria-controls": listId, autoComplete: 'off', size: htmlSize, value: inputValue, ...omit(['style', 'className'], rest), ...formFieldProps.inputProps, onChange: (e) => {
|
|
96
97
|
onChange(e);
|
|
97
98
|
rest.onChange && rest.onChange(e);
|
|
98
|
-
} })] }),
|
|
99
|
+
} })] }), showClearButton && jsx(ComboboxClearButton, {}), jsx("div", { className: classes.arrow, children: open ? (jsx(ChevronUpIcon, { title: 'arrow up', fontSize: '1.5em' })) : (jsx(ChevronDownIcon, { title: 'arrow down', fontSize: '1.5em' })) })] }));
|
|
99
100
|
};
|
|
100
101
|
ComboboxInput.displayName = 'ComboboxInput';
|
|
101
102
|
var ComboboxInput$1 = ComboboxInput;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
2
|
+
import { useMemo, Children, useState, isValidElement } from 'react';
|
|
4
3
|
import { ComboboxOption } from './Option/Option.js';
|
|
5
4
|
import ComboboxCustom from './Custom/Custom.js';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
const isOption = (option) => !!option;
|
|
7
|
+
function isComboboxOption(child) {
|
|
8
|
+
return isValidElement(child) && child.type === ComboboxOption;
|
|
9
|
+
}
|
|
10
|
+
function isComboboxCustom(child) {
|
|
11
|
+
return isValidElement(child) && child.type === ComboboxCustom;
|
|
12
|
+
}
|
|
13
|
+
function isInteractiveComboboxCustom(child) {
|
|
14
|
+
return isComboboxCustom(child) && child.props.interactive === true;
|
|
15
|
+
}
|
|
16
|
+
function useCombobox({ children, inputValue, multiple, filter, initialValue, }) {
|
|
8
17
|
const options = useMemo(() => {
|
|
9
18
|
const allOptions = [];
|
|
10
|
-
|
|
19
|
+
Children.forEach(children, (child) => {
|
|
11
20
|
if (isComboboxOption(child)) {
|
|
12
21
|
const props = child.props;
|
|
13
22
|
let label = props.displayValue || '';
|
|
14
23
|
if (!props.displayValue) {
|
|
15
24
|
let childrenLabel = '';
|
|
16
25
|
// go over children and find all strings
|
|
17
|
-
|
|
26
|
+
Children.forEach(props.children, (child) => {
|
|
18
27
|
if (typeof child === 'string') {
|
|
19
28
|
childrenLabel += child;
|
|
20
29
|
}
|
|
@@ -34,9 +43,14 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
34
43
|
});
|
|
35
44
|
return allOptions;
|
|
36
45
|
}, [children]);
|
|
46
|
+
const preSelectedOptions = (initialValue || [])
|
|
47
|
+
.map((value) => options.find((option) => option.value === value))
|
|
48
|
+
.filter(isOption);
|
|
49
|
+
const [selectedOptions, setSelectedOptions] = useState(preSelectedOptions);
|
|
50
|
+
const [prevSelectedHash, setPrevSelectedHash] = useState(JSON.stringify(selectedOptions));
|
|
37
51
|
const optionsChildren = useMemo(() => {
|
|
38
52
|
const valuesArray = Array.from(options);
|
|
39
|
-
const children_ =
|
|
53
|
+
const children_ = Children.toArray(children).filter((child) => isComboboxOption(child));
|
|
40
54
|
const activeValue = valuesArray.find((item) => item.label === inputValue);
|
|
41
55
|
if (activeValue && !multiple)
|
|
42
56
|
return children_;
|
|
@@ -54,7 +68,7 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
54
68
|
}, [options, children, multiple, inputValue, selectedOptions, filter]);
|
|
55
69
|
const customIds = useMemo(() => {
|
|
56
70
|
// find all custom components with `interactive=true` and generate random values for them
|
|
57
|
-
const children_ =
|
|
71
|
+
const children_ = Children.toArray(children).filter((child) => {
|
|
58
72
|
return isInteractiveComboboxCustom(child);
|
|
59
73
|
});
|
|
60
74
|
// return all ids
|
|
@@ -73,7 +87,7 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
73
87
|
return [...customIds, ...options];
|
|
74
88
|
}, [customIds, optionsChildren]);
|
|
75
89
|
const restChildren = useMemo(() => {
|
|
76
|
-
return
|
|
90
|
+
return Children.toArray(children).filter((child) => {
|
|
77
91
|
return !isComboboxOption(child);
|
|
78
92
|
});
|
|
79
93
|
}, [children]);
|
|
@@ -83,16 +97,11 @@ function useCombobox({ children, inputValue, multiple, selectedOptions, filter,
|
|
|
83
97
|
restChildren,
|
|
84
98
|
options,
|
|
85
99
|
customIds,
|
|
100
|
+
selectedOptions,
|
|
101
|
+
setSelectedOptions,
|
|
102
|
+
prevSelectedHash,
|
|
103
|
+
setPrevSelectedHash,
|
|
86
104
|
};
|
|
87
105
|
}
|
|
88
|
-
function isComboboxOption(child) {
|
|
89
|
-
return React.isValidElement(child) && child.type === ComboboxOption;
|
|
90
|
-
}
|
|
91
|
-
function isComboboxCustom(child) {
|
|
92
|
-
return React.isValidElement(child) && child.type === ComboboxCustom;
|
|
93
|
-
}
|
|
94
|
-
function isInteractiveComboboxCustom(child) {
|
|
95
|
-
return isComboboxCustom(child) && child.props.interactive === true;
|
|
96
|
-
}
|
|
97
106
|
|
|
98
107
|
export { useCombobox as default, isComboboxCustom, isComboboxOption, isInteractiveComboboxCustom };
|
|
@@ -18,6 +18,10 @@ export type ComboboxProps = {
|
|
|
18
18
|
* String array of selected options. Contains only one option during single selection mode.
|
|
19
19
|
*/
|
|
20
20
|
value?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* String array of initial selected options. Contains only one option during single selection mode.
|
|
23
|
+
*/
|
|
24
|
+
initialValue?: string[];
|
|
21
25
|
/**
|
|
22
26
|
* Callback function that is called when the value changes
|
|
23
27
|
*/
|
|
@@ -44,8 +48,19 @@ export type ComboboxProps = {
|
|
|
44
48
|
/**
|
|
45
49
|
* Label for the clear button
|
|
46
50
|
* @default 'Fjern alt'
|
|
51
|
+
* @deprecated Use `clearButtonLabel` instead
|
|
47
52
|
*/
|
|
48
53
|
cleanButtonLabel?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Hides the clear button
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
hideClearButton?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Label for the clear button
|
|
61
|
+
* @default 'Fjern alt'
|
|
62
|
+
*/
|
|
63
|
+
clearButtonLabel?: string;
|
|
49
64
|
/**
|
|
50
65
|
* Enables virtualizing of options list.
|
|
51
66
|
* @see https://tanstack.com/virtual
|
|
@@ -99,6 +114,10 @@ export declare const Combobox: React.ForwardRefExoticComponent<{
|
|
|
99
114
|
* String array of selected options. Contains only one option during single selection mode.
|
|
100
115
|
*/
|
|
101
116
|
value?: string[] | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* String array of initial selected options. Contains only one option during single selection mode.
|
|
119
|
+
*/
|
|
120
|
+
initialValue?: string[] | undefined;
|
|
102
121
|
/**
|
|
103
122
|
* Callback function that is called when the value changes
|
|
104
123
|
*/
|
|
@@ -125,8 +144,19 @@ export declare const Combobox: React.ForwardRefExoticComponent<{
|
|
|
125
144
|
/**
|
|
126
145
|
* Label for the clear button
|
|
127
146
|
* @default 'Fjern alt'
|
|
147
|
+
* @deprecated Use `clearButtonLabel` instead
|
|
128
148
|
*/
|
|
129
149
|
cleanButtonLabel?: string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Hides the clear button
|
|
152
|
+
* @default false
|
|
153
|
+
*/
|
|
154
|
+
hideClearButton?: boolean | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Label for the clear button
|
|
157
|
+
* @default 'Fjern alt'
|
|
158
|
+
*/
|
|
159
|
+
clearButtonLabel?: string | undefined;
|
|
130
160
|
/**
|
|
131
161
|
* Enables virtualizing of options list.
|
|
132
162
|
* @see https://tanstack.com/virtual
|
|
@@ -182,7 +212,8 @@ type ComboboxContextType = {
|
|
|
182
212
|
error: ComboboxProps['error'];
|
|
183
213
|
htmlSize: ComboboxProps['htmlSize'];
|
|
184
214
|
hideChips: NonNullable<ComboboxProps['hideChips']>;
|
|
185
|
-
|
|
215
|
+
clearButtonLabel: NonNullable<ComboboxProps['clearButtonLabel']>;
|
|
216
|
+
hideClearButton: NonNullable<ComboboxProps['hideClearButton']>;
|
|
186
217
|
options: Option[];
|
|
187
218
|
selectedOptions: Option[];
|
|
188
219
|
size: NonNullable<ComboboxProps['size']>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/Combobox/Combobox.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAepC,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM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,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnE,WAAW,EAAE,WAAW,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC;IACvD,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC3C,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,eAAe,gDAE3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxInput.d.ts","sourceRoot":"","sources":["../../../../../../src/components/form/Combobox/internal/ComboboxInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAcpC,eAAO,MAAM,aAAa;kBAEvB,KAAK,MAAM,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;;
|
|
1
|
+
{"version":3,"file":"ComboboxInput.d.ts","sourceRoot":"","sources":["../../../../../../src/components/form/Combobox/internal/ComboboxInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAcpC,eAAO,MAAM,aAAa;kBAEvB,KAAK,MAAM,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;;CA8K3D,CAAC;AAIF,eAAe,aAAa,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import type { ComboboxOptionProps } from './Option/Option';
|
|
3
3
|
import type { ComboboxProps } from './Combobox';
|
|
4
4
|
import type { ComboboxCustomProps } from './Custom/Custom';
|
|
5
5
|
export type UseComboboxProps = {
|
|
6
|
-
children:
|
|
6
|
+
children: ReactNode;
|
|
7
7
|
inputValue: string;
|
|
8
8
|
multiple: boolean;
|
|
9
|
-
selectedOptions: Option[];
|
|
10
9
|
filter: NonNullable<ComboboxProps['filter']>;
|
|
10
|
+
initialValue?: string[];
|
|
11
11
|
};
|
|
12
12
|
export type Option = {
|
|
13
13
|
value: string;
|
|
@@ -15,14 +15,18 @@ export type Option = {
|
|
|
15
15
|
displayValue?: string;
|
|
16
16
|
description?: string;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
19
|
-
|
|
18
|
+
export declare function isComboboxOption(child: ReactNode): child is ReactElement<ComboboxOptionProps>;
|
|
19
|
+
export declare function isComboboxCustom(child: ReactNode): child is ReactElement<ComboboxCustomProps>;
|
|
20
|
+
export declare function isInteractiveComboboxCustom(child: ReactNode): child is ReactElement<ComboboxCustomProps>;
|
|
21
|
+
export default function useCombobox({ children, inputValue, multiple, filter, initialValue, }: UseComboboxProps): {
|
|
22
|
+
optionsChildren: ReactElement<ComboboxOptionProps, string | import("react").JSXElementConstructor<any>>[];
|
|
20
23
|
optionValues: string[];
|
|
21
|
-
restChildren: (string | number |
|
|
24
|
+
restChildren: (string | number | ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | import("react").ReactPortal)[];
|
|
22
25
|
options: Option[];
|
|
23
26
|
customIds: string[];
|
|
27
|
+
selectedOptions: Option[];
|
|
28
|
+
setSelectedOptions: import("react").Dispatch<import("react").SetStateAction<Option[]>>;
|
|
29
|
+
prevSelectedHash: string;
|
|
30
|
+
setPrevSelectedHash: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
24
31
|
};
|
|
25
|
-
export declare function isComboboxOption(child: React.ReactNode): child is React.ReactElement<ComboboxOptionProps>;
|
|
26
|
-
export declare function isComboboxCustom(child: React.ReactNode): child is React.ReactElement<ComboboxCustomProps>;
|
|
27
|
-
export declare function isInteractiveComboboxCustom(child: React.ReactNode): child is React.ReactElement<ComboboxCustomProps>;
|
|
28
32
|
//# sourceMappingURL=useCombobox.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCombobox.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/Combobox/useCombobox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useCombobox.d.ts","sourceRoot":"","sources":["../../../../../src/components/form/Combobox/useCombobox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,GACf,KAAK,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAE5C;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,GACf,KAAK,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAE5C;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,SAAS,GACf,KAAK,IAAI,YAAY,CAAC,mBAAmB,CAAC,CAE5C;AAED,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,MAAM,EACN,YAAY,GACb,EAAE,gBAAgB;;;;;;;;;;EAmHlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digdir/designsystemet-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "React components for Designsystemet",
|
|
5
5
|
"author": "Designsystemet team",
|
|
6
6
|
"repository": "https://github.com/digdir/designsystemet",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"rollup": "^4.12.1",
|
|
44
44
|
"typescript": "^5.4.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "16a16d646a8ef0d1a5f3f1f5a806438a26dfa0bc"
|
|
47
47
|
}
|