@navikt/ds-react 6.13.0 → 6.14.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.
Files changed (270) hide show
  1. package/cjs/accordion/AccordionContext.d.ts +0 -1
  2. package/cjs/collapsible/Collapsible.context.d.ts +0 -1
  3. package/cjs/date/context/useDateInputContext.d.ts +0 -1
  4. package/cjs/date/datepicker/parts/HeadRow.d.ts +0 -1
  5. package/cjs/date/datepicker/parts/HeadRow.js +2 -3
  6. package/cjs/date/datepicker/parts/HeadRow.js.map +1 -1
  7. package/cjs/date/datepicker/parts/Row.d.ts +0 -1
  8. package/cjs/date/datepicker/parts/TableHead.d.ts +0 -1
  9. package/cjs/date/datepicker/parts/WeekNumber.d.ts +0 -1
  10. package/cjs/date/datepicker/types.d.ts +0 -1
  11. package/cjs/date/monthpicker/types.d.ts +0 -1
  12. package/cjs/date/utils/check-dates.js +2 -2
  13. package/cjs/date/utils/check-dates.js.map +1 -1
  14. package/cjs/date/utils/get-initial-year.js +1 -2
  15. package/cjs/date/utils/get-initial-year.js.map +1 -1
  16. package/cjs/date/utils/get-month-weeks.js +2 -3
  17. package/cjs/date/utils/get-month-weeks.js.map +1 -1
  18. package/cjs/date/utils/is-match.js +2 -3
  19. package/cjs/date/utils/is-match.js.map +1 -1
  20. package/cjs/dropdown/Menu/index.d.ts +1 -1
  21. package/cjs/dropdown/context.d.ts +0 -1
  22. package/cjs/expansion-card/context.d.ts +0 -1
  23. package/cjs/form/checkbox/useCheckbox.d.ts +3 -3
  24. package/cjs/form/combobox/Combobox.d.ts +1 -1
  25. package/cjs/form/combobox/Combobox.js.map +1 -1
  26. package/cjs/form/combobox/ComboboxProvider.js +3 -1
  27. package/cjs/form/combobox/ComboboxProvider.js.map +1 -1
  28. package/cjs/form/combobox/FilteredOptions/filtered-options-util.d.ts +1 -0
  29. package/cjs/form/combobox/FilteredOptions/filtered-options-util.js +6 -1
  30. package/cjs/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -1
  31. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +5 -5
  32. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  33. package/cjs/form/combobox/Input/Input.context.d.ts +20 -7
  34. package/cjs/form/combobox/Input/Input.context.js +6 -12
  35. package/cjs/form/combobox/Input/Input.context.js.map +1 -1
  36. package/cjs/form/combobox/Input/Input.d.ts +1 -1
  37. package/cjs/form/combobox/Input/Input.js +42 -18
  38. package/cjs/form/combobox/Input/Input.js.map +1 -1
  39. package/cjs/form/combobox/Input/InputController.d.ts +1 -1
  40. package/cjs/form/combobox/Input/InputController.js.map +1 -1
  41. package/cjs/form/combobox/types.d.ts +8 -4
  42. package/cjs/form/fieldset/context.d.ts +0 -1
  43. package/cjs/form/fieldset/useFieldset.d.ts +1 -1
  44. package/cjs/form/file-upload/FileUpload.context.d.ts +0 -1
  45. package/cjs/form/file-upload/parts/dropzone/dropzone.types.d.ts +0 -1
  46. package/cjs/form/file-upload/parts/item/utils/format-file-size.js +1 -2
  47. package/cjs/form/file-upload/parts/item/utils/format-file-size.js.map +1 -1
  48. package/cjs/form/file-upload/useFileUpload.d.ts +1 -2
  49. package/cjs/form/file-upload/utils/is-accepted-file-type.js +1 -2
  50. package/cjs/form/file-upload/utils/is-accepted-file-type.js.map +1 -1
  51. package/cjs/form/file-upload/utils/is-accepted-size.js +1 -2
  52. package/cjs/form/file-upload/utils/is-accepted-size.js.map +1 -1
  53. package/cjs/form/radio/useRadio.d.ts +3 -3
  54. package/cjs/form/search/context.d.ts +0 -1
  55. package/cjs/layout/base/PrimitiveAsChildProps.d.ts +0 -1
  56. package/cjs/layout/grid/HGrid.js +4 -1
  57. package/cjs/layout/grid/HGrid.js.map +1 -1
  58. package/cjs/layout/stack/Stack.js +7 -2
  59. package/cjs/layout/stack/Stack.js.map +1 -1
  60. package/cjs/layout/utilities/css.js +2 -3
  61. package/cjs/layout/utilities/css.js.map +1 -1
  62. package/cjs/list/context.d.ts +0 -1
  63. package/cjs/list/types.d.ts +0 -1
  64. package/cjs/modal/ModalUtils.js +3 -3
  65. package/cjs/modal/ModalUtils.js.map +1 -1
  66. package/cjs/modal/types.d.ts +0 -1
  67. package/cjs/overlays/dismissablelayer/DismissableLayer.d.ts +1 -1
  68. package/cjs/overlays/dismissablelayer/util/dispatchCustomEvent.js +2 -2
  69. package/cjs/overlays/dismissablelayer/util/dispatchCustomEvent.js.map +1 -1
  70. package/cjs/overlays/dismissablelayer/util/useEscapeKeydown.js +1 -2
  71. package/cjs/overlays/dismissablelayer/util/useEscapeKeydown.js.map +1 -1
  72. package/cjs/overlays/dismissablelayer/util/useFocusOutside.js +1 -2
  73. package/cjs/overlays/dismissablelayer/util/useFocusOutside.js.map +1 -1
  74. package/cjs/overlays/dismissablelayer/util/usePointerDownOutside.js +1 -2
  75. package/cjs/overlays/dismissablelayer/util/usePointerDownOutside.js.map +1 -1
  76. package/cjs/overlays/floating/Floating.utils.js +2 -3
  77. package/cjs/overlays/floating/Floating.utils.js.map +1 -1
  78. package/cjs/slot/merge-props.js +1 -2
  79. package/cjs/slot/merge-props.js.map +1 -1
  80. package/cjs/stepper/context.d.ts +0 -1
  81. package/cjs/table/context.d.ts +0 -1
  82. package/cjs/tabs/Tabs.context.d.ts +1 -2
  83. package/cjs/tabs/parts/tab/useTab.d.ts +1 -2
  84. package/cjs/tabs/parts/tab/useTab.js +1 -2
  85. package/cjs/tabs/parts/tab/useTab.js.map +1 -1
  86. package/cjs/tabs/parts/tablist/useScrollButtons.d.ts +0 -1
  87. package/cjs/tabs/parts/tablist/useScrollButtons.js +1 -2
  88. package/cjs/tabs/parts/tablist/useScrollButtons.js.map +1 -1
  89. package/cjs/tabs/parts/tablist/useTabList.js +3 -3
  90. package/cjs/tabs/parts/tablist/useTabList.js.map +1 -1
  91. package/cjs/tabs/parts/tabpanel/useTabPanel.js +1 -2
  92. package/cjs/tabs/parts/tabpanel/useTabPanel.js.map +1 -1
  93. package/cjs/tabs/useTabs.d.ts +0 -1
  94. package/cjs/tabs/useTabs.js +1 -2
  95. package/cjs/tabs/useTabs.js.map +1 -1
  96. package/cjs/timeline/hooks/usePeriodContext.d.ts +0 -1
  97. package/cjs/timeline/hooks/useRowContext.d.ts +0 -1
  98. package/cjs/timeline/hooks/useTimelineContext.d.ts +0 -1
  99. package/cjs/timeline/period/types.d.ts +0 -1
  100. package/cjs/timeline/zoom/index.d.ts +1 -1
  101. package/cjs/toggle-group/ToggleGroup.context.d.ts +1 -2
  102. package/cjs/toggle-group/parts/useToggleItem.d.ts +1 -2
  103. package/cjs/toggle-group/parts/useToggleItem.js +3 -3
  104. package/cjs/toggle-group/parts/useToggleItem.js.map +1 -1
  105. package/cjs/toggle-group/useToggleGroup.d.ts +0 -1
  106. package/cjs/toggle-group/useToggleGroup.js +1 -2
  107. package/cjs/toggle-group/useToggleGroup.js.map +1 -1
  108. package/cjs/util/composeEventHandlers.d.ts +0 -1
  109. package/cjs/util/composeEventHandlers.js +1 -2
  110. package/cjs/util/composeEventHandlers.js.map +1 -1
  111. package/cjs/util/copy.js +1 -1
  112. package/cjs/util/copy.js.map +1 -1
  113. package/cjs/util/create-context.js +1 -2
  114. package/cjs/util/create-context.js.map +1 -1
  115. package/cjs/util/debounce.js +1 -1
  116. package/cjs/util/debounce.js.map +1 -1
  117. package/cjs/util/hooks/descendants/useDescendant.d.ts +1 -1
  118. package/cjs/util/hooks/descendants/useDescendant.js +1 -2
  119. package/cjs/util/hooks/descendants/useDescendant.js.map +1 -1
  120. package/cjs/util/hooks/descendants/utils.js +4 -4
  121. package/cjs/util/hooks/descendants/utils.js.map +1 -1
  122. package/cjs/util/hooks/useCallbackRef.d.ts +0 -1
  123. package/cjs/util/hooks/useCallbackRef.js +1 -2
  124. package/cjs/util/hooks/useCallbackRef.js.map +1 -1
  125. package/cjs/util/hooks/useControllableState.js +1 -2
  126. package/cjs/util/hooks/useControllableState.js.map +1 -1
  127. package/cjs/util/hooks/useId.js +1 -2
  128. package/cjs/util/hooks/useId.js.map +1 -1
  129. package/cjs/util/hooks/useMergeRefs.d.ts +1 -1
  130. package/cjs/util/hooks/useMergeRefs.js +2 -3
  131. package/cjs/util/hooks/useMergeRefs.js.map +1 -1
  132. package/cjs/util/i18n/get.js +1 -2
  133. package/cjs/util/i18n/get.js.map +1 -1
  134. package/cjs/util/i18n/i18n.context.d.ts +0 -1
  135. package/cjs/util/i18n/i18n.context.js +2 -2
  136. package/cjs/util/i18n/i18n.context.js.map +1 -1
  137. package/cjs/util/i18n/merge.js +1 -2
  138. package/cjs/util/i18n/merge.js.map +1 -1
  139. package/cjs/util/omit.js +1 -2
  140. package/cjs/util/omit.js.map +1 -1
  141. package/cjs/util/types/AsChild.d.ts +0 -1
  142. package/cjs/util/types/AsChildProps.d.ts +0 -1
  143. package/cjs/util/virtualfocus/Context.d.ts +43 -0
  144. package/cjs/util/virtualfocus/Context.js +9 -0
  145. package/cjs/util/virtualfocus/Context.js.map +1 -0
  146. package/cjs/util/virtualfocus/SlottedDivElement.d.ts +7 -0
  147. package/cjs/util/virtualfocus/SlottedDivElement.js +46 -0
  148. package/cjs/util/virtualfocus/SlottedDivElement.js.map +1 -0
  149. package/cjs/util/virtualfocus/VirtualFocus.d.ts +62 -0
  150. package/cjs/util/virtualfocus/VirtualFocus.js +90 -0
  151. package/cjs/util/virtualfocus/VirtualFocus.js.map +1 -0
  152. package/cjs/util/virtualfocus/parts/VirtualFocusAnchor.d.ts +33 -0
  153. package/cjs/util/virtualfocus/parts/VirtualFocusAnchor.js +80 -0
  154. package/cjs/util/virtualfocus/parts/VirtualFocusAnchor.js.map +1 -0
  155. package/cjs/util/virtualfocus/parts/VirtualFocusContent.d.ts +4 -0
  156. package/cjs/util/virtualfocus/parts/VirtualFocusContent.js +45 -0
  157. package/cjs/util/virtualfocus/parts/VirtualFocusContent.js.map +1 -0
  158. package/cjs/util/virtualfocus/parts/VirtualFocusItem.d.ts +18 -0
  159. package/cjs/util/virtualfocus/parts/VirtualFocusItem.js +64 -0
  160. package/cjs/util/virtualfocus/parts/VirtualFocusItem.js.map +1 -0
  161. package/esm/accordion/AccordionContext.d.ts +0 -1
  162. package/esm/collapsible/Collapsible.context.d.ts +0 -1
  163. package/esm/date/context/useDateInputContext.d.ts +0 -1
  164. package/esm/date/datepicker/parts/HeadRow.d.ts +0 -1
  165. package/esm/date/datepicker/parts/Row.d.ts +0 -1
  166. package/esm/date/datepicker/parts/TableHead.d.ts +0 -1
  167. package/esm/date/datepicker/parts/WeekNumber.d.ts +0 -1
  168. package/esm/date/datepicker/types.d.ts +0 -1
  169. package/esm/date/monthpicker/types.d.ts +0 -1
  170. package/esm/dropdown/Menu/index.d.ts +1 -1
  171. package/esm/dropdown/context.d.ts +0 -1
  172. package/esm/expansion-card/context.d.ts +0 -1
  173. package/esm/form/checkbox/useCheckbox.d.ts +3 -3
  174. package/esm/form/combobox/Combobox.d.ts +1 -1
  175. package/esm/form/combobox/Combobox.js.map +1 -1
  176. package/esm/form/combobox/ComboboxProvider.js +3 -1
  177. package/esm/form/combobox/ComboboxProvider.js.map +1 -1
  178. package/esm/form/combobox/FilteredOptions/filtered-options-util.d.ts +1 -0
  179. package/esm/form/combobox/FilteredOptions/filtered-options-util.js +6 -1
  180. package/esm/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -1
  181. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +5 -5
  182. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  183. package/esm/form/combobox/Input/Input.context.d.ts +20 -7
  184. package/esm/form/combobox/Input/Input.context.js +7 -13
  185. package/esm/form/combobox/Input/Input.context.js.map +1 -1
  186. package/esm/form/combobox/Input/Input.d.ts +1 -1
  187. package/esm/form/combobox/Input/Input.js +43 -19
  188. package/esm/form/combobox/Input/Input.js.map +1 -1
  189. package/esm/form/combobox/Input/InputController.d.ts +1 -1
  190. package/esm/form/combobox/Input/InputController.js.map +1 -1
  191. package/esm/form/combobox/types.d.ts +8 -4
  192. package/esm/form/fieldset/context.d.ts +0 -1
  193. package/esm/form/fieldset/useFieldset.d.ts +1 -1
  194. package/esm/form/file-upload/FileUpload.context.d.ts +0 -1
  195. package/esm/form/file-upload/parts/dropzone/dropzone.types.d.ts +0 -1
  196. package/esm/form/file-upload/useFileUpload.d.ts +1 -2
  197. package/esm/form/radio/useRadio.d.ts +3 -3
  198. package/esm/form/search/context.d.ts +0 -1
  199. package/esm/layout/base/PrimitiveAsChildProps.d.ts +0 -1
  200. package/esm/layout/grid/HGrid.js +4 -1
  201. package/esm/layout/grid/HGrid.js.map +1 -1
  202. package/esm/layout/stack/Stack.js +7 -2
  203. package/esm/layout/stack/Stack.js.map +1 -1
  204. package/esm/list/context.d.ts +0 -1
  205. package/esm/list/types.d.ts +0 -1
  206. package/esm/modal/types.d.ts +0 -1
  207. package/esm/overlays/dismissablelayer/DismissableLayer.d.ts +1 -1
  208. package/esm/stepper/context.d.ts +0 -1
  209. package/esm/table/context.d.ts +0 -1
  210. package/esm/tabs/Tabs.context.d.ts +1 -2
  211. package/esm/tabs/parts/tab/useTab.d.ts +1 -2
  212. package/esm/tabs/parts/tablist/useScrollButtons.d.ts +0 -1
  213. package/esm/tabs/parts/tablist/useTabList.js +2 -1
  214. package/esm/tabs/parts/tablist/useTabList.js.map +1 -1
  215. package/esm/tabs/useTabs.d.ts +0 -1
  216. package/esm/timeline/hooks/usePeriodContext.d.ts +0 -1
  217. package/esm/timeline/hooks/useRowContext.d.ts +0 -1
  218. package/esm/timeline/hooks/useTimelineContext.d.ts +0 -1
  219. package/esm/timeline/period/types.d.ts +0 -1
  220. package/esm/timeline/zoom/index.d.ts +1 -1
  221. package/esm/toggle-group/ToggleGroup.context.d.ts +1 -2
  222. package/esm/toggle-group/parts/useToggleItem.d.ts +1 -2
  223. package/esm/toggle-group/parts/useToggleItem.js +2 -1
  224. package/esm/toggle-group/parts/useToggleItem.js.map +1 -1
  225. package/esm/toggle-group/useToggleGroup.d.ts +0 -1
  226. package/esm/util/composeEventHandlers.d.ts +0 -1
  227. package/esm/util/hooks/descendants/useDescendant.d.ts +1 -1
  228. package/esm/util/hooks/useCallbackRef.d.ts +0 -1
  229. package/esm/util/hooks/useMergeRefs.d.ts +1 -1
  230. package/esm/util/i18n/i18n.context.d.ts +0 -1
  231. package/esm/util/types/AsChild.d.ts +0 -1
  232. package/esm/util/types/AsChildProps.d.ts +0 -1
  233. package/esm/util/virtualfocus/Context.d.ts +43 -0
  234. package/esm/util/virtualfocus/Context.js +5 -0
  235. package/esm/util/virtualfocus/Context.js.map +1 -0
  236. package/esm/util/virtualfocus/SlottedDivElement.d.ts +7 -0
  237. package/esm/util/virtualfocus/SlottedDivElement.js +20 -0
  238. package/esm/util/virtualfocus/SlottedDivElement.js.map +1 -0
  239. package/esm/util/virtualfocus/VirtualFocus.d.ts +62 -0
  240. package/esm/util/virtualfocus/VirtualFocus.js +63 -0
  241. package/esm/util/virtualfocus/VirtualFocus.js.map +1 -0
  242. package/esm/util/virtualfocus/parts/VirtualFocusAnchor.d.ts +33 -0
  243. package/esm/util/virtualfocus/parts/VirtualFocusAnchor.js +54 -0
  244. package/esm/util/virtualfocus/parts/VirtualFocusAnchor.js.map +1 -0
  245. package/esm/util/virtualfocus/parts/VirtualFocusContent.d.ts +4 -0
  246. package/esm/util/virtualfocus/parts/VirtualFocusContent.js +19 -0
  247. package/esm/util/virtualfocus/parts/VirtualFocusContent.js.map +1 -0
  248. package/esm/util/virtualfocus/parts/VirtualFocusItem.d.ts +18 -0
  249. package/esm/util/virtualfocus/parts/VirtualFocusItem.js +38 -0
  250. package/esm/util/virtualfocus/parts/VirtualFocusItem.js.map +1 -0
  251. package/package.json +3 -3
  252. package/src/form/combobox/Combobox.tsx +4 -1
  253. package/src/form/combobox/ComboboxProvider.tsx +3 -0
  254. package/src/form/combobox/FilteredOptions/filtered-options-util.ts +9 -1
  255. package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +8 -5
  256. package/src/form/combobox/Input/Input.context.tsx +27 -25
  257. package/src/form/combobox/Input/Input.tsx +56 -27
  258. package/src/form/combobox/Input/InputController.tsx +1 -0
  259. package/src/form/combobox/__tests__/combobox.test.tsx +174 -66
  260. package/src/form/combobox/types.ts +11 -7
  261. package/src/layout/grid/HGrid.tsx +4 -1
  262. package/src/layout/stack/Stack.tsx +6 -2
  263. package/src/tabs/parts/tablist/useTabList.ts +4 -1
  264. package/src/toggle-group/parts/useToggleItem.ts +4 -1
  265. package/src/util/virtualfocus/Context.tsx +27 -0
  266. package/src/util/virtualfocus/SlottedDivElement.tsx +17 -0
  267. package/src/util/virtualfocus/VirtualFocus.tsx +89 -0
  268. package/src/util/virtualfocus/parts/VirtualFocusAnchor.tsx +102 -0
  269. package/src/util/virtualfocus/parts/VirtualFocusContent.tsx +17 -0
  270. package/src/util/virtualfocus/parts/VirtualFocusItem.tsx +60 -0
