@navikt/ds-react 5.7.6 → 5.9.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 +1824 -1758
- package/cjs/accordion/AccordionHeader.js +2 -2
- package/cjs/date/context/useDateInputContext.js +1 -5
- package/cjs/date/datepicker/DatePicker.js +26 -25
- package/cjs/date/hooks/useDatepicker.js +9 -17
- package/cjs/date/hooks/useMonthPicker.js +9 -17
- package/cjs/date/hooks/useRangeDatepicker.js +9 -20
- package/cjs/date/monthpicker/MonthPicker.js +11 -6
- package/cjs/date/{DateInput.js → parts/DateInput.js} +14 -10
- package/cjs/date/parts/DateWrapper.js +55 -0
- package/cjs/date/utils/labels.js +77 -1
- package/cjs/form/combobox/Combobox.js +2 -2
- package/cjs/form/combobox/ComboboxProvider.js +1 -2
- package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +15 -14
- package/cjs/form/combobox/FilteredOptions/filtered-options-util.js +24 -0
- package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +24 -108
- package/cjs/form/combobox/FilteredOptions/useVirtualFocus.js +55 -0
- package/cjs/form/combobox/Input/Input.js +33 -16
- package/cjs/form/combobox/customOptionsContext.js +2 -3
- package/cjs/layout/sidemal-test/Sidebar.js +1 -1
- package/cjs/loader/Loader.js +1 -1
- package/cjs/modal/Modal.js +39 -15
- package/cjs/popover/Popover.js +5 -7
- package/cjs/tooltip/Tooltip.js +14 -3
- package/cjs/util/useMedia.js +30 -0
- package/esm/accordion/AccordionHeader.js +2 -2
- package/esm/accordion/AccordionHeader.js.map +1 -1
- package/esm/date/context/useDateInputContext.d.ts +6 -2
- package/esm/date/context/useDateInputContext.js +1 -5
- package/esm/date/context/useDateInputContext.js.map +1 -1
- package/esm/date/datepicker/DatePicker.d.ts +1 -1
- package/esm/date/datepicker/DatePicker.js +28 -27
- package/esm/date/datepicker/DatePicker.js.map +1 -1
- package/esm/date/datepicker/types.d.ts +0 -5
- package/esm/date/hooks/useDatepicker.d.ts +8 -5
- package/esm/date/hooks/useDatepicker.js +10 -18
- package/esm/date/hooks/useDatepicker.js.map +1 -1
- package/esm/date/hooks/useMonthPicker.d.ts +7 -4
- package/esm/date/hooks/useMonthPicker.js +10 -18
- package/esm/date/hooks/useMonthPicker.js.map +1 -1
- package/esm/date/hooks/useRangeDatepicker.d.ts +9 -3
- package/esm/date/hooks/useRangeDatepicker.js +10 -21
- package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
- package/esm/date/index.d.ts +1 -1
- package/esm/date/index.js.map +1 -1
- package/esm/date/monthpicker/MonthPicker.d.ts +1 -1
- package/esm/date/monthpicker/MonthPicker.js +13 -8
- package/esm/date/monthpicker/MonthPicker.js.map +1 -1
- package/esm/date/monthpicker/types.d.ts +0 -5
- package/esm/date/{DateInput.d.ts → parts/DateInput.d.ts} +5 -1
- package/esm/date/{DateInput.js → parts/DateInput.js} +15 -11
- package/esm/date/parts/DateInput.js.map +1 -0
- package/esm/date/parts/DateWrapper.d.ts +15 -0
- package/esm/date/parts/DateWrapper.js +26 -0
- package/esm/date/parts/DateWrapper.js.map +1 -0
- package/esm/date/utils/labels.d.ts +2 -0
- package/esm/date/utils/labels.js +74 -0
- package/esm/date/utils/labels.js.map +1 -1
- package/esm/form/combobox/Combobox.js +2 -2
- package/esm/form/combobox/Combobox.js.map +1 -1
- package/esm/form/combobox/ComboboxProvider.js +1 -2
- package/esm/form/combobox/ComboboxProvider.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js +15 -14
- package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/filtered-options-util.d.ts +12 -0
- package/esm/form/combobox/FilteredOptions/filtered-options-util.js +23 -0
- package/esm/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -0
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.d.ts +10 -13
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +25 -109
- package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.d.ts +15 -0
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.js +54 -0
- package/esm/form/combobox/FilteredOptions/useVirtualFocus.js.map +1 -0
- package/esm/form/combobox/Input/Input.js +33 -16
- package/esm/form/combobox/Input/Input.js.map +1 -1
- package/esm/form/combobox/customOptionsContext.d.ts +4 -1
- package/esm/form/combobox/customOptionsContext.js +2 -3
- package/esm/form/combobox/customOptionsContext.js.map +1 -1
- package/esm/layout/bleed/Bleed.d.ts +1 -1
- package/esm/layout/bleed/Bleed.js +1 -1
- package/esm/layout/bleed/Bleed.js.map +1 -1
- package/esm/layout/box/Box.d.ts +1 -2
- package/esm/layout/box/Box.js +1 -1
- package/esm/layout/box/Box.js.map +1 -1
- package/esm/layout/grid/HGrid.d.ts +1 -1
- package/esm/layout/grid/HGrid.js +1 -1
- package/esm/layout/grid/HGrid.js.map +1 -1
- package/esm/layout/responsive/Responsive.d.ts +1 -1
- package/esm/layout/sidemal-test/Sidebar.js +1 -1
- package/esm/layout/sidemal-test/Sidebar.js.map +1 -1
- package/esm/layout/stack/Stack.d.ts +1 -1
- package/esm/layout/stack/Stack.js +1 -1
- package/esm/layout/stack/Stack.js.map +1 -1
- package/esm/layout/utilities/css.d.ts +1 -8
- package/esm/layout/utilities/css.js.map +1 -1
- package/esm/layout/utilities/types.d.ts +9 -0
- package/esm/loader/Loader.d.ts +1 -1
- package/esm/loader/Loader.js +1 -1
- package/esm/modal/Modal.js +39 -15
- package/esm/modal/Modal.js.map +1 -1
- package/esm/modal/ModalContext.d.ts +1 -0
- package/esm/modal/ModalContext.js.map +1 -1
- package/esm/modal/types.d.ts +7 -0
- package/esm/popover/Popover.d.ts +0 -5
- package/esm/popover/Popover.js +5 -7
- package/esm/popover/Popover.js.map +1 -1
- package/esm/tooltip/Tooltip.js +16 -5
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/util/useMedia.d.ts +8 -0
- package/esm/util/useMedia.js +27 -0
- package/esm/util/useMedia.js.map +1 -0
- package/package.json +3 -3
- package/src/accordion/AccordionHeader.tsx +3 -3
- package/src/date/context/useDateInputContext.tsx +5 -5
- package/src/date/datepicker/DatePicker.tsx +58 -65
- package/src/date/datepicker/datepicker.stories.tsx +37 -46
- package/src/date/datepicker/types.ts +0 -5
- package/src/date/hooks/useDatepicker.tsx +20 -25
- package/src/date/hooks/useMonthPicker.tsx +18 -24
- package/src/date/hooks/useRangeDatepicker.tsx +27 -30
- package/src/date/index.ts +1 -1
- package/src/date/monthpicker/MonthPicker.tsx +39 -43
- package/src/date/monthpicker/types.ts +0 -5
- package/src/date/{DateInput.tsx → parts/DateInput.tsx} +23 -12
- package/src/date/parts/DateWrapper.tsx +80 -0
- package/src/date/utils/labels.ts +83 -0
- package/src/form/combobox/Combobox.tsx +2 -2
- package/src/form/combobox/ComboboxProvider.tsx +1 -2
- package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +28 -16
- package/src/form/combobox/FilteredOptions/filtered-options-util.ts +38 -0
- package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +71 -142
- package/src/form/combobox/FilteredOptions/useVirtualFocus.ts +87 -0
- package/src/form/combobox/Input/Input.tsx +40 -21
- package/src/form/combobox/combobox.stories.tsx +44 -0
- package/src/form/combobox/customOptionsContext.tsx +10 -5
- package/src/guide-panel/guidepanel.stories.tsx +2 -2
- package/src/layout/bleed/Bleed.tsx +2 -5
- package/src/layout/box/Box.tsx +1 -3
- package/src/layout/grid/HGrid.tsx +2 -6
- package/src/layout/responsive/Responsive.tsx +1 -1
- package/src/layout/sidemal-test/Sidebar.tsx +1 -1
- package/src/layout/stack/Stack.tsx +2 -6
- package/src/layout/utilities/css.ts +1 -36
- package/src/layout/utilities/types.ts +16 -0
- package/src/loader/Loader.tsx +1 -1
- package/src/modal/Modal.tsx +54 -21
- package/src/modal/ModalContext.ts +1 -0
- package/src/modal/modal.stories.tsx +30 -2
- package/src/modal/types.ts +7 -0
- package/src/popover/Popover.tsx +4 -12
- package/src/tooltip/Tooltip.tsx +18 -6
- package/src/util/__tests__/useMedia.test.tsx +19 -0
- package/src/util/useMedia.ts +38 -0
- package/cjs/date/hooks/useEscape.js +0 -23
- package/cjs/date/hooks/useOutsideClickHandler.js +0 -26
- package/esm/date/DateInput.js.map +0 -1
- package/esm/date/hooks/useEscape.d.ts +0 -2
- package/esm/date/hooks/useEscape.js +0 -20
- package/esm/date/hooks/useEscape.js.map +0 -1
- package/esm/date/hooks/useOutsideClickHandler.d.ts +0 -1
- package/esm/date/hooks/useOutsideClickHandler.js +0 -23
- package/esm/date/hooks/useOutsideClickHandler.js.map +0 -1
- package/src/date/hooks/useEscape.tsx +0 -30
- package/src/date/hooks/useOutsideClickHandler.tsx +0 -34
|
@@ -6,27 +6,28 @@ import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsCon
|
|
|
6
6
|
import { useInputContext } from "../Input/inputContext";
|
|
7
7
|
import { Loader } from "../../../loader";
|
|
8
8
|
import { BodyShort, Label } from "../../../typography";
|
|
9
|
+
import filteredOptionsUtil from "./filtered-options-util";
|
|
9
10
|
const FilteredOptions = () => {
|
|
10
11
|
const { inputProps: { id }, size, value, } = useInputContext();
|
|
11
|
-
const { allowNewValues, isLoading, isListOpen, filteredOptions,
|
|
12
|
+
const { allowNewValues, isLoading, isListOpen, filteredOptions, setFilteredOptionsRef, isMouseLastUsedInputDevice, setIsMouseLastUsedInputDevice, isValueNew, toggleIsListOpen, activeDecendantId, virtualFocus, } = useFilteredOptionsContext();
|
|
12
13
|
const { isMultiSelect, selectedOptions, toggleOption } = useSelectedOptionsContext();
|
|
13
|
-
return (React.createElement("ul", { ref:
|
|
14
|
+
return (React.createElement("ul", { ref: setFilteredOptionsRef, className: cl("navds-combobox__list", {
|
|
14
15
|
"navds-combobox__list--closed": !isListOpen,
|
|
15
16
|
"navds-combobox__list--with-hover": isMouseLastUsedInputDevice,
|
|
16
|
-
}), id:
|
|
17
|
-
isLoading && (React.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id:
|
|
17
|
+
}), id: filteredOptionsUtil.getFilteredOptionsId(id), role: "listbox", tabIndex: -1 },
|
|
18
|
+
isLoading && (React.createElement("li", { className: "navds-combobox__list-item--loading", role: "option", "aria-selected": false, id: filteredOptionsUtil.getIsLoadingId(id), "data-no-focus": "true" },
|
|
18
19
|
React.createElement(Loader, { "aria-label": "S\u00F8ker..." }))),
|
|
19
20
|
isValueNew && allowNewValues && (React.createElement("li", { tabIndex: -1, onMouseMove: () => {
|
|
20
|
-
if (
|
|
21
|
-
|
|
21
|
+
if (activeDecendantId !== filteredOptionsUtil.getAddNewOptionId(id)) {
|
|
22
|
+
virtualFocus.moveFocusToElement(filteredOptionsUtil.getAddNewOptionId(id));
|
|
22
23
|
setIsMouseLastUsedInputDevice(true);
|
|
23
24
|
}
|
|
24
25
|
}, onPointerUp: (event) => {
|
|
25
26
|
toggleOption(value, event);
|
|
26
27
|
if (!isMultiSelect && !selectedOptions.includes(value))
|
|
27
28
|
toggleIsListOpen(false);
|
|
28
|
-
}, id:
|
|
29
|
-
"navds-combobox__list-item__new-option--focus":
|
|
29
|
+
}, id: filteredOptionsUtil.getAddNewOptionId(id), className: cl("navds-combobox__list-item__new-option", {
|
|
30
|
+
"navds-combobox__list-item__new-option--focus": activeDecendantId === filteredOptionsUtil.getAddNewOptionId(id),
|
|
30
31
|
}), role: "option", "aria-selected": false },
|
|
31
32
|
React.createElement(PlusIcon, { "aria-hidden": true }),
|
|
32
33
|
React.createElement(BodyShort, { size: size },
|
|
@@ -36,13 +37,13 @@ const FilteredOptions = () => {
|
|
|
36
37
|
"\u201C",
|
|
37
38
|
value,
|
|
38
39
|
"\u201D")))),
|
|
39
|
-
!isLoading && filteredOptions.length === 0 && (React.createElement("li", { className: "navds-combobox__list-item__no-options", role: "option", "aria-selected": false, id:
|
|
40
|
-
filteredOptions.map((option
|
|
41
|
-
"navds-combobox__list-item--focus":
|
|
40
|
+
!isLoading && filteredOptions.length === 0 && (React.createElement("li", { className: "navds-combobox__list-item__no-options", role: "option", "aria-selected": false, id: filteredOptionsUtil.getNoHitsId(id), "data-no-focus": "true" }, "Ingen s\u00F8ketreff")),
|
|
41
|
+
filteredOptions.map((option) => (React.createElement("li", { className: cl("navds-combobox__list-item", {
|
|
42
|
+
"navds-combobox__list-item--focus": activeDecendantId === filteredOptionsUtil.getOptionId(id, option),
|
|
42
43
|
"navds-combobox__list-item--selected": selectedOptions.includes(option),
|
|
43
|
-
}), id:
|
|
44
|
-
if (
|
|
45
|
-
|
|
44
|
+
}), id: filteredOptionsUtil.getOptionId(id, option), key: option, tabIndex: -1, onMouseMove: () => {
|
|
45
|
+
if (activeDecendantId !== filteredOptionsUtil.getOptionId(id, option)) {
|
|
46
|
+
virtualFocus.moveFocusToElement(filteredOptionsUtil.getOptionId(id, option));
|
|
46
47
|
setIsMouseLastUsedInputDevice(true);
|
|
47
48
|
}
|
|
48
49
|
}, onPointerUp: (event) => {
|
|
@@ -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,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;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"FilteredOptions.js","sourceRoot":"","sources":["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eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
normalizeText: (text: string) => string;
|
|
3
|
+
isPartOfText: (value: any, text: any) => boolean;
|
|
4
|
+
isValueInList: (value: any, list: any) => any;
|
|
5
|
+
getMatchingValuesFromList: (value: any, list: any) => any;
|
|
6
|
+
getFilteredOptionsId: (comboboxId: string) => string;
|
|
7
|
+
getAddNewOptionId: (comboboxId: string) => string;
|
|
8
|
+
getOptionId: (comboboxId: string, option: string) => string;
|
|
9
|
+
getIsLoadingId: (comboboxId: string) => string;
|
|
10
|
+
getNoHitsId: (comboboxId: string) => string;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const normalizeText = (text) => typeof text === "string" ? text.toLocaleLowerCase().trim() : "";
|
|
2
|
+
const isPartOfText = (value, text) => normalizeText(text).startsWith(normalizeText(value !== null && value !== void 0 ? value : ""));
|
|
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));
|
|
5
|
+
const getFilteredOptionsId = (comboboxId) => `${comboboxId}-filtered-options`;
|
|
6
|
+
const getOptionId = (comboboxId, option) => `${comboboxId.toLocaleLowerCase()}-option-${option
|
|
7
|
+
.replace(" ", "-")
|
|
8
|
+
.toLocaleLowerCase()}`;
|
|
9
|
+
const getAddNewOptionId = (comboboxId) => `${comboboxId}-combobox-new-option`;
|
|
10
|
+
const getIsLoadingId = (comboboxId) => `${comboboxId}-is-loading`;
|
|
11
|
+
const getNoHitsId = (comboboxId) => `${comboboxId}-no-hits`;
|
|
12
|
+
export default {
|
|
13
|
+
normalizeText,
|
|
14
|
+
isPartOfText,
|
|
15
|
+
isValueInList,
|
|
16
|
+
getMatchingValuesFromList,
|
|
17
|
+
getFilteredOptionsId,
|
|
18
|
+
getAddNewOptionId,
|
|
19
|
+
getOptionId,
|
|
20
|
+
getIsLoadingId,
|
|
21
|
+
getNoHitsId,
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=filtered-options-util.js.map
|
|
@@ -0,0 +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,EAAE,CAC7C,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAElE,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACnC,aAAa,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC,CAAC;AAE7D,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CACpC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE7E,MAAM,yBAAyB,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAChD,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE5D,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,eAAe;IACb,aAAa;IACb,YAAY;IACZ,aAAa;IACb,yBAAyB;IACzB,oBAAoB;IACpB,iBAAiB;IACjB,WAAW;IACX,cAAc;IACd,WAAW;CACZ,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React, { SetStateAction } from "react";
|
|
2
|
+
import { VirtualFocusType } from "./useVirtualFocus";
|
|
3
|
+
import { ComboboxProps } from "../types";
|
|
4
|
+
type FilteredOptionsProps = {
|
|
5
|
+
children: any;
|
|
6
|
+
value: Pick<ComboboxProps, "allowNewValues" | "filteredOptions" | "isListOpen" | "isLoading" | "options">;
|
|
7
|
+
};
|
|
2
8
|
type FilteredOptionsContextType = {
|
|
3
9
|
activeDecendantId?: string;
|
|
4
10
|
allowNewValues?: boolean;
|
|
5
11
|
ariaDescribedBy?: string;
|
|
6
|
-
|
|
7
|
-
filteredOptionsIndex: number | null;
|
|
8
|
-
setFilteredOptionsIndex: (index: number) => void;
|
|
12
|
+
setFilteredOptionsRef: React.Dispatch<React.SetStateAction<HTMLUListElement | null>>;
|
|
9
13
|
isListOpen: boolean;
|
|
10
14
|
isLoading?: boolean;
|
|
11
15
|
filteredOptions: string[];
|
|
@@ -13,17 +17,10 @@ type FilteredOptionsContextType = {
|
|
|
13
17
|
setIsMouseLastUsedInputDevice: React.Dispatch<SetStateAction<boolean>>;
|
|
14
18
|
isValueNew: boolean;
|
|
15
19
|
toggleIsListOpen: (newState?: boolean) => void;
|
|
16
|
-
currentOption
|
|
17
|
-
resetFilteredOptionsIndex: () => void;
|
|
18
|
-
moveFocusUp: () => void;
|
|
19
|
-
moveFocusDown: () => void;
|
|
20
|
-
moveFocusToInput: () => void;
|
|
21
|
-
moveFocusToEnd: () => void;
|
|
20
|
+
currentOption?: string;
|
|
22
21
|
shouldAutocomplete?: boolean;
|
|
22
|
+
virtualFocus: VirtualFocusType;
|
|
23
23
|
};
|
|
24
|
-
export declare const FilteredOptionsProvider: ({ children, value: props }:
|
|
25
|
-
children: any;
|
|
26
|
-
value: any;
|
|
27
|
-
}) => React.JSX.Element;
|
|
24
|
+
export declare const FilteredOptionsProvider: ({ children, value: props, }: FilteredOptionsProps) => React.JSX.Element;
|
|
28
25
|
export declare const useFilteredOptionsContext: () => FilteredOptionsContextType;
|
|
29
26
|
export {};
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import React, { useState,
|
|
1
|
+
import React, { useState, useMemo, createContext, useContext, useCallback, } from "react";
|
|
2
2
|
import cl from "clsx";
|
|
3
3
|
import { useCustomOptionsContext } from "../customOptionsContext";
|
|
4
4
|
import { useInputContext } from "../Input/inputContext";
|
|
5
5
|
import usePrevious from "../../../util/usePrevious";
|
|
6
6
|
import { useClientLayoutEffect } from "../../../util";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const isValueInList = (value, list) => list === null || list === void 0 ? void 0 : list.find((listItem) => normalizeText(value) === normalizeText(listItem));
|
|
10
|
-
const getMatchingValuesFromList = (value, list) => list === null || list === void 0 ? void 0 : list.filter((listItem) => isPartOfText(value, listItem));
|
|
7
|
+
import filteredOptionsUtils from "./filtered-options-util";
|
|
8
|
+
import useVirtualFocus from "./useVirtualFocus";
|
|
11
9
|
const FilteredOptionsContext = createContext({});
|
|
12
|
-
export const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
10
|
+
export const FilteredOptionsProvider = ({ children, value: props, }) => {
|
|
13
11
|
const { allowNewValues, filteredOptions: externalFilteredOptions, isListOpen: isExternalListOpen, isLoading, options, } = props;
|
|
14
|
-
const filteredOptionsRef =
|
|
12
|
+
const [filteredOptionsRef, setFilteredOptionsRef] = useState(null);
|
|
13
|
+
const virtualFocus = useVirtualFocus(filteredOptionsRef);
|
|
15
14
|
const { inputProps: { "aria-describedby": partialAriaDescribedBy, id }, value, searchTerm, setValue, setSearchTerm, shouldAutocomplete, } = useInputContext();
|
|
16
|
-
const [filteredOptionsIndex, setFilteredOptionsIndex] = useState(null);
|
|
17
15
|
const [isInternalListOpen, setInternalListOpen] = useState(false);
|
|
18
16
|
const { customOptions } = useCustomOptionsContext();
|
|
19
17
|
const filteredOptions = useMemo(() => {
|
|
@@ -21,17 +19,20 @@ export const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
|
21
19
|
return externalFilteredOptions;
|
|
22
20
|
}
|
|
23
21
|
const opts = [...customOptions, ...options];
|
|
24
|
-
|
|
25
|
-
return getMatchingValuesFromList(searchTerm, opts);
|
|
22
|
+
return filteredOptionsUtils.getMatchingValuesFromList(searchTerm, opts);
|
|
26
23
|
}, [customOptions, externalFilteredOptions, options, searchTerm]);
|
|
27
24
|
const previousSearchTerm = usePrevious(searchTerm);
|
|
28
25
|
const [isMouseLastUsedInputDevice, setIsMouseLastUsedInputDevice] = useState(false);
|
|
26
|
+
const filteredOptionsMap = useMemo(() => options.reduce((map, _option) => (Object.assign(Object.assign({}, map), { [filteredOptionsUtils.getOptionId(id, _option)]: _option })), {
|
|
27
|
+
[filteredOptionsUtils.getAddNewOptionId(id)]: allowNewValues
|
|
28
|
+
? value
|
|
29
|
+
: undefined,
|
|
30
|
+
}), [allowNewValues, id, options, value]);
|
|
29
31
|
useClientLayoutEffect(() => {
|
|
30
32
|
if (shouldAutocomplete &&
|
|
31
|
-
normalizeText(searchTerm) !== "" &&
|
|
33
|
+
filteredOptionsUtils.normalizeText(searchTerm) !== "" &&
|
|
32
34
|
((previousSearchTerm === null || previousSearchTerm === void 0 ? void 0 : previousSearchTerm.length) || 0) < searchTerm.length &&
|
|
33
|
-
filteredOptions.length > 0
|
|
34
|
-
!isValueInList(searchTerm, filteredOptions)) {
|
|
35
|
+
filteredOptions.length > 0) {
|
|
35
36
|
setValue(`${searchTerm}${filteredOptions[0].substring(searchTerm.length)}`);
|
|
36
37
|
setSearchTerm(searchTerm);
|
|
37
38
|
}
|
|
@@ -47,24 +48,22 @@ export const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
|
47
48
|
return isExternalListOpen !== null && isExternalListOpen !== void 0 ? isExternalListOpen : isInternalListOpen;
|
|
48
49
|
}, [isExternalListOpen, isInternalListOpen]);
|
|
49
50
|
const toggleIsListOpen = useCallback((newState) => {
|
|
50
|
-
|
|
51
|
+
virtualFocus.moveFocusToTop();
|
|
51
52
|
setInternalListOpen((oldState) => newState !== null && newState !== void 0 ? newState : !oldState);
|
|
52
|
-
}, []);
|
|
53
|
-
const isValueNew = useMemo(() => Boolean(value) &&
|
|
54
|
-
|
|
55
|
-
return isValueNew && allowNewValues ? -1 : 0;
|
|
56
|
-
}, [allowNewValues, isValueNew]);
|
|
53
|
+
}, [virtualFocus]);
|
|
54
|
+
const isValueNew = useMemo(() => Boolean(value) &&
|
|
55
|
+
!filteredOptionsMap[filteredOptionsUtils.getOptionId(id, value)], [filteredOptionsMap, id, value]);
|
|
57
56
|
const ariaDescribedBy = useMemo(() => {
|
|
58
57
|
let activeOption;
|
|
59
58
|
if (!isLoading && filteredOptions.length === 0) {
|
|
60
|
-
activeOption =
|
|
59
|
+
activeOption = filteredOptionsUtils.getNoHitsId(id);
|
|
61
60
|
}
|
|
62
61
|
else if ((value && value !== "") || isLoading) {
|
|
63
62
|
if (shouldAutocomplete && filteredOptions[0]) {
|
|
64
|
-
activeOption =
|
|
63
|
+
activeOption = filteredOptionsUtils.getOptionId(id, filteredOptions[0]);
|
|
65
64
|
}
|
|
66
65
|
else if (isListOpen && isLoading) {
|
|
67
|
-
activeOption =
|
|
66
|
+
activeOption = filteredOptionsUtils.getIsLoadingId(id);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
return cl(activeOption, partialAriaDescribedBy) || undefined;
|
|
@@ -77,91 +76,12 @@ export const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
|
77
76
|
filteredOptions,
|
|
78
77
|
id,
|
|
79
78
|
]);
|
|
80
|
-
const currentOption = useMemo(() => {
|
|
81
|
-
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
if (filteredOptionsIndex === -1) {
|
|
85
|
-
return value;
|
|
86
|
-
}
|
|
87
|
-
return filteredOptions[filteredOptionsIndex];
|
|
88
|
-
}, [filteredOptionsIndex, filteredOptions, value]);
|
|
89
|
-
const resetFilteredOptionsIndex = () => {
|
|
90
|
-
setFilteredOptionsIndex(getMinimumIndex());
|
|
91
|
-
};
|
|
92
|
-
const scrollToOption = useCallback((newIndex) => {
|
|
93
|
-
if (filteredOptionsRef.current &&
|
|
94
|
-
filteredOptionsRef.current.children[newIndex]) {
|
|
95
|
-
const child = filteredOptionsRef.current.children[newIndex];
|
|
96
|
-
const { top, bottom } = child.getBoundingClientRect();
|
|
97
|
-
const parentRect = filteredOptionsRef.current.getBoundingClientRect();
|
|
98
|
-
if (top < parentRect.top || bottom > parentRect.bottom) {
|
|
99
|
-
child.scrollIntoView({ block: "nearest" });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, []);
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
if (filteredOptionsIndex !== null && isListOpen) {
|
|
105
|
-
scrollToOption(filteredOptionsIndex);
|
|
106
|
-
}
|
|
107
|
-
}, [filteredOptionsIndex, isListOpen, scrollToOption]);
|
|
108
|
-
const moveFocusToInput = useCallback(() => {
|
|
109
|
-
setFilteredOptionsIndex(null);
|
|
110
|
-
toggleIsListOpen(false);
|
|
111
|
-
}, [toggleIsListOpen]);
|
|
112
|
-
const moveFocusToEnd = useCallback(() => {
|
|
113
|
-
const lastIndex = filteredOptions.length - 1;
|
|
114
|
-
toggleIsListOpen(true);
|
|
115
|
-
setFilteredOptionsIndex(lastIndex);
|
|
116
|
-
}, [filteredOptions.length, toggleIsListOpen]);
|
|
117
|
-
const moveFocusUp = useCallback(() => {
|
|
118
|
-
if (filteredOptionsIndex === null) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (filteredOptionsIndex === getMinimumIndex()) {
|
|
122
|
-
toggleIsListOpen(false);
|
|
123
|
-
setFilteredOptionsIndex(null);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
const newIndex = Math.max(getMinimumIndex(), filteredOptionsIndex - 1);
|
|
127
|
-
setFilteredOptionsIndex(newIndex);
|
|
128
|
-
}
|
|
129
|
-
}, [filteredOptionsIndex, getMinimumIndex, toggleIsListOpen]);
|
|
130
|
-
const moveFocusDown = useCallback(() => {
|
|
131
|
-
if (filteredOptionsIndex === null || !isListOpen) {
|
|
132
|
-
toggleIsListOpen(true);
|
|
133
|
-
if (allowNewValues || filteredOptions.length >= 1) {
|
|
134
|
-
setFilteredOptionsIndex(getMinimumIndex());
|
|
135
|
-
}
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const newIndex = Math.min(filteredOptionsIndex + 1, Math.max(getMinimumIndex(), filteredOptions.length - 1));
|
|
139
|
-
setFilteredOptionsIndex(newIndex);
|
|
140
|
-
}, [
|
|
141
|
-
allowNewValues,
|
|
142
|
-
filteredOptions.length,
|
|
143
|
-
filteredOptionsIndex,
|
|
144
|
-
getMinimumIndex,
|
|
145
|
-
isListOpen,
|
|
146
|
-
toggleIsListOpen,
|
|
147
|
-
]);
|
|
148
|
-
const activeDecendantId = useMemo(() => {
|
|
149
|
-
if (filteredOptionsIndex === null) {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
else if (filteredOptionsIndex === -1) {
|
|
153
|
-
return `${id}-combobox-new-option`;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
return `${id}-option-${currentOption === null || currentOption === void 0 ? void 0 : currentOption.replace(" ", "-")}`;
|
|
157
|
-
}
|
|
158
|
-
}, [filteredOptionsIndex, currentOption, id]);
|
|
79
|
+
const currentOption = useMemo(() => { var _a; return filteredOptionsMap[((_a = virtualFocus.activeElement) === null || _a === void 0 ? void 0 : _a.getAttribute("id")) || -1]; }, [filteredOptionsMap, virtualFocus]);
|
|
80
|
+
const activeDecendantId = useMemo(() => { var _a; return ((_a = virtualFocus.activeElement) === null || _a === void 0 ? void 0 : _a.getAttribute("id")) || undefined; }, [virtualFocus.activeElement]);
|
|
159
81
|
const filteredOptionsState = {
|
|
160
82
|
activeDecendantId,
|
|
161
83
|
allowNewValues,
|
|
162
|
-
|
|
163
|
-
filteredOptionsIndex,
|
|
164
|
-
setFilteredOptionsIndex,
|
|
84
|
+
setFilteredOptionsRef,
|
|
165
85
|
shouldAutocomplete,
|
|
166
86
|
isListOpen,
|
|
167
87
|
isLoading,
|
|
@@ -171,11 +91,7 @@ export const FilteredOptionsProvider = ({ children, value: props }) => {
|
|
|
171
91
|
isValueNew,
|
|
172
92
|
toggleIsListOpen,
|
|
173
93
|
currentOption,
|
|
174
|
-
|
|
175
|
-
moveFocusUp,
|
|
176
|
-
moveFocusDown,
|
|
177
|
-
moveFocusToInput,
|
|
178
|
-
moveFocusToEnd,
|
|
94
|
+
virtualFocus,
|
|
179
95
|
ariaDescribedBy,
|
|
180
96
|
};
|
|
181
97
|
return (React.createElement(FilteredOptionsContext.Provider, { value: filteredOptionsState }, children));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filteredOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/filteredOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"filteredOptionsContext.js","sourceRoot":"","sources":["../../../../src/form/combobox/FilteredOptions/filteredOptionsContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK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AAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from "react";
|
|
2
|
+
export type VirtualFocusType = {
|
|
3
|
+
activeElement: HTMLElement | undefined;
|
|
4
|
+
getElementById: (id: string) => HTMLElement | undefined;
|
|
5
|
+
isFocusOnTheTop: boolean;
|
|
6
|
+
isFocusOnTheBottom: boolean;
|
|
7
|
+
setIndex: Dispatch<SetStateAction<number>>;
|
|
8
|
+
moveFocusUp: () => void;
|
|
9
|
+
moveFocusDown: () => void;
|
|
10
|
+
moveFocusToElement: (id: string) => void;
|
|
11
|
+
moveFocusToTop: () => void;
|
|
12
|
+
moveFocusToBottom: () => void;
|
|
13
|
+
};
|
|
14
|
+
declare const useVirtualFocus: (containerRef: HTMLElement | null) => VirtualFocusType;
|
|
15
|
+
export default useVirtualFocus;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
const useVirtualFocus = (containerRef) => {
|
|
3
|
+
const [index, setIndex] = useState(-1);
|
|
4
|
+
const listOfAllChildren = (containerRef === null || containerRef === void 0 ? void 0 : containerRef.children)
|
|
5
|
+
? Array.prototype.slice.call(containerRef === null || containerRef === void 0 ? void 0 : containerRef.children)
|
|
6
|
+
: [];
|
|
7
|
+
const elementsAbleToReceiveFocus = listOfAllChildren.filter((child) => child.getAttribute("data-no-focus") !== "true");
|
|
8
|
+
const activeElement = elementsAbleToReceiveFocus[index];
|
|
9
|
+
const getElementById = (id) => listOfAllChildren.find((element) => element.id === id);
|
|
10
|
+
const isFocusOnTheTop = index === 0;
|
|
11
|
+
const isFocusOnTheBottom = index === elementsAbleToReceiveFocus.length - 1;
|
|
12
|
+
const scrollToOption = (newIndex) => {
|
|
13
|
+
const indexOfElementToScrollTo = Math.min(Math.max(newIndex, 0), (containerRef === null || containerRef === void 0 ? void 0 : containerRef.children.length) || 0);
|
|
14
|
+
if (containerRef === null || containerRef === void 0 ? void 0 : containerRef.children[indexOfElementToScrollTo]) {
|
|
15
|
+
const child = containerRef.children[indexOfElementToScrollTo];
|
|
16
|
+
const { top, bottom } = child.getBoundingClientRect();
|
|
17
|
+
const parentRect = containerRef.getBoundingClientRect();
|
|
18
|
+
if (top < parentRect.top || bottom > parentRect.bottom) {
|
|
19
|
+
child.scrollIntoView({ block: "nearest" });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const _moveFocusAndScrollTo = (_index) => {
|
|
24
|
+
setIndex(_index);
|
|
25
|
+
scrollToOption(_index);
|
|
26
|
+
};
|
|
27
|
+
const moveFocusUp = () => _moveFocusAndScrollTo(Math.max(index - 1, -1));
|
|
28
|
+
const moveFocusDown = () => _moveFocusAndScrollTo(Math.min(index + 1, elementsAbleToReceiveFocus.length - 1));
|
|
29
|
+
const moveFocusToTop = () => _moveFocusAndScrollTo(-1);
|
|
30
|
+
const moveFocusToBottom = () => _moveFocusAndScrollTo(elementsAbleToReceiveFocus.length - 1);
|
|
31
|
+
const moveFocusToElement = (id) => {
|
|
32
|
+
const thisElement = elementsAbleToReceiveFocus.find((_element) => _element.getAttribute("id") === id);
|
|
33
|
+
const indexOfElement = thisElement
|
|
34
|
+
? elementsAbleToReceiveFocus.indexOf(thisElement)
|
|
35
|
+
: -1;
|
|
36
|
+
if (indexOfElement >= 0) {
|
|
37
|
+
setIndex(indexOfElement);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
activeElement,
|
|
42
|
+
getElementById,
|
|
43
|
+
isFocusOnTheTop,
|
|
44
|
+
isFocusOnTheBottom,
|
|
45
|
+
setIndex,
|
|
46
|
+
moveFocusUp,
|
|
47
|
+
moveFocusDown,
|
|
48
|
+
moveFocusToElement,
|
|
49
|
+
moveFocusToTop,
|
|
50
|
+
moveFocusToBottom,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export default useVirtualFocus;
|
|
54
|
+
//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W,GAAG,0BAA0B,CAAC,IAAI,CACjD,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,CACjD,CAAC;QACF,MAAM,cAAc,GAAG,WAAW;YAChC,CAAC,CAAC,0BAA0B,CAAC,OAAO,CAAC,WAAW,CAAC;YACjD,CAAC,CAAC,CAAC,CAAC,CAAC;QACP,IAAI,cAAc,IAAI,CAAC,EAAE;YACvB,QAAQ,CAAC,cAAc,CAAC,CAAC;SAC1B;IACH,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QACb,cAAc;QACd,eAAe;QACf,kBAAkB;QAClB,QAAQ;QACR,WAAW;QACX,aAAa;QACb,kBAAkB;QAClB,cAAc;QACd,iBAAiB;KAClB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -15,20 +15,25 @@ import cl from "clsx";
|
|
|
15
15
|
import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
|
|
16
16
|
import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
|
|
17
17
|
import { useInputContext } from "./inputContext";
|
|
18
|
+
import filteredOptionsUtil from "../FilteredOptions/filtered-options-util";
|
|
18
19
|
const Input = forwardRef((_a, ref) => {
|
|
19
20
|
var { inputClassName } = _a, rest = __rest(_a, ["inputClassName"]);
|
|
20
21
|
const { clearInput, inputProps, onChange, size, value } = useInputContext();
|
|
21
22
|
const { selectedOptions, removeSelectedOption, toggleOption, isMultiSelect, } = useSelectedOptionsContext();
|
|
22
|
-
const { activeDecendantId, allowNewValues, currentOption, filteredOptions, toggleIsListOpen, isListOpen,
|
|
23
|
+
const { activeDecendantId, allowNewValues, currentOption, filteredOptions, isValueNew, toggleIsListOpen, isListOpen, ariaDescribedBy, setIsMouseLastUsedInputDevice, shouldAutocomplete, virtualFocus, } = useFilteredOptionsContext();
|
|
23
24
|
const onEnter = useCallback((event) => {
|
|
25
|
+
const isTextInSelectedOptions = (text) => {
|
|
26
|
+
return selectedOptions.find((item) => item.toLocaleLowerCase() === text.toLocaleLowerCase());
|
|
27
|
+
};
|
|
24
28
|
if (currentOption) {
|
|
25
29
|
event.preventDefault();
|
|
26
30
|
// Selecting a value from the dropdown / FilteredOptions
|
|
27
31
|
toggleOption(currentOption, event);
|
|
28
|
-
if (!isMultiSelect && !
|
|
32
|
+
if (!isMultiSelect && !isTextInSelectedOptions(currentOption)) {
|
|
29
33
|
toggleIsListOpen(false);
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
|
-
else if (shouldAutocomplete &&
|
|
36
|
+
else if (shouldAutocomplete && isTextInSelectedOptions(value)) {
|
|
32
37
|
event.preventDefault();
|
|
33
38
|
// Trying to set the same value that is already set, so just clearing the input
|
|
34
39
|
clearInput(event);
|
|
@@ -36,15 +41,20 @@ const Input = forwardRef((_a, ref) => {
|
|
|
36
41
|
else if ((allowNewValues || shouldAutocomplete) && value !== "") {
|
|
37
42
|
event.preventDefault();
|
|
38
43
|
// Autocompleting or adding a new value
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
const selectedValue = allowNewValues && isValueNew ? value : filteredOptions[0];
|
|
45
|
+
toggleOption(selectedValue, event);
|
|
46
|
+
if (!isMultiSelect &&
|
|
47
|
+
!isTextInSelectedOptions(filteredOptions[0] || selectedValue)) {
|
|
41
48
|
toggleIsListOpen(false);
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
}, [
|
|
44
52
|
allowNewValues,
|
|
45
53
|
clearInput,
|
|
46
54
|
currentOption,
|
|
55
|
+
filteredOptions,
|
|
47
56
|
isMultiSelect,
|
|
57
|
+
isValueNew,
|
|
48
58
|
selectedOptions,
|
|
49
59
|
shouldAutocomplete,
|
|
50
60
|
toggleIsListOpen,
|
|
@@ -63,10 +73,10 @@ const Input = forwardRef((_a, ref) => {
|
|
|
63
73
|
onEnter(e);
|
|
64
74
|
break;
|
|
65
75
|
case "Home":
|
|
66
|
-
|
|
76
|
+
virtualFocus.moveFocusToTop();
|
|
67
77
|
break;
|
|
68
78
|
case "End":
|
|
69
|
-
|
|
79
|
+
virtualFocus.moveFocusToBottom();
|
|
70
80
|
break;
|
|
71
81
|
default:
|
|
72
82
|
break;
|
|
@@ -85,26 +95,32 @@ const Input = forwardRef((_a, ref) => {
|
|
|
85
95
|
// so we don't interfere with text editing
|
|
86
96
|
if (e.target.selectionStart === (value === null || value === void 0 ? void 0 : value.length)) {
|
|
87
97
|
e.preventDefault();
|
|
88
|
-
|
|
98
|
+
if (virtualFocus.activeElement === null || !isListOpen) {
|
|
99
|
+
toggleIsListOpen(true);
|
|
100
|
+
}
|
|
101
|
+
virtualFocus.moveFocusDown();
|
|
89
102
|
}
|
|
90
103
|
}
|
|
91
104
|
else if (e.key === "ArrowUp") {
|
|
92
105
|
// Check that the FilteredOptions list is open and has virtual focus.
|
|
93
106
|
// Otherwise ignore keystrokes, so it doesn't interfere with text editing
|
|
94
|
-
if (isListOpen &&
|
|
107
|
+
if (isListOpen && activeDecendantId) {
|
|
95
108
|
e.preventDefault();
|
|
96
|
-
|
|
109
|
+
if (virtualFocus.isFocusOnTheTop) {
|
|
110
|
+
toggleIsListOpen(false);
|
|
111
|
+
}
|
|
112
|
+
virtualFocus.moveFocusUp();
|
|
97
113
|
}
|
|
98
114
|
}
|
|
99
115
|
}, [
|
|
100
116
|
value,
|
|
101
117
|
selectedOptions,
|
|
102
118
|
removeSelectedOption,
|
|
103
|
-
moveFocusDown,
|
|
104
119
|
isListOpen,
|
|
105
|
-
|
|
106
|
-
moveFocusUp,
|
|
120
|
+
activeDecendantId,
|
|
107
121
|
setIsMouseLastUsedInputDevice,
|
|
122
|
+
toggleIsListOpen,
|
|
123
|
+
virtualFocus,
|
|
108
124
|
]);
|
|
109
125
|
const onChangeHandler = useCallback((event) => {
|
|
110
126
|
const newValue = event.target.value;
|
|
@@ -114,12 +130,13 @@ const Input = forwardRef((_a, ref) => {
|
|
|
114
130
|
else if (filteredOptions.length === 0) {
|
|
115
131
|
toggleIsListOpen(false);
|
|
116
132
|
}
|
|
133
|
+
virtualFocus.moveFocusToTop();
|
|
117
134
|
onChange(event);
|
|
118
|
-
}, [filteredOptions.length, onChange, toggleIsListOpen]);
|
|
135
|
+
}, [filteredOptions.length, virtualFocus, onChange, toggleIsListOpen]);
|
|
119
136
|
const onBlur = () => {
|
|
120
|
-
|
|
137
|
+
virtualFocus.moveFocusToTop();
|
|
121
138
|
};
|
|
122
|
-
return (React.createElement("input", Object.assign({}, rest, omit(inputProps, ["aria-invalid"]), { ref: ref, value: value, onChange: onChangeHandler, type: "text", role: "combobox", onBlur: onBlur, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, "aria-controls":
|
|
139
|
+
return (React.createElement("input", Object.assign({}, rest, omit(inputProps, ["aria-invalid"]), { ref: ref, value: value, onChange: onChangeHandler, type: "text", role: "combobox", onBlur: onBlur, onKeyUp: handleKeyUp, onKeyDown: handleKeyDown, "aria-controls": filteredOptionsUtil.getFilteredOptionsId(inputProps.id), "aria-expanded": !!isListOpen, autoComplete: "off", "aria-autocomplete": shouldAutocomplete ? "both" : "list", "aria-activedescendant": activeDecendantId, "aria-describedby": ariaDescribedBy, "aria-invalid": inputProps["aria-invalid"], className: cl(inputClassName, "navds-combobox__input", "navds-body-short", `navds-body-short--${size}`) })));
|
|
123
140
|
});
|
|
124
141
|
export default Input;
|
|
125
142
|
//# sourceMappingURL=Input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../../src/form/combobox/Input/Input.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,EAAE,EACZ,WAAW,EACX,UAAU,GAGX,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,yBAA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CAAC,MAAM,2BAChC,iBAAiB,sBACtB,eAAe,kBACnB,UAAU,CAAC,cAAc,CAAC,EACxC,SAAS,EAAE,EAAE,CACX,cAAc,EACd,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,IAAI,EAAE,CAC5B,IACD,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,KAAK,CAAC"}
|
|
@@ -5,8 +5,11 @@ type CustomOptionsContextType = {
|
|
|
5
5
|
addCustomOption: (option: string) => void;
|
|
6
6
|
setCustomOptions: React.Dispatch<React.SetStateAction<string[]>>;
|
|
7
7
|
};
|
|
8
|
-
export declare const CustomOptionsProvider: ({ children }: {
|
|
8
|
+
export declare const CustomOptionsProvider: ({ children, value, }: {
|
|
9
9
|
children: any;
|
|
10
|
+
value: {
|
|
11
|
+
isMultiSelect?: boolean;
|
|
12
|
+
};
|
|
10
13
|
}) => React.JSX.Element;
|
|
11
14
|
export declare const useCustomOptionsContext: () => CustomOptionsContextType;
|
|
12
15
|
export {};
|