@navikt/ds-react 8.10.5 → 8.11.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 (266) hide show
  1. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +0 -1
  2. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
  3. package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +6 -6
  4. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +6 -29
  5. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  6. package/cjs/data/stories/Data.test-data.d.ts +3 -6
  7. package/cjs/data/stories/Data.test-data.js +46 -59
  8. package/cjs/data/stories/Data.test-data.js.map +1 -1
  9. package/cjs/data/table/base-cell/DataTableBaseCell.d.ts +18 -18
  10. package/cjs/data/table/base-cell/DataTableBaseCell.js +4 -8
  11. package/cjs/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  12. package/cjs/data/table/column-header/DataTableColumnHeader.d.ts +19 -13
  13. package/cjs/data/table/column-header/DataTableColumnHeader.js +26 -28
  14. package/cjs/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  15. package/cjs/data/table/column-header/useTableColumnResize.d.ts +19 -29
  16. package/cjs/data/table/column-header/useTableColumnResize.js +30 -28
  17. package/cjs/data/table/column-header/useTableColumnResize.js.map +1 -1
  18. package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.d.ts +1 -1
  19. package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.js +2 -2
  20. package/cjs/data/table/details-panel-row/DataTableDetailsPanelRow.js.map +1 -1
  21. package/cjs/data/table/helpers/collectTableRowEntries.d.ts +2 -2
  22. package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -11
  23. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +45 -51
  24. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  25. package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +9 -8
  26. package/cjs/data/table/helpers/selection/getSingleSelectProps.js +23 -10
  27. package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  28. package/cjs/data/table/helpers/selection/selection.types.d.ts +24 -32
  29. package/cjs/data/table/helpers/selection/selection.utils.d.ts +21 -0
  30. package/cjs/data/table/helpers/selection/selection.utils.js +46 -0
  31. package/cjs/data/table/helpers/selection/selection.utils.js.map +1 -0
  32. package/cjs/data/table/hooks/useColumnOptions.d.ts +17 -6
  33. package/cjs/data/table/hooks/useColumnOptions.js +26 -8
  34. package/cjs/data/table/hooks/useColumnOptions.js.map +1 -1
  35. package/cjs/data/table/hooks/useTableDetailsPanel.d.ts +10 -14
  36. package/cjs/data/table/hooks/useTableDetailsPanel.js +6 -5
  37. package/cjs/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  38. package/cjs/data/table/hooks/useTableItems.d.ts +32 -19
  39. package/cjs/data/table/hooks/useTableItems.js +13 -15
  40. package/cjs/data/table/hooks/useTableItems.js.map +1 -1
  41. package/cjs/data/table/hooks/useTableKeyboardNav.d.ts +1 -6
  42. package/cjs/data/table/hooks/useTableKeyboardNav.js +1 -4
  43. package/cjs/data/table/hooks/useTableKeyboardNav.js.map +1 -1
  44. package/cjs/data/table/hooks/useTableSelection.d.ts +7 -6
  45. package/cjs/data/table/hooks/useTableSelection.js +52 -35
  46. package/cjs/data/table/hooks/useTableSelection.js.map +1 -1
  47. package/cjs/data/table/hooks/useTableSort.d.ts +15 -9
  48. package/cjs/data/table/hooks/useTableSort.js +9 -11
  49. package/cjs/data/table/hooks/useTableSort.js.map +1 -1
  50. package/cjs/data/table/index.d.ts +1 -1
  51. package/cjs/data/table/index.js +3 -23
  52. package/cjs/data/table/index.js.map +1 -1
  53. package/cjs/data/table/root/DataGridTable.types.d.ts +65 -0
  54. package/cjs/data/table/root/DataGridTable.types.js +3 -0
  55. package/cjs/data/table/root/DataGridTable.types.js.map +1 -0
  56. package/cjs/data/table/root/DataGridTableRoot.d.ts +104 -0
  57. package/cjs/data/table/root/DataGridTableRoot.js +237 -0
  58. package/cjs/data/table/root/DataGridTableRoot.js.map +1 -0
  59. package/cjs/data/table/root/DataTableRoot.context.d.ts +17 -7
  60. package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
  61. package/cjs/data/table/sub-row-toggle/DataTableSubRowToggle.js +4 -4
  62. package/cjs/data/table/sub-row-toggle/DataTableSubRowToggle.js.map +1 -1
  63. package/cjs/data/table/tbody/DataTableTbody.js +4 -2
  64. package/cjs/data/table/tbody/DataTableTbody.js.map +1 -1
  65. package/cjs/data/table/tr/DataTableTr.d.ts +7 -5
  66. package/cjs/data/table/tr/DataTableTr.js +69 -32
  67. package/cjs/data/table/tr/DataTableTr.js.map +1 -1
  68. package/cjs/data/token-filter/TokenFilter.d.ts +0 -6
  69. package/cjs/data/token-filter/TokenFilter.js +1 -1
  70. package/cjs/data-grid/index.d.ts +2 -0
  71. package/cjs/data-grid/index.js +9 -0
  72. package/cjs/data-grid/index.js.map +1 -0
  73. package/cjs/data-grid/root/DataGrid.types.d.ts +35 -0
  74. package/cjs/{data/table/root/DataTable.types.js → data-grid/root/DataGrid.types.js} +1 -1
  75. package/cjs/data-grid/root/DataGrid.types.js.map +1 -0
  76. package/cjs/data-grid/root/DataGridRoot.context.d.ts +16 -0
  77. package/cjs/data-grid/root/DataGridRoot.context.js +11 -0
  78. package/cjs/data-grid/root/DataGridRoot.context.js.map +1 -0
  79. package/cjs/data-grid/root/DataGridRoot.d.ts +89 -0
  80. package/cjs/data-grid/root/DataGridRoot.js +93 -0
  81. package/cjs/data-grid/root/DataGridRoot.js.map +1 -0
  82. package/cjs/preview.d.ts +1 -0
  83. package/cjs/preview.js +7 -0
  84. package/cjs/preview.js.map +1 -0
  85. package/cjs/table/ColumnHeader.js +2 -1
  86. package/cjs/table/ColumnHeader.js.map +1 -1
  87. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +0 -1
  88. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
  89. package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +6 -6
  90. package/esm/data/drag-and-drop/root/DragAndDropRoot.js +6 -29
  91. package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  92. package/esm/data/stories/Data.test-data.d.ts +3 -6
  93. package/esm/data/stories/Data.test-data.js +46 -59
  94. package/esm/data/stories/Data.test-data.js.map +1 -1
  95. package/esm/data/table/base-cell/DataTableBaseCell.d.ts +18 -18
  96. package/esm/data/table/base-cell/DataTableBaseCell.js +4 -8
  97. package/esm/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  98. package/esm/data/table/column-header/DataTableColumnHeader.d.ts +19 -13
  99. package/esm/data/table/column-header/DataTableColumnHeader.js +27 -29
  100. package/esm/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  101. package/esm/data/table/column-header/useTableColumnResize.d.ts +19 -29
  102. package/esm/data/table/column-header/useTableColumnResize.js +30 -28
  103. package/esm/data/table/column-header/useTableColumnResize.js.map +1 -1
  104. package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.d.ts +1 -1
  105. package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.js +2 -2
  106. package/esm/data/table/details-panel-row/DataTableDetailsPanelRow.js.map +1 -1
  107. package/esm/data/table/helpers/collectTableRowEntries.d.ts +2 -2
  108. package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +14 -11
  109. package/esm/data/table/helpers/selection/getMultipleSelectProps.js +45 -51
  110. package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  111. package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +9 -8
  112. package/esm/data/table/helpers/selection/getSingleSelectProps.js +23 -10
  113. package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  114. package/esm/data/table/helpers/selection/selection.types.d.ts +24 -32
  115. package/esm/data/table/helpers/selection/selection.utils.d.ts +21 -0
  116. package/esm/data/table/helpers/selection/selection.utils.js +43 -0
  117. package/esm/data/table/helpers/selection/selection.utils.js.map +1 -0
  118. package/esm/data/table/hooks/useColumnOptions.d.ts +17 -6
  119. package/esm/data/table/hooks/useColumnOptions.js +26 -8
  120. package/esm/data/table/hooks/useColumnOptions.js.map +1 -1
  121. package/esm/data/table/hooks/useTableDetailsPanel.d.ts +10 -14
  122. package/esm/data/table/hooks/useTableDetailsPanel.js +6 -5
  123. package/esm/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  124. package/esm/data/table/hooks/useTableItems.d.ts +32 -19
  125. package/esm/data/table/hooks/useTableItems.js +14 -13
  126. package/esm/data/table/hooks/useTableItems.js.map +1 -1
  127. package/esm/data/table/hooks/useTableKeyboardNav.d.ts +1 -6
  128. package/esm/data/table/hooks/useTableKeyboardNav.js +1 -4
  129. package/esm/data/table/hooks/useTableKeyboardNav.js.map +1 -1
  130. package/esm/data/table/hooks/useTableSelection.d.ts +7 -6
  131. package/esm/data/table/hooks/useTableSelection.js +52 -35
  132. package/esm/data/table/hooks/useTableSelection.js.map +1 -1
  133. package/esm/data/table/hooks/useTableSort.d.ts +15 -9
  134. package/esm/data/table/hooks/useTableSort.js +10 -12
  135. package/esm/data/table/hooks/useTableSort.js.map +1 -1
  136. package/esm/data/table/index.d.ts +1 -1
  137. package/esm/data/table/index.js +1 -21
  138. package/esm/data/table/index.js.map +1 -1
  139. package/esm/data/table/root/DataGridTable.types.d.ts +65 -0
  140. package/esm/data/table/root/DataGridTable.types.js +2 -0
  141. package/esm/data/table/root/DataGridTable.types.js.map +1 -0
  142. package/esm/data/table/root/DataGridTableRoot.d.ts +104 -0
  143. package/esm/data/table/root/DataGridTableRoot.js +202 -0
  144. package/esm/data/table/root/DataGridTableRoot.js.map +1 -0
  145. package/esm/data/table/root/DataTableRoot.context.d.ts +17 -7
  146. package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
  147. package/esm/data/table/sub-row-toggle/DataTableSubRowToggle.js +4 -4
  148. package/esm/data/table/sub-row-toggle/DataTableSubRowToggle.js.map +1 -1
  149. package/esm/data/table/tbody/DataTableTbody.js +4 -2
  150. package/esm/data/table/tbody/DataTableTbody.js.map +1 -1
  151. package/esm/data/table/tr/DataTableTr.d.ts +7 -5
  152. package/esm/data/table/tr/DataTableTr.js +68 -32
  153. package/esm/data/table/tr/DataTableTr.js.map +1 -1
  154. package/esm/data/token-filter/TokenFilter.d.ts +0 -6
  155. package/esm/data/token-filter/TokenFilter.js +1 -1
  156. package/esm/data-grid/index.d.ts +2 -0
  157. package/esm/data-grid/index.js +4 -0
  158. package/esm/data-grid/index.js.map +1 -0
  159. package/esm/data-grid/root/DataGrid.types.d.ts +35 -0
  160. package/esm/data-grid/root/DataGrid.types.js +2 -0
  161. package/esm/data-grid/root/DataGrid.types.js.map +1 -0
  162. package/esm/data-grid/root/DataGridRoot.context.d.ts +16 -0
  163. package/esm/data-grid/root/DataGridRoot.context.js +7 -0
  164. package/esm/data-grid/root/DataGridRoot.context.js.map +1 -0
  165. package/esm/data-grid/root/DataGridRoot.d.ts +89 -0
  166. package/esm/data-grid/root/DataGridRoot.js +57 -0
  167. package/esm/data-grid/root/DataGridRoot.js.map +1 -0
  168. package/esm/preview.d.ts +1 -0
  169. package/esm/preview.js +3 -0
  170. package/esm/preview.js.map +1 -0
  171. package/esm/table/ColumnHeader.js +2 -1
  172. package/esm/table/ColumnHeader.js.map +1 -1
  173. package/package.json +23 -3
  174. package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +0 -1
  175. package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +18 -52
  176. package/src/data/stories/Data.test-data.tsx +76 -65
  177. package/src/data/table/base-cell/DataTableBaseCell.tsx +36 -26
  178. package/src/data/table/column-header/DataTableColumnHeader.tsx +62 -62
  179. package/src/data/table/column-header/useTableColumnResize.ts +63 -79
  180. package/src/data/table/details-panel-row/DataTableDetailsPanelRow.tsx +3 -3
  181. package/src/data/table/helpers/collectTableRowEntries.ts +1 -2
  182. package/src/data/table/helpers/selection/getMultipleSelectProps.ts +69 -83
  183. package/src/data/table/helpers/selection/getSingleSelectProps.ts +35 -17
  184. package/src/data/table/helpers/selection/selection.types.ts +23 -33
  185. package/src/data/table/helpers/selection/selection.utils.test.ts +161 -0
  186. package/src/data/table/helpers/selection/selection.utils.ts +73 -0
  187. package/src/data/table/hooks/__tests__/useTableItems.test.ts +2 -1
  188. package/src/data/table/hooks/useColumnOptions.ts +49 -15
  189. package/src/data/table/hooks/useTableDetailsPanel.tsx +21 -28
  190. package/src/data/table/hooks/useTableItems.ts +60 -38
  191. package/src/data/table/hooks/useTableKeyboardNav.ts +1 -13
  192. package/src/data/table/hooks/useTableSelection.ts +80 -68
  193. package/src/data/table/hooks/useTableSort.ts +36 -23
  194. package/src/data/table/index.tsx +4 -21
  195. package/src/data/table/root/DataGridTable.types.ts +82 -0
  196. package/src/data/table/root/DataGridTableRoot.tsx +566 -0
  197. package/src/data/table/root/DataTableRoot.context.ts +24 -10
  198. package/src/data/table/sub-row-toggle/DataTableSubRowToggle.tsx +6 -5
  199. package/src/data/table/tbody/DataTableTbody.tsx +6 -2
  200. package/src/data/table/tr/DataTableTr.tsx +145 -47
  201. package/src/data/token-filter/TokenFilter.tsx +1 -1
  202. package/src/data-grid/index.ts +3 -0
  203. package/src/data-grid/root/DataGrid.types.ts +36 -0
  204. package/src/data-grid/root/DataGridRoot.context.ts +21 -0
  205. package/src/data-grid/root/DataGridRoot.tsx +152 -0
  206. package/src/preview.ts +2 -0
  207. package/src/table/ColumnHeader.tsx +3 -1
  208. package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.d.ts +0 -22
  209. package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js +0 -35
  210. package/cjs/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js.map +0 -1
  211. package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.d.ts +0 -27
  212. package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js +0 -86
  213. package/cjs/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js.map +0 -1
  214. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.d.ts +0 -5
  215. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js +0 -6
  216. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js.map +0 -1
  217. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.d.ts +0 -24
  218. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js +0 -108
  219. package/cjs/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js.map +0 -1
  220. package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.d.ts +0 -46
  221. package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.js +0 -112
  222. package/cjs/data/table/helpers/selection/SelectionSubtreeHelper.js.map +0 -1
  223. package/cjs/data/table/root/DataTable.types.d.ts +0 -63
  224. package/cjs/data/table/root/DataTable.types.js.map +0 -1
  225. package/cjs/data/table/root/DataTableRoot.d.ts +0 -141
  226. package/cjs/data/table/root/DataTableRoot.js +0 -229
  227. package/cjs/data/table/root/DataTableRoot.js.map +0 -1
  228. package/cjs/data/table/root/DataTableRoot.legacy.d.ts +0 -177
  229. package/cjs/data/table/root/DataTableRoot.legacy.js +0 -104
  230. package/cjs/data/table/root/DataTableRoot.legacy.js.map +0 -1
  231. package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.d.ts +0 -22
  232. package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js +0 -29
  233. package/esm/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.js.map +0 -1
  234. package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.d.ts +0 -27
  235. package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js +0 -50
  236. package/esm/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.js.map +0 -1
  237. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.d.ts +0 -5
  238. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js +0 -3
  239. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.js.map +0 -1
  240. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.d.ts +0 -24
  241. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js +0 -68
  242. package/esm/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.js.map +0 -1
  243. package/esm/data/table/helpers/selection/SelectionSubtreeHelper.d.ts +0 -46
  244. package/esm/data/table/helpers/selection/SelectionSubtreeHelper.js +0 -109
  245. package/esm/data/table/helpers/selection/SelectionSubtreeHelper.js.map +0 -1
  246. package/esm/data/table/root/DataTable.types.d.ts +0 -63
  247. package/esm/data/table/root/DataTable.types.js +0 -2
  248. package/esm/data/table/root/DataTable.types.js.map +0 -1
  249. package/esm/data/table/root/DataTableRoot.d.ts +0 -141
  250. package/esm/data/table/root/DataTableRoot.js +0 -193
  251. package/esm/data/table/root/DataTableRoot.js.map +0 -1
  252. package/esm/data/table/root/DataTableRoot.legacy.d.ts +0 -177
  253. package/esm/data/table/root/DataTableRoot.legacy.js +0 -59
  254. package/esm/data/table/root/DataTableRoot.legacy.js.map +0 -1
  255. package/src/data/drag-and-drop-legacy/drag-handler/DragAndDropDragHandlerLegacy.tsx +0 -104
  256. package/src/data/drag-and-drop-legacy/item/DragAndDropItemLegacy.tsx +0 -74
  257. package/src/data/drag-and-drop-legacy/root/DragAndDropLegacy.context.tsx +0 -11
  258. package/src/data/drag-and-drop-legacy/root/DragAndDropLegacyRoot.tsx +0 -94
  259. package/src/data/table/Readme.md +0 -11
  260. package/src/data/table/helpers/selection/SelectionSubtreeHelper.test.ts +0 -66
  261. package/src/data/table/helpers/selection/SelectionSubtreeHelper.ts +0 -162
  262. package/src/data/table/hooks/__tests__/useTableSelection.test.ts +0 -488
  263. package/src/data/table/root/DataTable.types.ts +0 -87
  264. package/src/data/table/root/DataTableRoot.legacy.tsx +0 -297
  265. package/src/data/table/root/DataTableRoot.tsx +0 -562
  266. package/src/data/table/root/agent-feature-gap.md +0 -96