@@ -0,0 +1,19 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { forwardRef } from "react";
13
+ import { useVirtualFocusInternalContext } from "../Context.js";
14
+ export const VirtualFocusContent = forwardRef((_a, ref) => {
15
+ var { children } = _a, rest = __rest(_a, ["children"]);
16
+ const { uniqueId } = useVirtualFocusInternalContext();
17
+ return (React.createElement("div", Object.assign({ ref: ref }, rest, { id: `virtualfocus-${uniqueId}-content` }), children));
18
+ });
19
+ //# sourceMappingURL=VirtualFocusContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualFocusContent.js","sourceRoot":"","sources":["../../../../src/util/virtualfocus/parts/VirtualFocusContent.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAK5D,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAG3C,CAAC,EAAqB,EAAE,GAAG,EAAE,EAAE;QAA9B,EAAE,QAAQ,OAAW,EAAN,IAAI,cAAnB,YAAqB,CAAF;IACpB,MAAM,EAAE,QAAQ,EAAE,GAAG,8BAA8B,EAAE,CAAC;IACtD,OAAO,CACL,2CAAK,GAAG,EAAE,GAAG,IAAM,IAAI,IAAE,EAAE,EAAE,gBAAgB,QAAQ,UAAU,KAC5D,QAAQ,CACL,CACP,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ export interface VirtualFocusItemProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "id" | "tabIndex"> {
3
+ /**
4
+ * The function that is run when the element is focused
5
+ * (virtually, not actual focus, eg. set a border around an item)
6
+ */
7
+ onActive: () => void;
8
+ /**
9
+ * The function that is run when the focused element
10
+ * is to be selected (eg. do an actual search, change route... etc)
11
+ */
12
+ onSelect: () => void;
13
+ children: React.ReactNode;
14
+ }
15
+ /**
16
+ * Contains an item you want to be iterable via virtual focus.
17
+ */
18
+ export declare const VirtualFocusItem: React.ForwardRefExoticComponent<VirtualFocusItemProps & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,38 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { forwardRef } from "react";
13
+ import { Slot } from "../../../slot/Slot.js";
14
+ import { composeEventHandlers } from "../../composeEventHandlers.js";
15
+ import { useMergeRefs } from "../../hooks/index.js";
16
+ import { useVirtualFocusDescendant, useVirtualFocusInternalContext, } from "../Context.js";
17
+ /**
18
+ * Contains an item you want to be iterable via virtual focus.
19
+ */
20
+ export const VirtualFocusItem = forwardRef((_a, ref) => {
21
+ var { children, onActive, onSelect } = _a, rest = __rest(_a, ["children", "onActive", "onSelect"]);
22
+ const { virtualFocusIdx, setVirtualFocusIdx, uniqueId } = useVirtualFocusInternalContext();
23
+ const { register, index } = useVirtualFocusDescendant({
24
+ handleOnActive: () => {
25
+ setVirtualFocusIdx(index);
26
+ onActive();
27
+ },
28
+ handleOnSelect: onSelect,
29
+ });
30
+ const mergedRefs = useMergeRefs(ref, register);
31
+ return (React.createElement(Slot, Object.assign({ ref: mergedRefs }, rest, { id: `virtualfocus-${uniqueId}-${index}`, "data-aksel-virtualfocus": virtualFocusIdx === index, tabIndex: -1, onClick: composeEventHandlers(rest.onClick, () => {
32
+ onSelect();
33
+ }), onMouseMove: composeEventHandlers(rest.onMouseMove, () => {
34
+ setVirtualFocusIdx(index);
35
+ onActive();
36
+ }) }), children));
37
+ });
38
+ //# sourceMappingURL=VirtualFocusItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VirtualFocusItem.js","sourceRoot":"","sources":["../../../../src/util/virtualfocus/parts/VirtualFocusItem.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,YAAY,CAAC;AAiBpB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACxC,CAAC,EAAyC,EAAE,GAAG,EAAE,EAAE;QAAlD,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,OAAW,EAAN,IAAI,cAAvC,oCAAyC,CAAF;IACtC,MAAM,EAAE,eAAe,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GACrD,8BAA8B,EAAE,CAAC;IACnC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,yBAAyB,CAAC;QACpD,cAAc,EAAE,GAAG,EAAE;YACnB,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1B,QAAQ,EAAE,CAAC;QACb,CAAC;QACD,cAAc,EAAE,QAAQ;KACzB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC/C,OAAO,CACL,oBAAC,IAAI,kBACH,GAAG,EAAE,UAAU,IACX,IAAI,IACR,EAAE,EAAE,gBAAgB,QAAQ,IAAI,KAAK,EAAE,6BACd,eAAe,KAAK,KAAK,EAClD,QAAQ,EAAE,CAAC,CAAC,EACZ,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;YAC/C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,EACF,WAAW,EAAE,oBAAoB,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;YACvD,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC1B,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,KAED,QAAQ,CACJ,CACR,CAAC;AACJ,CAAC,CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "6.13.0",
3
+ "version": "6.14.0",
4
4
  "description": "React components from the Norwegian Labour and Welfare Administration.",
