@navikt/ds-react 4.9.0 → 4.9.1
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 +4 -4
- package/cjs/button/Button.js +1 -1
- package/cjs/form/combobox/ComboboxWrapper.js +5 -1
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +6 -2
- package/cjs/form/combobox/SelectedOptions/selectedOptionsContext.js +7 -5
- package/esm/button/Button.js +1 -1
- package/esm/button/Button.js.map +1 -1
- package/esm/form/combobox/ComboboxWrapper.js +6 -2
- package/esm/form/combobox/ComboboxWrapper.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +6 -2
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js +7 -5
- package/esm/form/combobox/SelectedOptions/selectedOptionsContext.js.map +1 -1
- package/esm/form/combobox/types.d.ts +3 -2
- package/package.json +2 -2
- package/src/button/Button.tsx +1 -5
- package/src/button/button.stories.tsx +6 -4
- package/src/form/combobox/ComboboxWrapper.tsx +6 -1
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +6 -1
- package/src/form/combobox/SelectedOptions/selectedOptionsContext.tsx +8 -8
- package/src/form/combobox/combobox.stories.tsx +2 -0
- package/src/form/combobox/types.ts +7 -2
package/_docs.json
CHANGED
|
@@ -14345,7 +14345,7 @@
|
|
|
14345
14345
|
},
|
|
14346
14346
|
"onToggleSelected": {
|
|
14347
14347
|
"defaultValue": null,
|
|
14348
|
-
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected\n@returns",
|
|
14348
|
+
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected - Whether the option has been selected or unselected\n@param isAddedByUser - Whether the option comes from user input, instead of from the list\n@returns",
|
|
14349
14349
|
"name": "onToggleSelected",
|
|
14350
14350
|
"parent": {
|
|
14351
14351
|
"fileName": "react/src/form/combobox/types.ts",
|
|
@@ -14359,7 +14359,7 @@
|
|
|
14359
14359
|
],
|
|
14360
14360
|
"required": false,
|
|
14361
14361
|
"type": {
|
|
14362
|
-
"name": "((option: string, isSelected: boolean) => void)"
|
|
14362
|
+
"name": "((option: string, isSelected: boolean, isAddedByUser: boolean) => void)"
|
|
14363
14363
|
}
|
|
14364
14364
|
},
|
|
14365
14365
|
"selectedOptions": {
|
|
@@ -14798,7 +14798,7 @@
|
|
|
14798
14798
|
},
|
|
14799
14799
|
"onToggleSelected": {
|
|
14800
14800
|
"defaultValue": null,
|
|
14801
|
-
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected\n@returns",
|
|
14801
|
+
"description": "Callback function triggered whenever an option is selected or de-selected\n@param option\n@param isSelected - Whether the option has been selected or unselected\n@param isAddedByUser - Whether the option comes from user input, instead of from the list\n@returns",
|
|
14802
14802
|
"name": "onToggleSelected",
|
|
14803
14803
|
"parent": {
|
|
14804
14804
|
"fileName": "react/src/form/combobox/types.ts",
|
|
@@ -14812,7 +14812,7 @@
|
|
|
14812
14812
|
],
|
|
14813
14813
|
"required": false,
|
|
14814
14814
|
"type": {
|
|
14815
|
-
"name": "((option: string, isSelected: boolean) => void)"
|
|
14815
|
+
"name": "((option: string, isSelected: boolean, isAddedByUser: boolean) => void)"
|
|
14816
14816
|
}
|
|
14817
14817
|
},
|
|
14818
14818
|
"selectedOptions": {
|
package/cjs/button/Button.js
CHANGED
|
@@ -76,7 +76,7 @@ exports.Button = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
76
76
|
"navds-button--disabled": disabled !== null && disabled !== void 0 ? disabled : widthOverride,
|
|
77
77
|
}), style: Object.assign(Object.assign({}, style), { width: widthOverride }), disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }), widthOverride ? (react_1.default.createElement(__1.Loader, { size: size })) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
78
78
|
icon && iconPosition === "left" && (react_1.default.createElement("span", { className: "navds-button__icon" }, icon)),
|
|
79
|
-
children && (react_1.default.createElement(__1.Label, { as: "span", size: size === "medium" ? "medium" : "small"
|
|
79
|
+
children && (react_1.default.createElement(__1.Label, { as: "span", size: size === "medium" ? "medium" : "small" }, children)),
|
|
80
80
|
icon && iconPosition === "right" && (react_1.default.createElement("span", { className: "navds-button__icon" }, icon))))));
|
|
81
81
|
});
|
|
82
82
|
exports.default = exports.Button;
|
|
@@ -30,22 +30,26 @@ const clsx_1 = __importDefault(require("clsx"));
|
|
|
30
30
|
const react_1 = __importStar(require("react"));
|
|
31
31
|
const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize, toggleIsListOpen, toggleListButtonRef, }) => {
|
|
32
32
|
const wrapperRef = (0, react_1.useRef)(null);
|
|
33
|
+
const [hasFocusWithin, setHasFocusWithin] = (0, react_1.useState)(false);
|
|
33
34
|
function onFocusInsideWrapper(e) {
|
|
34
35
|
var _a;
|
|
35
36
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget)) &&
|
|
36
37
|
(toggleListButtonRef === null || toggleListButtonRef === void 0 ? void 0 : toggleListButtonRef.current) !== e.target) {
|
|
37
38
|
toggleIsListOpen(true);
|
|
39
|
+
setHasFocusWithin(true);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
function onBlurWrapper(e) {
|
|
41
43
|
var _a;
|
|
42
44
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
43
45
|
toggleIsListOpen(false);
|
|
46
|
+
setHasFocusWithin(false);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
return (react_1.default.createElement("div", { ref: wrapperRef, className: (0, clsx_1.default)(className, "navds-form-field", `navds-form-field--${inputSize}`, "navds-search", {
|
|
47
50
|
"navds-search--error": hasError,
|
|
48
51
|
"navds-search--disabled": !!inputProps.disabled,
|
|
49
|
-
|
|
52
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
53
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper, tabIndex: -1 }, children));
|
|
50
54
|
};
|
|
51
55
|
exports.default = ComboboxWrapper;
|
|
@@ -11,7 +11,7 @@ const filteredOptionsContext_1 = require("./filteredOptionsContext");
|
|
|
11
11
|
const selectedOptionsContext_1 = require("../SelectedOptions/selectedOptionsContext");
|
|
12
12
|
const inputContext_1 = require("../Input/inputContext");
|
|
13
13
|
const FilteredOptions = () => {
|
|
14
|
-
const { inputProps: { id }, size, value, } = (0, inputContext_1.useInputContext)();
|
|
14
|
+
const { clearInput, inputProps: { id }, size, value, } = (0, inputContext_1.useInputContext)();
|
|
15
15
|
const { allowNewValues, isLoading, isListOpen, filteredOptions, filteredOptionsIndex, filteredOptionsRef, isValueNew, toggleIsListOpen, } = (0, filteredOptionsContext_1.useFilteredOptionsContext)();
|
|
16
16
|
const { isMultiSelect, selectedOptions, toggleOption } = (0, selectedOptionsContext_1.useSelectedOptionsContext)();
|
|
17
17
|
return (react_1.default.createElement("ul", { ref: filteredOptionsRef, className: (0, clsx_1.default)("navds-combobox__list", {
|
|
@@ -19,7 +19,10 @@ const FilteredOptions = () => {
|
|
|
19
19
|
}), id: `${id}-filtered-options`, role: "listbox", tabIndex: -1 },
|
|
20
20
|
isLoading && (react_1.default.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: `${id}-is-loading` },
|
|
21
21
|
react_1.default.createElement(__1.Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
22
|
-
isValueNew && allowNewValues && (react_1.default.createElement("li", { tabIndex: -1, onPointerUp: (event) =>
|
|
22
|
+
isValueNew && allowNewValues && (react_1.default.createElement("li", { tabIndex: -1, onPointerUp: (event) => {
|
|
23
|
+
toggleOption(value, event);
|
|
24
|
+
clearInput(event);
|
|
25
|
+
}, id: `${id}-combobox-new-option`, className: (0, clsx_1.default)("navds-combobox__list-item__new-option", {
|
|
23
26
|
"navds-combobox__list-item__new-option--focus": filteredOptionsIndex === -1,
|
|
24
27
|
}), role: "option", "aria-selected": false },
|
|
25
28
|
react_1.default.createElement(aksel_icons_1.PlusIcon, { "aria-hidden": true }),
|
|
@@ -36,6 +39,7 @@ const FilteredOptions = () => {
|
|
|
36
39
|
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
37
40
|
}), id: `${id}-option-${option.replace(" ", "-")}`, key: option, tabIndex: -1, onPointerUp: (event) => {
|
|
38
41
|
toggleOption(option, event);
|
|
42
|
+
clearInput(event);
|
|
39
43
|
if (!isMultiSelect) {
|
|
40
44
|
toggleIsListOpen(false);
|
|
41
45
|
}
|
|
@@ -40,9 +40,10 @@ const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
40
40
|
const selectedOptions = (0, react_1.useMemo)(() => externalSelectedOptions !== null && externalSelectedOptions !== void 0 ? externalSelectedOptions : [...customOptions, ...internalSelectedOptions], [customOptions, externalSelectedOptions, internalSelectedOptions]);
|
|
41
41
|
const addSelectedOption = (0, react_1.useCallback)((option) => {
|
|
42
42
|
var _a;
|
|
43
|
-
|
|
43
|
+
const isAddedByUser = !options
|
|
44
44
|
.map((opt) => opt.toLowerCase())
|
|
45
|
-
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option))
|
|
45
|
+
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option));
|
|
46
|
+
if (isAddedByUser) {
|
|
46
47
|
allowNewValues && addCustomOption(option);
|
|
47
48
|
}
|
|
48
49
|
else if (isMultiSelect) {
|
|
@@ -54,16 +55,17 @@ const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
54
55
|
else {
|
|
55
56
|
setSelectedOptions([option]);
|
|
56
57
|
}
|
|
57
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true);
|
|
58
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true, isAddedByUser);
|
|
58
59
|
}, [addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]);
|
|
59
60
|
const removeSelectedOption = (0, react_1.useCallback)((option) => {
|
|
60
|
-
|
|
61
|
+
const isAddedByUser = customOptions.includes(option);
|
|
62
|
+
if (isAddedByUser) {
|
|
61
63
|
removeCustomOption(option);
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
64
66
|
setSelectedOptions((prevSelectedOptions) => prevSelectedOptions.filter((selectedOption) => selectedOption !== option));
|
|
65
67
|
}
|
|
66
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false);
|
|
68
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false, isAddedByUser);
|
|
67
69
|
}, [customOptions, onToggleSelected, removeCustomOption]);
|
|
68
70
|
const toggleOption = (0, react_1.useCallback)((option, event) => {
|
|
69
71
|
if (selectedOptions.includes(option)) {
|
package/esm/button/Button.js
CHANGED
|
@@ -47,7 +47,7 @@ export const Button = forwardRef((_a, ref) => {
|
|
|
47
47
|
"navds-button--disabled": disabled !== null && disabled !== void 0 ? disabled : widthOverride,
|
|
48
48
|
}), style: Object.assign(Object.assign({}, style), { width: widthOverride }), disabled: (disabled !== null && disabled !== void 0 ? disabled : widthOverride) ? true : undefined }), widthOverride ? (React.createElement(Loader, { size: size })) : (React.createElement(React.Fragment, null,
|
|
49
49
|
icon && iconPosition === "left" && (React.createElement("span", { className: "navds-button__icon" }, icon)),
|
|
50
|
-
children && (React.createElement(Label, { as: "span", size: size === "medium" ? "medium" : "small"
|
|
50
|
+
children && (React.createElement(Label, { as: "span", size: size === "medium" ? "medium" : "small" }, children)),
|
|
51
51
|
icon && iconPosition === "right" && (React.createElement("span", { className: "navds-button__icon" }, icon))))));
|
|
52
52
|
});
|
|
53
53
|
export default Button;
|
package/esm/button/Button.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sourceRoot":"","sources":["../../src/button/Button.tsx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|
import cl from "clsx";
|
|
2
|
-
import React, { useRef } from "react";
|
|
2
|
+
import React, { useRef, useState } from "react";
|
|
3
3
|
const ComboboxWrapper = ({ children, className, hasError, inputProps, inputSize, toggleIsListOpen, toggleListButtonRef, }) => {
|
|
4
4
|
const wrapperRef = useRef(null);
|
|
5
|
+
const [hasFocusWithin, setHasFocusWithin] = useState(false);
|
|
5
6
|
function onFocusInsideWrapper(e) {
|
|
6
7
|
var _a;
|
|
7
8
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget)) &&
|
|
8
9
|
(toggleListButtonRef === null || toggleListButtonRef === void 0 ? void 0 : toggleListButtonRef.current) !== e.target) {
|
|
9
10
|
toggleIsListOpen(true);
|
|
11
|
+
setHasFocusWithin(true);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
12
14
|
function onBlurWrapper(e) {
|
|
13
15
|
var _a;
|
|
14
16
|
if (!((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.relatedTarget))) {
|
|
15
17
|
toggleIsListOpen(false);
|
|
18
|
+
setHasFocusWithin(false);
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
return (React.createElement("div", { ref: wrapperRef, className: cl(className, "navds-form-field", `navds-form-field--${inputSize}`, "navds-search", {
|
|
19
22
|
"navds-search--error": hasError,
|
|
20
23
|
"navds-search--disabled": !!inputProps.disabled,
|
|
21
|
-
|
|
24
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
25
|
+
}), onFocus: onFocusInsideWrapper, onBlur: onBlurWrapper, tabIndex: -1 }, children));
|
|
22
26
|
};
|
|
23
27
|
export default ComboboxWrapper;
|
|
24
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;AAC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EAAE,QAAQ;YAC/B,wBAAwB,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ;YAC/C,yBAAyB,EAAE,cAAc;SAC1C,CACF,EACD,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,CAAC,CAAC,IAEX,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { useFilteredOptionsContext } from "./filteredOptionsContext";
|
|
|
6
6
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
7
7
|
import { useInputContext } from "../Input/inputContext";
|
|
8
8
|
const FilteredOptions = () => {
|
|
9
|
-
const { inputProps: { id }, size, value, } = useInputContext();
|
|
9
|
+
const { clearInput, inputProps: { id }, size, value, } = useInputContext();
|
|
10
10
|
const { allowNewValues, isLoading, isListOpen, filteredOptions, filteredOptionsIndex, filteredOptionsRef, isValueNew, toggleIsListOpen, } = useFilteredOptionsContext();
|
|
11
11
|
const { isMultiSelect, selectedOptions, toggleOption } = useSelectedOptionsContext();
|
|
12
12
|
return (React.createElement("ul", { ref: filteredOptionsRef, className: cl("navds-combobox__list", {
|
|
@@ -14,7 +14,10 @@ const FilteredOptions = () => {
|
|
|
14
14
|
}), id: `${id}-filtered-options`, role: "listbox", tabIndex: -1 },
|
|
15
15
|
isLoading && (React.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: `${id}-is-loading` },
|
|
16
16
|
React.createElement(Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
17
|
-
isValueNew && allowNewValues && (React.createElement("li", { tabIndex: -1, onPointerUp: (event) =>
|
|
17
|
+
isValueNew && allowNewValues && (React.createElement("li", { tabIndex: -1, onPointerUp: (event) => {
|
|
18
|
+
toggleOption(value, event);
|
|
19
|
+
clearInput(event);
|
|
20
|
+
}, id: `${id}-combobox-new-option`, className: cl("navds-combobox__list-item__new-option", {
|
|
18
21
|
"navds-combobox__list-item__new-option--focus": filteredOptionsIndex === -1,
|
|
19
22
|
}), role: "option", "aria-selected": false },
|
|
20
23
|
React.createElement(PlusIcon, { "aria-hidden": true }),
|
|
@@ -31,6 +34,7 @@ const FilteredOptions = () => {
|
|
|
31
34
|
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
32
35
|
}), id: `${id}-option-${option.replace(" ", "-")}`, key: option, tabIndex: -1, onPointerUp: (event) => {
|
|
33
36
|
toggleOption(option, event);
|
|
37
|
+
clearInput(event);
|
|
34
38
|
if (!isMultiSelect) {
|
|
35
39
|
toggleIsListOpen(false);
|
|
36
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,EACJ,UAAU,EAAE,EAAE,EAAE,EAAE,EAClB,IAAI,EACJ,KAAK,GACN,GAAG,eAAe,EAAE,CAAC;IACtB,MAAM,EACJ,cAAc,EACd,SAAS,EACT,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,GAAG,yBAAyB,EAAE,CAAC;IAChC,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,GACpD,yBAAyB,EAAE,CAAC;IAE9B,OAAO,CACL,4BACE,GAAG,EAAE,kBAAkB,EACvB,SAAS,EAAE,EAAE,CAAC,sBAAsB,EAAE;YACpC,8BAA8B,EAAE,CAAC,UAAU;SAC5C,CAAC,EACF,EAAE,EAAE,GAAG,EAAE,mBAAmB,EAC5B,IAAI,EAAC,SAAS,EACd,QAAQ,EAAE,CAAC,CAAC;QAEX,SAAS,IAAI,CACZ,4BACE,SAAS,EAAC,oCAAoC,EAC9C,IAAI,EAAC,QAAQ,mBACE,KAAK,EACpB,EAAE,EAAE,GAAG,EAAE,aAAa;YAEtB,oBAAC,MAAM,kBAAY,eAAU,GAAG,CAC7B,CACN;QACA,UAAU,IAAI,cAAc,IAAI,CAC/B,4BACE,QAAQ,EAAE,CAAC,CAAC,EACZ,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/FilteredOptions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,eAAe,GAAG,GAAG,EAAE;IAC3B,MAAM,EACJ,UAAU,EACV,UAAU,EAAE,EAAE,EAAE,EAAE,EAClB,IAAI,EACJ,KAAK,GACN,GAAG,eAAe,EAAE,CAAC;IACtB,MAAM,EACJ,cAAc,EACd,SAAS,EACT,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,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AI,EAAC,QAAQ,mBACE,KAAK,EACpB,EAAE,EAAE,GAAG,EAAE,UAAU,2BAGhB,CACN;QACA,eAAe,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CACtC,4BACE,SAAS,EAAE,EAAE,CAAC,2BAA2B,EAAE;gBACzC,kCAAkC,EAAE,KAAK,KAAK,oBAAoB;gBAClE,qCAAqC,EACnC,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;aACnC,CAAC,EACF,EAAE,EAAE,GAAG,EAAE,WAAW,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAC9C,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,CAAC,EACZ,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE;gBACrB,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;gBAC5B,UAAU,CAAC,KAAK,CAAC,CAAC;gBAClB,IAAI,CAAC,aAAa,EAAE;oBAClB,gBAAgB,CAAC,KAAK,CAAC,CAAC;iBACzB;YACH,CAAC,EACD,IAAI,EAAC,QAAQ,mBACE,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC;YAE/C,oBAAC,SAAS,IAAC,IAAI,EAAE,IAAI,IAAG,MAAM,CAAa;YAC1C,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,oBAAC,aAAa,OAAG,CACnD,CACN,CAAC,CACC,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -11,9 +11,10 @@ export const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
11
11
|
const selectedOptions = useMemo(() => externalSelectedOptions !== null && externalSelectedOptions !== void 0 ? externalSelectedOptions : [...customOptions, ...internalSelectedOptions], [customOptions, externalSelectedOptions, internalSelectedOptions]);
|
|
12
12
|
const addSelectedOption = useCallback((option) => {
|
|
13
13
|
var _a;
|
|
14
|
-
|
|
14
|
+
const isAddedByUser = !options
|
|
15
15
|
.map((opt) => opt.toLowerCase())
|
|
16
|
-
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option))
|
|
16
|
+
.includes((_a = option === null || option === void 0 ? void 0 : option.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(option));
|
|
17
|
+
if (isAddedByUser) {
|
|
17
18
|
allowNewValues && addCustomOption(option);
|
|
18
19
|
}
|
|
19
20
|
else if (isMultiSelect) {
|
|
@@ -25,16 +26,17 @@ export const SelectedOptionsProvider = ({ children, value, }) => {
|
|
|
25
26
|
else {
|
|
26
27
|
setSelectedOptions([option]);
|
|
27
28
|
}
|
|
28
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true);
|
|
29
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, true, isAddedByUser);
|
|
29
30
|
}, [addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]);
|
|
30
31
|
const removeSelectedOption = useCallback((option) => {
|
|
31
|
-
|
|
32
|
+
const isAddedByUser = customOptions.includes(option);
|
|
33
|
+
if (isAddedByUser) {
|
|
32
34
|
removeCustomOption(option);
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
37
|
setSelectedOptions((prevSelectedOptions) => prevSelectedOptions.filter((selectedOption) => selectedOption !== option));
|
|
36
38
|
}
|
|
37
|
-
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false);
|
|
39
|
+
onToggleSelected === null || onToggleSelected === void 0 ? void 0 : onToggleSelected(option, false, isAddedByUser);
|
|
38
40
|
}, [customOptions, onToggleSelected, removeCustomOption]);
|
|
39
41
|
const toggleOption = useCallback((option, event) => {
|
|
40
42
|
if (selectedOptions.includes(option)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectedOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/SelectedOptions/selectedOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAelE,MAAM,sBAAsB,GAAG,aAAa,CAC1C,EAAgC,CACjC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,EACR,KAAK,GAWN,EAAE,EAAE;IACH,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,eAAe,EAAE,CAAC;IACrD,MAAM,EAAE,aAAa,EAAE,kBAAkB,EAAE,eAAe,EAAE,GAC1D,uBAAuB,EAAE,CAAC;IAC5B,MAAM,EACJ,cAAc,EACd,aAAa,EACb,eAAe,EAAE,uBAAuB,EACxC,gBAAgB,EAChB,OAAO,GACR,GAAG,KAAK,CAAC;IACV,MAAM,CAAC,uBAAuB,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAW,EAAE,CAAC,CAAC;IAC7E,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CACH,uBAAuB,aAAvB,uBAAuB,cAAvB,uBAAuB,GAAI,CAAC,GAAG,aAAa,EAAE,GAAG,uBAAuB,CAAC,EAC3E,CAAC,aAAa,EAAE,uBAAuB,EAAE,uBAAuB,CAAC,CAClE,CAAC;IAEF,MAAM,iBAAiB,GAAG,WAAW,CACnC,CAAC,MAAc,EAAE,EAAE;;QACjB,
|
|
1
|
+
{"version":3,"file":"selectedOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/SelectedOptions/selectedOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CA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AAU;QACV,UAAU;QACV,aAAa;QACb,oBAAoB;QACpB,eAAe;KAChB,CACF,CAAC;IAEF,MAAM,mBAAmB,GAAG,WAAW,CAAW,eAAe,CAAC,CAAC;IAEnE,MAAM,oBAAoB,GAAG;QAC3B,iBAAiB;QACjB,aAAa;QACb,oBAAoB;QACpB,mBAAmB;QACnB,eAAe;QACf,kBAAkB;QAClB,YAAY;KACb,CAAC;IAEF,OAAO,CACL,oBAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,oBAAoB,IACzD,QAAQ,CACuB,CACnC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,sBAAsB,CAAC,CAAC;IACnD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -75,10 +75,11 @@ export interface ComboboxProps extends FormFieldProps, Omit<InputHTMLAttributes<
|
|
|
75
75
|
* Callback function triggered whenever an option is selected or de-selected
|
|
76
76
|
*
|
|
77
77
|
* @param option
|
|
78
|
-
* @param isSelected
|
|
78
|
+
* @param isSelected - Whether the option has been selected or unselected
|
|
79
|
+
* @param isAddedByUser - Whether the option comes from user input, instead of from the list
|
|
79
80
|
* @returns
|
|
80
81
|
*/
|
|
81
|
-
onToggleSelected?: (option: string, isSelected: boolean) => void;
|
|
82
|
+
onToggleSelected?: (option: string, isSelected: boolean, isAddedByUser: boolean) => void;
|
|
82
83
|
/**
|
|
83
84
|
* List of selected options.
|
|
84
85
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.1",
|
|
4
4
|
"description": "Aksel react-components for NAV designsystem",
|
|
5
5
|
"author": "Aksel | NAV designsystem team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@floating-ui/react": "0.24.1",
|
|
41
|
-
"@navikt/aksel-icons": "^4.9.
|
|
41
|
+
"@navikt/aksel-icons": "^4.9.1",
|
|
42
42
|
"@radix-ui/react-tabs": "1.0.0",
|
|
43
43
|
"@radix-ui/react-toggle-group": "1.0.0",
|
|
44
44
|
"clsx": "^1.2.1",
|
package/src/button/Button.tsx
CHANGED
|
@@ -126,11 +126,7 @@ export const Button: OverridableComponent<ButtonProps, HTMLButtonElement> =
|
|
|
126
126
|
<span className="navds-button__icon">{icon}</span>
|
|
127
127
|
)}
|
|
128
128
|
{children && (
|
|
129
|
-
<Label
|
|
130
|
-
as="span"
|
|
131
|
-
size={size === "medium" ? "medium" : "small"}
|
|
132
|
-
aria-live="polite"
|
|
133
|
-
>
|
|
129
|
+
<Label as="span" size={size === "medium" ? "medium" : "small"}>
|
|
134
130
|
{children}
|
|
135
131
|
</Label>
|
|
136
132
|
)}
|
|
@@ -148,8 +148,9 @@ export const Loading = {
|
|
|
148
148
|
</div>
|
|
149
149
|
),
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
parameters: {
|
|
152
|
+
chromatic: { disableSnapshot: true },
|
|
153
|
+
},
|
|
153
154
|
};
|
|
154
155
|
|
|
155
156
|
export const Icon = () => (
|
|
@@ -275,6 +276,7 @@ export const LoadingWithAs = {
|
|
|
275
276
|
</div>
|
|
276
277
|
),
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
parameters: {
|
|
280
|
+
chromatic: { disableSnapshot: true },
|
|
281
|
+
},
|
|
280
282
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
|
-
import React, { useRef } from "react";
|
|
2
|
+
import React, { useRef, useState } from "react";
|
|
3
3
|
|
|
4
4
|
type ComboboxWrapperProps = {
|
|
5
5
|
children: any;
|
|
@@ -23,6 +23,7 @@ const ComboboxWrapper = ({
|
|
|
23
23
|
toggleListButtonRef,
|
|
24
24
|
}: ComboboxWrapperProps) => {
|
|
25
25
|
const wrapperRef = useRef<HTMLDivElement | null>(null);
|
|
26
|
+
const [hasFocusWithin, setHasFocusWithin] = useState(false);
|
|
26
27
|
|
|
27
28
|
function onFocusInsideWrapper(e) {
|
|
28
29
|
if (
|
|
@@ -30,12 +31,14 @@ const ComboboxWrapper = ({
|
|
|
30
31
|
toggleListButtonRef?.current !== e.target
|
|
31
32
|
) {
|
|
32
33
|
toggleIsListOpen(true);
|
|
34
|
+
setHasFocusWithin(true);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
function onBlurWrapper(e) {
|
|
37
39
|
if (!wrapperRef.current?.contains(e.relatedTarget)) {
|
|
38
40
|
toggleIsListOpen(false);
|
|
41
|
+
setHasFocusWithin(false);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -50,10 +53,12 @@ const ComboboxWrapper = ({
|
|
|
50
53
|
{
|
|
51
54
|
"navds-search--error": hasError,
|
|
52
55
|
"navds-search--disabled": !!inputProps.disabled,
|
|
56
|
+
"navds-combobox--focused": hasFocusWithin,
|
|
53
57
|
}
|
|
54
58
|
)}
|
|
55
59
|
onFocus={onFocusInsideWrapper}
|
|
56
60
|
onBlur={onBlurWrapper}
|
|
61
|
+
tabIndex={-1}
|
|
57
62
|
>
|
|
58
63
|
{children}
|
|
59
64
|
</div>
|
|
@@ -8,6 +8,7 @@ import { useInputContext } from "../Input/inputContext";
|
|
|
8
8
|
|
|
9
9
|
const FilteredOptions = () => {
|
|
10
10
|
const {
|
|
11
|
+
clearInput,
|
|
11
12
|
inputProps: { id },
|
|
12
13
|
size,
|
|
13
14
|
value,
|
|
@@ -48,7 +49,10 @@ const FilteredOptions = () => {
|
|
|
48
49
|
{isValueNew && allowNewValues && (
|
|
49
50
|
<li
|
|
50
51
|
tabIndex={-1}
|
|
51
|
-
onPointerUp={(event) =>
|
|
52
|
+
onPointerUp={(event) => {
|
|
53
|
+
toggleOption(value, event);
|
|
54
|
+
clearInput(event);
|
|
55
|
+
}}
|
|
52
56
|
id={`${id}-combobox-new-option`}
|
|
53
57
|
className={cl("navds-combobox__list-item__new-option", {
|
|
54
58
|
"navds-combobox__list-item__new-option--focus":
|
|
@@ -88,6 +92,7 @@ const FilteredOptions = () => {
|
|
|
88
92
|
tabIndex={-1}
|
|
89
93
|
onPointerUp={(event) => {
|
|
90
94
|
toggleOption(option, event);
|
|
95
|
+
clearInput(event);
|
|
91
96
|
if (!isMultiSelect) {
|
|
92
97
|
toggleIsListOpen(false);
|
|
93
98
|
}
|
|
@@ -60,11 +60,10 @@ export const SelectedOptionsProvider = ({
|
|
|
60
60
|
|
|
61
61
|
const addSelectedOption = useCallback(
|
|
62
62
|
(option: string) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
) {
|
|
63
|
+
const isAddedByUser = !options
|
|
64
|
+
.map((opt) => opt.toLowerCase())
|
|
65
|
+
.includes(option?.toLowerCase?.());
|
|
66
|
+
if (isAddedByUser) {
|
|
68
67
|
allowNewValues && addCustomOption(option);
|
|
69
68
|
} else if (isMultiSelect) {
|
|
70
69
|
setSelectedOptions((prevSelectedOptions) => [
|
|
@@ -74,14 +73,15 @@ export const SelectedOptionsProvider = ({
|
|
|
74
73
|
} else {
|
|
75
74
|
setSelectedOptions([option]);
|
|
76
75
|
}
|
|
77
|
-
onToggleSelected?.(option, true);
|
|
76
|
+
onToggleSelected?.(option, true, isAddedByUser);
|
|
78
77
|
},
|
|
79
78
|
[addCustomOption, allowNewValues, isMultiSelect, onToggleSelected, options]
|
|
80
79
|
);
|
|
81
80
|
|
|
82
81
|
const removeSelectedOption = useCallback(
|
|
83
82
|
(option: string) => {
|
|
84
|
-
|
|
83
|
+
const isAddedByUser = customOptions.includes(option);
|
|
84
|
+
if (isAddedByUser) {
|
|
85
85
|
removeCustomOption(option);
|
|
86
86
|
} else {
|
|
87
87
|
setSelectedOptions((prevSelectedOptions) =>
|
|
@@ -90,7 +90,7 @@ export const SelectedOptionsProvider = ({
|
|
|
90
90
|
)
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
-
onToggleSelected?.(option, false);
|
|
93
|
+
onToggleSelected?.(option, false, isAddedByUser);
|
|
94
94
|
},
|
|
95
95
|
[customOptions, onToggleSelected, removeCustomOption]
|
|
96
96
|
);
|
|
@@ -82,6 +82,7 @@ export function MultiSelect(props) {
|
|
|
82
82
|
label="Komboboks - velg flere"
|
|
83
83
|
options={props.options}
|
|
84
84
|
isMultiSelect={props.isMultiSelect}
|
|
85
|
+
size={props.size}
|
|
85
86
|
/>
|
|
86
87
|
</DemoContainer>
|
|
87
88
|
);
|
|
@@ -90,6 +91,7 @@ export function MultiSelect(props) {
|
|
|
90
91
|
MultiSelect.args = {
|
|
91
92
|
options,
|
|
92
93
|
isMultiSelect: true,
|
|
94
|
+
size: "medium",
|
|
93
95
|
};
|
|
94
96
|
|
|
95
97
|
export function MultiSelectWithAddNewOptions(props) {
|
|
@@ -78,10 +78,15 @@ export interface ComboboxProps
|
|
|
78
78
|
* Callback function triggered whenever an option is selected or de-selected
|
|
79
79
|
*
|
|
80
80
|
* @param option
|
|
81
|
-
* @param isSelected
|
|
81
|
+
* @param isSelected - Whether the option has been selected or unselected
|
|
82
|
+
* @param isAddedByUser - Whether the option comes from user input, instead of from the list
|
|
82
83
|
* @returns
|
|
83
84
|
*/
|
|
84
|
-
onToggleSelected?: (
|
|
85
|
+
onToggleSelected?: (
|
|
86
|
+
option: string,
|
|
87
|
+
isSelected: boolean,
|
|
88
|
+
isAddedByUser: boolean
|
|
89
|
+
) => void;
|
|
85
90
|
/**
|
|
86
91
|
* List of selected options.
|
|
87
92
|
*
|