@@ -1,488 +0,0 @@
1
- import { act, renderHook } from "@testing-library/react";
2
- import { describe, expect, test, vi } from "vitest";
3
- import type {
4
- MultipleSelection,
5
- SingleSelection,
6
- } from "../../helpers/selection/selection.types";
7
- import {
8
- type UseTableSelectionReturn,
9
- useTableSelection,
10
- } from "../useTableSelection";
11
-
12
- type Item = { id: string; name: string };
13
-
14
- const items: Item[] = [
15
- { id: "a", name: "Alpha" },
16
- { id: "b", name: "Beta" },
17
- { id: "c", name: "Charlie" },
18
- ];
19
-
20
- const visibleRowIds = items.map((item) => item.id);
21
- const childRowIdsById = new Map<string | number, (string | number)[]>([
22
- ["a", ["a1", "a2"]],
23
- ["a1", []],
24
- ["a2", ["a2a"]],
25
- ["a2a", []],
26
- ]);
27
-
28
- function asSingle(result: {
29
- current: UseTableSelectionReturn;
30
- }): SingleSelection {
31
- return result.current.selection as SingleSelection;
32
- }
33
-
34
- function asMultiple(result: {
35
- current: UseTableSelectionReturn;
36
- }): MultipleSelection {
37
- return result.current.selection as MultipleSelection;
38
- }
39
-
40
- describe("useTableSelection", () => {
41
- describe('selectionMode="none"', () => {
42
- test("returns empty selectedKeys and no prop getters", () => {
43
- const { result } = renderHook(() =>
44
- useTableSelection({
45
- selection: { selectionMode: "none" },
46
- visibleRowIds,
47
- }),
48
- );
49
-
50
- expect(result.current.selection.selectionMode).toBe("none");
51
- expect(result.current.selection.selectedKeys).toEqual([]);
52
- });
53
- });
54
-
55
- describe('selectionMode="single"', () => {
56
- test("returns getRowRadioProps", () => {
57
- const { result } = renderHook(() =>
58
- useTableSelection({
59
- selection: { selectionMode: "single" },
60
- visibleRowIds,
61
- }),
62
- );
63
-
64
- expect(result.current.selection.selectionMode).toBe("single");
65
- expect(asSingle(result).getRowRadioProps).toBeDefined();
66
- });
67
-
68
- test("selecting a row via radio onChange", () => {
69
- const onChange = vi.fn();
70
- const { result } = renderHook(() =>
71
- useTableSelection({
72
- selection: { selectionMode: "single", onSelectionChange: onChange },
73
- visibleRowIds,
74
- }),
75
- );
76
-
77
- const radioProps = asSingle(result).getRowRadioProps("a");
78
- expect(radioProps.checked).toBe(false);
79
-
80
- act(() => {
81
- radioProps.onChange?.({} as React.ChangeEvent<HTMLInputElement>);
82
- });
83
-
84
- expect(asSingle(result).selectedKeys).toEqual(["a"]);
85
- });
86
-
87
- test("toggling the same row keeps it selected", () => {
88
- const { result } = renderHook(() =>
89
- useTableSelection({
90
- selection: { selectionMode: "single", defaultSelectedKeys: ["a"] },
91
- visibleRowIds,
92
- }),
93
- );
94
-
95
- act(() => {
96
- asSingle(result)
97
- .getRowRadioProps("a")
98
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
99
- });
100
-
101
- expect(asSingle(result).selectedKeys).toEqual(["a"]);
102
- });
103
-
104
- test("selecting a new row replaces the previous", () => {
105
- const { result } = renderHook(() =>
106
- useTableSelection({
107
- selection: { selectionMode: "single", defaultSelectedKeys: ["a"] },
108
- visibleRowIds,
109
- }),
110
- );
111
-
112
- act(() => {
113
- asSingle(result)
114
- .getRowRadioProps("b")
115
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
116
- });
117
-
118
- expect(asSingle(result).selectedKeys).toEqual(["b"]);
119
- });
120
-
121
- test("disabled rows have disabled prop", () => {
122
- const { result } = renderHook(() =>
123
- useTableSelection({
124
- selection: { selectionMode: "single", disabledSelectionKeys: ["b"] },
125
- visibleRowIds,
126
- }),
127
- );
128
-
129
- expect(asSingle(result).getRowRadioProps("a").disabled).toBe(false);
130
- expect(asSingle(result).getRowRadioProps("b").disabled).toBe(true);
131
- });
132
-
133
- test("controlled selectedKeys", () => {
134
- const { result, rerender } = renderHook(
135
- ({ selectedKeys }) =>
136
- useTableSelection({
137
- selection: { selectionMode: "single", selectedKeys },
138
- visibleRowIds,
139
- }),
140
- { initialProps: { selectedKeys: ["a"] as (string | number)[] } },
141
- );
142
-
143
- expect(asSingle(result).selectedKeys).toEqual(["a"]);
144
-
145
- rerender({ selectedKeys: ["b"] });
146
- expect(asSingle(result).selectedKeys).toEqual(["b"]);
147
- });
148
- });
149
-
150
- describe('selectionMode="multiple"', () => {
151
- test("returns getTheadCheckboxProps and getRowCheckboxProps", () => {
152
- const { result } = renderHook(() =>
153
- useTableSelection({
154
- selection: { selectionMode: "multiple" },
155
- visibleRowIds,
156
- }),
157
- );
158
-
159
- expect(result.current.selection.selectionMode).toBe("multiple");
160
- expect(asMultiple(result).getTheadCheckboxProps).toBeDefined();
161
- expect(asMultiple(result).getRowCheckboxProps).toBeDefined();
162
- });
163
-
164
- test("selecting individual rows", () => {
165
- const { result } = renderHook(() =>
166
- useTableSelection({
167
- selection: { selectionMode: "multiple" },
168
- visibleRowIds,
169
- }),
170
- );
171
-
172
- act(() => {
173
- asMultiple(result)
174
- .getRowCheckboxProps("a")
175
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
176
- });
177
-
178
- expect(asMultiple(result).selectedKeys).toEqual(["a"]);
179
-
180
- act(() => {
181
- asMultiple(result)
182
- .getRowCheckboxProps("c")
183
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
184
- });
185
-
186
- expect(asMultiple(result).selectedKeys).toEqual(["a", "c"]);
187
- });
188
-
189
- test("deselecting a row", () => {
190
- const { result } = renderHook(() =>
191
- useTableSelection({
192
- selection: {
193
- selectionMode: "multiple",
194
- defaultSelectedKeys: ["a", "b"],
195
- },
196
- visibleRowIds,
197
- }),
198
- );
199
-
200
- act(() => {
201
- asMultiple(result)
202
- .getRowCheckboxProps("a")
203
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
204
- });
205
-
206
- expect(asMultiple(result).selectedKeys).toEqual(["b"]);
207
- });
208
-
209
- test("select all via thead checkbox", () => {
210
- const { result } = renderHook(() =>
211
- useTableSelection({
212
- selection: { selectionMode: "multiple" },
213
- visibleRowIds,
214
- }),
215
- );
216
-
217
- act(() => {
218
- asMultiple(result)
219
- .getTheadCheckboxProps()
220
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
221
- });
222
-
223
- expect(asMultiple(result).selectedKeys).toEqual(["a", "b", "c"]);
224
- });
225
-
226
- test("select all via thead includes hidden descendants for visible parents", () => {
227
- const { result } = renderHook(() =>
228
- useTableSelection({
229
- selection: { selectionMode: "multiple" },
230
- visibleRowIds: ["a"],
231
- childRowIdsById,
232
- }),
233
- );
234
-
235
- act(() => {
236
- asMultiple(result)
237
- .getTheadCheckboxProps()
238
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
239
- });
240
-
241
- expect(asMultiple(result).selectedKeys).toEqual(["a", "a1", "a2", "a2a"]);
242
- });
243
-
244
- test("deselect all when all are selected", () => {
245
- const { result } = renderHook(() =>
246
- useTableSelection({
247
- selection: {
248
- selectionMode: "multiple",
249
- defaultSelectedKeys: ["a", "b", "c"],
250
- },
251
- visibleRowIds,
252
- }),
253
- );
254
-
255
- act(() => {
256
- asMultiple(result)
257
- .getTheadCheckboxProps()
258
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
259
- });
260
-
261
- expect(asMultiple(result).selectedKeys).toEqual([]);
262
- });
263
-
264
- test("deselect all clears hidden descendants for visible parents but preserves unrelated keys", () => {
265
- const { result } = renderHook(() =>
266
- useTableSelection({
267
- selection: {
268
- selectionMode: "multiple",
269
- defaultSelectedKeys: ["a", "a1", "a2", "a2a", "external"],
270
- },
271
- visibleRowIds: ["a"],
272
- childRowIdsById,
273
- }),
274
- );
275
-
276
- act(() => {
277
- asMultiple(result)
278
- .getTheadCheckboxProps()
279
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
280
- });
281
-
282
- expect(asMultiple(result).selectedKeys).toEqual(["external"]);
283
- });
284
-
285
- test("select all skips disabled keys", () => {
286
- const { result } = renderHook(() =>
287
- useTableSelection({
288
- selection: {
289
- selectionMode: "multiple",
290
- disabledSelectionKeys: ["b"],
291
- },
292
- visibleRowIds,
293
- }),
294
- );
295
-
296
- act(() => {
297
- asMultiple(result)
298
- .getTheadCheckboxProps()
299
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
300
- });
301
-
302
- expect(asMultiple(result).selectedKeys).toEqual(["a", "c"]);
303
- });
304
-
305
- test("deselect all preserves disabled-but-selected rows", () => {
306
- const { result } = renderHook(() =>
307
- useTableSelection({
308
- selection: {
309
- selectionMode: "multiple",
310
- defaultSelectedKeys: ["a", "b", "c"],
311
- disabledSelectionKeys: ["b"],
312
- },
313
- visibleRowIds,
314
- }),
315
- );
316
-
317
- act(() => {
318
- asMultiple(result)
319
- .getTheadCheckboxProps()
320
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
321
- });
322
-
323
- expect(asMultiple(result).selectedKeys).toEqual(["b"]);
324
- });
325
-
326
- test("thead checkbox shows indeterminate when partially selected", () => {
327
- const { result } = renderHook(() =>
328
- useTableSelection({
329
- selection: { selectionMode: "multiple", defaultSelectedKeys: ["a"] },
330
- visibleRowIds,
331
- }),
332
- );
333
-
334
- const theadProps = asMultiple(result).getTheadCheckboxProps();
335
- expect(theadProps.indeterminate).toBe(true);
336
- expect(theadProps.checked).toBe(false);
337
- });
338
-
339
- test("thead checkbox shows checked when all selected", () => {
340
- const { result } = renderHook(() =>
341
- useTableSelection({
342
- selection: {
343
- selectionMode: "multiple",
344
- defaultSelectedKeys: ["a", "b", "c"],
345
- },
346
- visibleRowIds,
347
- }),
348
- );
349
-
350
- const theadProps = asMultiple(result).getTheadCheckboxProps();
351
- expect(theadProps.indeterminate).toBe(false);
352
- expect(theadProps.checked).toBe(true);
353
- });
354
-
355
- test("thead checkbox shows checked when all selectable rows are selected", () => {
356
- const { result } = renderHook(() =>
357
- useTableSelection({
358
- selection: {
359
- selectionMode: "multiple",
360
- defaultSelectedKeys: ["a", "c"],
361
- disabledSelectionKeys: ["b"],
362
- },
363
- visibleRowIds,
364
- }),
365
- );
366
-
367
- const theadProps = asMultiple(result).getTheadCheckboxProps();
368
- expect(theadProps.indeterminate).toBe(false);
369
- expect(theadProps.checked).toBe(true);
370
- });
371
-
372
- test("deselecting one row when all rows are selected", () => {
373
- const { result } = renderHook(() =>
374
- useTableSelection({
375
- selection: {
376
- selectionMode: "multiple",
377
- defaultSelectedKeys: ["a", "b", "c"],
378
- },
379
- visibleRowIds,
380
- }),
381
- );
382
-
383
- act(() => {
384
- asMultiple(result)
385
- .getRowCheckboxProps("b")
386
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
387
- });
388
-
389
- expect(asMultiple(result).selectedKeys).toEqual(["a", "c"]);
390
- });
391
-
392
- test("disabled rows have disabled prop", () => {
393
- const { result } = renderHook(() =>
394
- useTableSelection({
395
- selection: {
396
- selectionMode: "multiple",
397
- disabledSelectionKeys: ["b"],
398
- },
399
- visibleRowIds,
400
- }),
401
- );
402
-
403
- expect(asMultiple(result).getRowCheckboxProps("a").disabled).toBe(false);
404
- expect(asMultiple(result).getRowCheckboxProps("b").disabled).toBe(true);
405
- });
406
-
407
- test("thead checkbox disabled when all rows disabled", () => {
408
- const { result } = renderHook(() =>
409
- useTableSelection({
410
- selection: {
411
- selectionMode: "multiple",
412
- disabledSelectionKeys: ["a", "b", "c"],
413
- },
414
- visibleRowIds,
415
- }),
416
- );
417
-
418
- expect(asMultiple(result).getTheadCheckboxProps().disabled).toBe(true);
419
- });
420
-
421
- test("parent rows show indeterminate when visible descendants are partially selected", () => {
422
- const { result } = renderHook(() =>
423
- useTableSelection({
424
- selection: { selectionMode: "multiple", defaultSelectedKeys: ["a1"] },
425
- visibleRowIds: ["a", "a1", "a2"],
426
- childRowIdsById,
427
- }),
428
- );
429
-
430
- const parentProps = asMultiple(result).getRowCheckboxProps("a");
431
-
432
- expect(parentProps.checked).toBe(false);
433
- expect(parentProps.indeterminate).toBe(true);
434
- });
435
-
436
- test("toggling a parent row selects and deselects its descendants", () => {
437
- const { result } = renderHook(() =>
438
- useTableSelection({
439
- selection: { selectionMode: "multiple" },
440
- visibleRowIds: ["a", "a1", "a2"],
441
- childRowIdsById,
442
- }),
443
- );
444
-
445
- act(() => {
446
- asMultiple(result)
447
- .getRowCheckboxProps("a")
448
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
449
- });
450
-
451
- expect(asMultiple(result).selectedKeys).toEqual(["a", "a1", "a2", "a2a"]);
452
-
453
- act(() => {
454
- asMultiple(result)
455
- .getRowCheckboxProps("a")
456
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
457
- });
458
-
459
- expect(asMultiple(result).selectedKeys).toEqual([]);
460
- });
461
-
462
- test("toggling a collapsed parent selects and deselects hidden descendants", () => {
463
- const { result } = renderHook(() =>
464
- useTableSelection({
465
- selection: { selectionMode: "multiple" },
466
- visibleRowIds: ["a"],
467
- childRowIdsById,
468
- }),
469
- );
470
-
471
- act(() => {
472
- asMultiple(result)
473
- .getRowCheckboxProps("a")
474
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
475
- });
476
-
477
- expect(asMultiple(result).selectedKeys).toEqual(["a", "a1", "a2", "a2a"]);
478
-
479
- act(() => {
480
- asMultiple(result)
481
- .getRowCheckboxProps("a")
482
- .onChange?.({} as React.ChangeEvent<HTMLInputElement>);
483
- });
484
-
485
- expect(asMultiple(result).selectedKeys).toEqual([]);
486
- });
487
- });
488
- });
@@ -1,87 +0,0 @@
1
- import type { ResizeProps } from "../column-header/useTableColumnResize";
2
-
3
- type SortDirection = "asc" | "desc" | "none";
4
-
5
- /**
6
- * TODO:
7
- * - Consider "accessorKey" or similar to allow simple column definitions without a cell function.
8
- * - Add "align" property for better control over text alignment in cells.
9
- */
10
- type ColumnDefinition<T, DetailsT = Record<string, any>> = Pick<
11
- ResizeProps,
12
- | "resizable"
13
- | "width"
14
- | "defaultWidth"
15
- | "autoWidth"
16
- | "minWidth"
17
- | "maxWidth"
18
- | "onWidthChange"
19
- > & {
20
- id: string;
21
- /**
22
- * Text alignment for cells in this column.
23
- *
24
- *
25
- * @default "left"
26
- */
27
- align?: "left" | "right" | "center";
28
- /**
29
- * Assigned to the cell's `th` element instead of `td` if true.
30
- *
31
- * Should be used for cells that act as row headers. Each row should have one rowheader, and only have one cell with `isRowHeader: true`,
32
- */
33
- isRowHeader?: boolean;
34
- /**
35
- * Renders table header-cell
36
- */
37
- header?: React.ReactNode;
38
- /**
39
- * Renders table-cell
40
- */
41
- cell: (item: T) => React.ReactNode;
42
- /**
43
- * Label of header. Renders if header is not provided.
44
- */
45
- label: string;
46
- /**
47
- * Makes the column sortable. Renders the header as a sort button.
48
- * Use `sort` and `onSortChange` on the root component to control sort state.
49
- */
50
- sortable?: boolean;
51
- /**
52
- * Additional metadata that can be used for filtering or other purposes. Not used by the table itself.
53
- */
54
- details?: DetailsT;
55
- };
56
-
57
- type ColumnDefinitions<T, DetailsT = Record<string, any>> = ColumnDefinition<
58
- T,
59
- DetailsT
60
- >[];
61
-
62
- /**
63
- * A single sort entry representing a column's current sort state.
64
- * Absent from the `sort` array means the column is unsorted.
65
- */
66
- type SortEntry = {
67
- columnId: string;
68
- direction: "asc" | "desc";
69
- };
70
-
71
- /**
72
- * The column that changed in a sort operation, passed as the second argument
73
- * to `onSortChange`. Useful for triggering targeted server-side sort requests.
74
- */
75
- type SortChangeDetail = {
76
- columnId: string;
77
- /** The new direction for this column. `"none"` means the column was removed from the sort. */
78
- direction: "asc" | "desc" | "none";
79
- };
80
-
81
- export type {
82
- ColumnDefinition,
83
- ColumnDefinitions,
84
- SortDirection,
85
- SortEntry,
86
- SortChangeDetail,
87
- };