5
5
  "author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
6
6
  "license": "MIT",
@@ -594,8 +594,8 @@
594
594
  "dependencies": {
595
595
  "@floating-ui/react": "0.25.4",
596
596
  "@floating-ui/react-dom": "^2.0.9",
597
- "@navikt/aksel-icons": "^6.13.0",
598
- "@navikt/ds-tokens": "^6.13.0",
597
+ "@navikt/aksel-icons": "^6.14.0",
598
+ "@navikt/ds-tokens": "^6.14.0",
599
599
  "clsx": "^2.1.0",
600
600
  "date-fns": "^3.0.0",
601
601
  "react-day-picker": "8.10.0"
@@ -10,7 +10,10 @@ import { ComboboxProps } from "./types";
10
10
 
11
11
  export const Combobox = forwardRef<
12
12
  HTMLInputElement,
13
- Omit<ComboboxProps, "onChange" | "options" | "size" | "onClear" | "value">
13
+ Omit<
14
+ ComboboxProps,
15
+ "onChange" | "options" | "size" | "onClear" | "value" | "disabled"
16
+ >
14
17
  >((props, ref) => {
15
18
  const { className, hideLabel = false, description, label, ...rest } = props;
16
19
 
@@ -35,6 +35,7 @@ const ComboboxProvider = forwardRef<HTMLInputElement, ComboboxProps>(
35
35
  allowNewValues = false,
36
36
  children,
37
37
  defaultValue,
38
+ disabled,
38
39
  error,
39
40
  errorId,
40
41
  filteredOptions: externalFilteredOptions,
@@ -60,6 +61,8 @@ const ComboboxProvider = forwardRef<HTMLInputElement, ComboboxProps>(
60
61
  <InputContextProvider
61
62
  value={{
62
63
  defaultValue,
64
+ description: rest.description,
65
+ disabled,
63
66
  error,
64
67
  errorId,
65
68
  id,
@@ -4,11 +4,18 @@ const normalizeText = (text: string): string =>
4
4
  typeof text === "string" ? text.toLocaleLowerCase().trim() : "";
5
5
 
6
6
  const isPartOfText = (value: string, text: string) =>
7
- normalizeText(text).startsWith(normalizeText(value ?? ""));
7
+ normalizeText(text).includes(normalizeText(value ?? ""));
8
8
 
9
9
  const getMatchingValuesFromList = (value: string, list: ComboboxOption[]) =>
10
10
  list.filter((listItem) => isPartOfText(value, listItem.label));
11
11
 
12
+ const getFirstValueStartingWith = (text: string, list: ComboboxOption[]) => {
13
+ const normalizedText = normalizeText(text);
14
+ return list.find((listItem) =>
15
+ normalizeText(listItem.label).startsWith(normalizedText),
16
+ );
17
+ };
18
+
12
19
  const getFilteredOptionsId = (comboboxId: string) =>
13
20
  `${comboboxId}-filtered-options`;
14
21
 
@@ -37,4 +44,5 @@ export default {
37
44
  getIsLoadingId,
38
45
  getNoHitsId,
39
46
  getMaxSelectedOptionsId,
47
+ getFirstValueStartingWith,
40
48
  };
@@ -106,16 +106,19 @@ const FilteredOptionsProvider = ({
106
106
  }, [allowNewValues, customOptions, id, options, value]);
107
107
 
108
108
  useClientLayoutEffect(() => {
109
+ const autoCompleteCandidate =
110
+ filteredOptionsUtils.getFirstValueStartingWith(
111
+ searchTerm,
112
+ filteredOptions,
113
+ )?.label;
109
114
  if (
110
115
  shouldAutocomplete &&
111
- filteredOptionsUtils.normalizeText(searchTerm) !== "" &&
112
- (previousSearchTerm?.length || 0) < searchTerm.length &&
113
- filteredOptions.length > 0
116
+ autoCompleteCandidate &&
117
+ (previousSearchTerm?.length || 0) < searchTerm.length
114
118
  ) {
115
119
  setValue(
116
- `${searchTerm}${filteredOptions[0].label.substring(searchTerm.length)}`,
120
+ `${searchTerm}${autoCompleteCandidate.substring(searchTerm.length)}`,
117
121
  );
118
- setSearchTerm(searchTerm);
119
122
  }
120
123
  }, [
121
124
  filteredOptions,
@@ -1,11 +1,4 @@
1
- import React, {
2
- ChangeEvent,
3
- ChangeEventHandler,
4
- useCallback,
5
- useMemo,
6
- useRef,
7
- useState,
8
- } from "react";
1
+ import React, { useCallback, useMemo, useRef, useState } from "react";
9
2
  import { createContext } from "../../../util/create-context";
10
3
  import { useClientLayoutEffect } from "../../../util/hooks";
11
4
  import { FormFieldType, useFormField } from "../../useFormField";
@@ -13,12 +6,12 @@ import { ComboboxProps } from "../types";
13
6
 
14
7
  interface InputContextValue extends FormFieldType {
15
8
  clearInput: NonNullable<ComboboxProps["onClear"]>;
16
- error?: string;
9
+ error?: ComboboxProps["error"];
17
10
  focusInput: () => void;
18
11
  inputRef: React.RefObject<HTMLInputElement>;
19
12
  value: string;
20
13
  setValue: (text: string) => void;
21
- onChange: ChangeEventHandler<HTMLInputElement>;
14
+ onChange: (newValue: string) => void;
22
15
  searchTerm: string;
23
16
  setSearchTerm: React.Dispatch<React.SetStateAction<string>>;
24
17
  shouldAutocomplete?: boolean;
@@ -31,7 +24,24 @@ const [InputContextProvider, useInputContext] =
31
24
  errorMessage: "useInputContext must be used within an InputContextProvider",
32
25
  });
33
26
 
34
- const InputProvider = ({ children, value: props }) => {
27
+ interface Props {
28
+ children: React.ReactNode;
29
+ value: {
30
+ defaultValue: ComboboxProps["defaultValue"];
31
+ description: ComboboxProps["description"];
32
+ disabled: ComboboxProps["disabled"];
33
+ error: ComboboxProps["error"];
34
+ errorId: ComboboxProps["errorId"];
35
+ id: ComboboxProps["id"];
36
+ value: ComboboxProps["value"];
37
+ onChange: ComboboxProps["onChange"];
38
+ onClear: ComboboxProps["onClear"];
39
+ shouldAutocomplete: ComboboxProps["shouldAutocomplete"];
40
+ size: ComboboxProps["size"];
41
+ };
42
+ }
43
+
44
+ const InputProvider = ({ children, value: props }: Props) => {
35
45
  const {
36
46
  defaultValue = "",
37
47
  description,
@@ -68,30 +78,22 @@ const InputProvider = ({ children, value: props }) => {
68
78
  const [searchTerm, setSearchTerm] = useState(value);
69
79
 
70
80
  const onChange = useCallback(
71
- (event: ChangeEvent<HTMLInputElement>) => {
72
- const newValue = event.currentTarget.value;
81
+ (newValue: string) => {
73
82
  externalValue ?? setInternalValue(newValue);
74
- externalOnChange?.(event);
75
83
  setSearchTerm(newValue);
84
+ externalOnChange?.(newValue);
76
85
  },
77
86
  [externalValue, externalOnChange],
78
87
  );
79
88
 
80
- const setValue = useCallback(
81
- (text) => {
82
- setInternalValue(text);
83
- },
84
- [setInternalValue],
85
- );
86
-
87
89
  const clearInput = useCallback(
88
90
  (event: React.PointerEvent | React.KeyboardEvent | React.MouseEvent) => {
89
91
  onClear?.(event);
90
- externalOnChange?.(null, "");
91
- setValue("");
92
+ externalOnChange?.("");
93
+ setInternalValue("");
92
94
  setSearchTerm("");
93
95
  },
94
- [externalOnChange, onClear, setValue],
96
+ [externalOnChange, onClear, setInternalValue],
95
97
  );
96
98
 
97
99
  const focusInput = useCallback(() => {
@@ -111,7 +113,7 @@ const InputProvider = ({ children, value: props }) => {
111
113
  focusInput,
112
114
  inputRef,
113
115
  value,
114
- setValue,
116
+ setValue: setInternalValue,
115
117
  onChange,
116
118
  searchTerm,
117
119
  setSearchTerm,
@@ -1,18 +1,19 @@
1
1
  import cl from "clsx";
2
2
  import React, {
3
- ChangeEvent,
4
3
  InputHTMLAttributes,
5
4
  forwardRef,
6
5
  useCallback,
6
+ useRef,
7
7
  } from "react";
8
8
  import { omit } from "../../../util";
9
+ import { useMergeRefs } from "../../../util/hooks";
9
10
  import filteredOptionsUtil from "../FilteredOptions/filtered-options-util";
10
11
  import { useFilteredOptionsContext } from "../FilteredOptions/filteredOptionsContext";
11
12
  import { useSelectedOptionsContext } from "../SelectedOptions/selectedOptionsContext";
12
13
  import { useInputContext } from "./Input.context";
13
14
 
14
15
  interface InputProps
15
- extends Omit<InputHTMLAttributes<HTMLInputElement>, "value"> {
16
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "disabled"> {
16
17
  ref: React.Ref<HTMLInputElement>;
17
18
  inputClassName?: string;
18
19
  value?: string;
@@ -20,7 +21,17 @@ interface InputProps
20
21
 
21
22
  const Input = forwardRef<HTMLInputElement, InputProps>(
22
23
  ({ inputClassName, ...rest }, ref) => {
23
- const { clearInput, inputProps, onChange, size, value } = useInputContext();
24
+ const internalRef = useRef<HTMLInputElement>(null);
25
+ const mergedRefs = useMergeRefs(ref, internalRef);
26
+ const {
27
+ clearInput,
28
+ inputProps,
29
+ onChange,
30
+ size,
31
+ value,
32
+ searchTerm,
33
+ setValue,
34
+ } = useInputContext();
24
35
  const {
25
36
  selectedOptions,
26
37
  removeSelectedOption,
@@ -56,7 +67,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
56
67
  if (!isMultiSelect && !isTextInSelectedOptions(currentOption.label)) {
57
68
  toggleIsListOpen(false);
58
69
  }
59
- } else if (shouldAutocomplete && isTextInSelectedOptions(value)) {
70
+ } else if (isTextInSelectedOptions(value)) {
60
71
  event.preventDefault();
61
72
  // Trying to set the same value that is already set, so just clearing the input
62
73
  clearInput(event);
@@ -67,13 +78,13 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
67
78
  allowNewValues && isValueNew
68
79
  ? { label: value, value }
69
80
  : filteredOptions[0];
81
+
82
+ if (!selectedValue) {
83
+ return;
84
+ }
85
+
70
86
  toggleOption(selectedValue, event);
71
- if (
72
- !isMultiSelect &&
73
- !isTextInSelectedOptions(
74
- filteredOptions[0].label || selectedValue.label,
75
- )
76
- ) {
87
+ if (!isMultiSelect && !isTextInSelectedOptions(selectedValue.label)) {
77
88
  toggleIsListOpen(false);
78
89
  }
79
90
  }
@@ -96,10 +107,6 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
96
107
  const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {
97
108
  e.preventDefault();
98
109
  switch (e.key) {
99
- case "Escape":
100
- clearInput(e);
101
- toggleIsListOpen(false);
102
- break;
103
110
  case "Enter":
104
111
  case "Accept":
105
112
  onEnter(e);
@@ -118,7 +125,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
118
125
  };
119
126
 
120
127
  const handleKeyDown = useCallback(
121
- (e) => {
128
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
122
129
  setIsMouseLastUsedInputDevice(false);
123
130
  if (e.key === "Backspace") {
124
131
  if (value === "") {
@@ -132,17 +139,34 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
132
139
  if (activeDecendantId || value) {
133
140
  e.preventDefault();
134
141
  }
142
+ } else if (e.key === "Escape") {
143
+ if (isListOpen || value) {
144
+ e.preventDefault(); // Prevents closing an encasing Modal, as Combobox reacts on keyup.
145
+ clearInput(e);
146
+ toggleIsListOpen(false);
147
+ }
148
+ } else if (["ArrowLeft", "ArrowRight"].includes(e.key)) {
149
+ /**
150
+ * In case user has an active selection and 'completes' the selection with ArrowLeft or ArrowRight
151
+ * we need to make sure to update the filter.
152
+ */
153
+ if (value !== "" && value !== searchTerm) {
154
+ onChange(value);
155
+ }
135
156
  } else if (e.key === "ArrowDown") {
136
- // Check that cursor position is at the end of the input field,
137
- // so we don't interfere with text editing
138
- if (e.target.selectionStart === value?.length) {
139
- e.preventDefault();
140
- if (virtualFocus.activeElement === null || !isListOpen) {
141
- toggleIsListOpen(true);
142
- }
143
- virtualFocus.moveFocusDown();
157
+ // Reset the value to the search term to cancel autocomplete
158
+ // if the user moves focus down to the FilteredOptions
159
+ if (value !== searchTerm) {
160
+ setValue(searchTerm);
144
161
  }
162
+ if (virtualFocus.activeElement === null || !isListOpen) {
163
+ toggleIsListOpen(true);
164
+ }
165
+ virtualFocus.moveFocusDown();
145
166
  } else if (e.key === "ArrowUp") {
167
+ if (value !== "" && value !== searchTerm) {
168
+ onChange(value);
169
+ }
146
170
  // Check that the FilteredOptions list is open and has virtual focus.
147
171
  // Otherwise ignore keystrokes, so it doesn't interfere with text editing
148
172
  if (isListOpen && activeDecendantId) {
@@ -161,13 +185,17 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
161
185
  isListOpen,
162
186
  activeDecendantId,
163
187
  setIsMouseLastUsedInputDevice,
188
+ clearInput,
164
189
  toggleIsListOpen,
190
+ onChange,
165
191
  virtualFocus,
192
+ setValue,
193
+ searchTerm,
166
194
  ],
167
195
  );
168
196
 
169
197
  const onChangeHandler = useCallback(
170
- (event: ChangeEvent<HTMLInputElement>) => {
198
+ (event: React.ChangeEvent<HTMLInputElement>) => {
171
199
  const newValue = event.target.value;
172
200
  if (newValue && newValue !== "") {
173
201
  toggleIsListOpen(true);
@@ -175,7 +203,7 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
175
203
  toggleIsListOpen(false);
176
204
  }
177
205
  virtualFocus.moveFocusToTop();
178
- onChange(event);
206
+ onChange(newValue);
179
207
  },
180
208
  [filteredOptions.length, virtualFocus, onChange, toggleIsListOpen],
181
209
  );
@@ -184,10 +212,11 @@ const Input = forwardRef<HTMLInputElement, InputProps>(
184
212
  <input
185
213
  {...rest}
186
214
  {...omit(inputProps, ["aria-invalid"])}
187
- ref={ref}
215
+ ref={mergedRefs}
188
216
  value={value}
189
217
  onBlur={() => virtualFocus.moveFocusToTop()}
190
- onChange={onChangeHandler}
218
+ onClick={() => value !== searchTerm && onChange(value)}
219
+ onInput={onChangeHandler}
191
220
  type="text"
192
221
  role="combobox"
193
222
  onKeyUp={handleKeyUp}
@@ -24,6 +24,7 @@ export const InputController = forwardRef<
24
24
  | "size"
25
25
  | "onClear"
26
26
  | "value"
27
+ | "disabled"
27
28
  >
28
29
  >((props, ref) => {
29
30
  const {