@navikt/ds-react 8.10.6 → 8.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/cjs/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +5 -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 +1 -1
  4. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +50 -20
  5. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  6. package/cjs/data/stories/Data.test-data.d.ts +2 -2
  7. package/cjs/data/stories/Data.test-data.js +37 -42
  8. package/cjs/data/stories/Data.test-data.js.map +1 -1
  9. package/cjs/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
  10. package/cjs/data/table/base-cell/DataTableBaseCell.js +2 -2
  11. package/cjs/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  12. package/cjs/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
  13. package/cjs/data/table/column-header/DataTableColumnHeader.js +8 -5
  14. package/cjs/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  15. package/cjs/data/table/column-header/useTableColumnResize.d.ts +2 -4
  16. package/cjs/data/table/column-header/useTableColumnResize.js +15 -11
  17. package/cjs/data/table/column-header/useTableColumnResize.js.map +1 -1
  18. package/cjs/data/table/helpers/collectTableRowEntries.d.ts +1 -1
  19. package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
  20. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
  21. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  22. package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
  23. package/cjs/data/table/helpers/selection/getSingleSelectProps.js +1 -1
  24. package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  25. package/cjs/data/table/helpers/selection/selection.types.d.ts +19 -27
  26. package/cjs/data/table/helpers/selection/selection.utils.d.ts +1 -1
  27. package/cjs/data/table/helpers/table-focus.js +1 -1
  28. package/cjs/data/table/helpers/table-focus.js.map +1 -1
  29. package/cjs/data/table/hooks/useColumnOptions.d.ts +8 -5
  30. package/cjs/data/table/hooks/useColumnOptions.js +25 -10
  31. package/cjs/data/table/hooks/useColumnOptions.js.map +1 -1
  32. package/cjs/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
  33. package/cjs/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  34. package/cjs/data/table/hooks/useTableItems.d.ts +10 -11
  35. package/cjs/data/table/hooks/useTableItems.js +11 -3
  36. package/cjs/data/table/hooks/useTableItems.js.map +1 -1
  37. package/cjs/data/table/hooks/useTableSelection.d.ts +2 -1
  38. package/cjs/data/table/hooks/useTableSelection.js +46 -29
  39. package/cjs/data/table/hooks/useTableSelection.js.map +1 -1
  40. package/cjs/data/table/hooks/useTableSort.d.ts +13 -7
  41. package/cjs/data/table/hooks/useTableSort.js +8 -9
  42. package/cjs/data/table/hooks/useTableSort.js.map +1 -1
  43. package/cjs/data/table/index.d.ts +1 -1
  44. package/cjs/data/table/index.js +3 -23
  45. package/cjs/data/table/index.js.map +1 -1
  46. package/cjs/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
  47. package/cjs/data/table/root/DataGridTable.types.js +3 -0
  48. package/cjs/data/table/root/DataGridTable.types.js.map +1 -0
  49. package/cjs/data/table/root/DataGridTableRoot.d.ts +104 -0
  50. package/cjs/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +59 -38
  51. package/cjs/data/table/root/DataGridTableRoot.js.map +1 -0
  52. package/cjs/data/table/root/DataTableRoot.context.d.ts +6 -2
  53. package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
  54. package/cjs/data/table/tbody/DataTableTbody.js +3 -3
  55. package/cjs/data/table/tbody/DataTableTbody.js.map +1 -1
  56. package/cjs/data/table/tr/DataTableTr.d.ts +3 -3
  57. package/cjs/data/table/tr/DataTableTr.js +45 -23
  58. package/cjs/data/table/tr/DataTableTr.js.map +1 -1
  59. package/cjs/data/token-filter/TokenFilter.d.ts +0 -6
  60. package/cjs/data/token-filter/TokenFilter.js +1 -1
  61. package/cjs/data-grid/index.d.ts +2 -0
  62. package/cjs/data-grid/index.js +9 -0
  63. package/cjs/data-grid/index.js.map +1 -0
  64. package/cjs/data-grid/root/DataGrid.types.d.ts +48 -0
  65. package/cjs/{data/table/root/DataTable.types.js → data-grid/root/DataGrid.types.js} +1 -1
  66. package/cjs/data-grid/root/DataGrid.types.js.map +1 -0
  67. package/cjs/data-grid/root/DataGridRoot.context.d.ts +16 -0
  68. package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
  69. package/cjs/data-grid/root/DataGridRoot.context.js.map +1 -0
  70. package/cjs/data-grid/root/DataGridRoot.d.ts +89 -0
  71. package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.js +35 -8
  72. package/cjs/data-grid/root/DataGridRoot.js.map +1 -0
  73. package/cjs/preview.d.ts +1 -0
  74. package/cjs/{data/data-grid/index.js → preview.js} +3 -3
  75. package/cjs/preview.js.map +1 -0
  76. package/cjs/primitives/bleed/Bleed.d.ts +0 -2
  77. package/cjs/primitives/bleed/Bleed.js.map +1 -1
  78. package/cjs/table/ColumnHeader.js.map +1 -1
  79. package/cjs/tabs/Tabs.context.d.ts +1 -1
  80. package/cjs/tabs/useTabs.d.ts +1 -1
  81. package/cjs/toggle-group/ToggleGroup.context.d.ts +1 -1
  82. package/cjs/toggle-group/useToggleGroup.d.ts +1 -1
  83. package/cjs/utils/components/dismissablelayer/DismissableLayer.js +1 -0
  84. package/cjs/utils/components/dismissablelayer/DismissableLayer.js.map +1 -1
  85. package/cjs/utils/components/dismissablelayer/util/useFocusOutside.d.ts +1 -0
  86. package/cjs/utils/components/dismissablelayer/util/useFocusOutside.js +11 -1
  87. package/cjs/utils/components/dismissablelayer/util/useFocusOutside.js.map +1 -1
  88. package/cjs/utils/hooks/useControllableState.d.ts +1 -1
  89. package/cjs/utils/hooks/useControllableState.js.map +1 -1
  90. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js +5 -1
  91. package/esm/data/drag-and-drop/drag-handler/DragAndDropDragHandler.js.map +1 -1
  92. package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
  93. package/esm/data/drag-and-drop/root/DragAndDropRoot.js +51 -21
  94. package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  95. package/esm/data/stories/Data.test-data.d.ts +2 -2
  96. package/esm/data/stories/Data.test-data.js +37 -42
  97. package/esm/data/stories/Data.test-data.js.map +1 -1
  98. package/esm/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
  99. package/esm/data/table/base-cell/DataTableBaseCell.js +2 -2
  100. package/esm/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  101. package/esm/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
  102. package/esm/data/table/column-header/DataTableColumnHeader.js +8 -5
  103. package/esm/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  104. package/esm/data/table/column-header/useTableColumnResize.d.ts +2 -4
  105. package/esm/data/table/column-header/useTableColumnResize.js +15 -11
  106. package/esm/data/table/column-header/useTableColumnResize.js.map +1 -1
  107. package/esm/data/table/helpers/collectTableRowEntries.d.ts +1 -1
  108. package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
  109. package/esm/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
  110. package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  111. package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
  112. package/esm/data/table/helpers/selection/getSingleSelectProps.js +1 -1
  113. package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  114. package/esm/data/table/helpers/selection/selection.types.d.ts +19 -27
  115. package/esm/data/table/helpers/selection/selection.utils.d.ts +1 -1
  116. package/esm/data/table/helpers/table-focus.js +1 -1
  117. package/esm/data/table/helpers/table-focus.js.map +1 -1
  118. package/esm/data/table/hooks/useColumnOptions.d.ts +8 -5
  119. package/esm/data/table/hooks/useColumnOptions.js +25 -10
  120. package/esm/data/table/hooks/useColumnOptions.js.map +1 -1
  121. package/esm/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
  122. package/esm/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  123. package/esm/data/table/hooks/useTableItems.d.ts +10 -11
  124. package/esm/data/table/hooks/useTableItems.js +11 -3
  125. package/esm/data/table/hooks/useTableItems.js.map +1 -1
  126. package/esm/data/table/hooks/useTableSelection.d.ts +2 -1
  127. package/esm/data/table/hooks/useTableSelection.js +46 -29
  128. package/esm/data/table/hooks/useTableSelection.js.map +1 -1
  129. package/esm/data/table/hooks/useTableSort.d.ts +13 -7
  130. package/esm/data/table/hooks/useTableSort.js +9 -10
  131. package/esm/data/table/hooks/useTableSort.js.map +1 -1
  132. package/esm/data/table/index.d.ts +1 -1
  133. package/esm/data/table/index.js +1 -21
  134. package/esm/data/table/index.js.map +1 -1
  135. package/esm/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
  136. package/esm/data/table/root/DataGridTable.types.js +2 -0
  137. package/esm/data/table/root/DataGridTable.types.js.map +1 -0
  138. package/esm/data/table/root/DataGridTableRoot.d.ts +104 -0
  139. package/esm/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +61 -39
  140. package/esm/data/table/root/DataGridTableRoot.js.map +1 -0
  141. package/esm/data/table/root/DataTableRoot.context.d.ts +6 -2
  142. package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
  143. package/esm/data/table/tbody/DataTableTbody.js +3 -3
  144. package/esm/data/table/tbody/DataTableTbody.js.map +1 -1
  145. package/esm/data/table/tr/DataTableTr.d.ts +3 -3
  146. package/esm/data/table/tr/DataTableTr.js +45 -23
  147. package/esm/data/table/tr/DataTableTr.js.map +1 -1
  148. package/esm/data/token-filter/TokenFilter.d.ts +0 -6
  149. package/esm/data/token-filter/TokenFilter.js +1 -1
  150. package/esm/data-grid/index.d.ts +2 -0
  151. package/esm/data-grid/index.js +4 -0
  152. package/esm/data-grid/index.js.map +1 -0
  153. package/esm/data-grid/root/DataGrid.types.d.ts +48 -0
  154. package/esm/data-grid/root/DataGrid.types.js +2 -0
  155. package/esm/data-grid/root/DataGrid.types.js.map +1 -0
  156. package/esm/data-grid/root/DataGridRoot.context.d.ts +16 -0
  157. package/esm/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
  158. package/esm/data-grid/root/DataGridRoot.context.js.map +1 -0
  159. package/esm/data-grid/root/DataGridRoot.d.ts +89 -0
  160. package/esm/data-grid/root/DataGridRoot.js +59 -0
  161. package/esm/data-grid/root/DataGridRoot.js.map +1 -0
  162. package/esm/preview.d.ts +1 -0
  163. package/esm/preview.js +3 -0
  164. package/esm/preview.js.map +1 -0
  165. package/esm/primitives/bleed/Bleed.d.ts +0 -2
  166. package/esm/primitives/bleed/Bleed.js.map +1 -1
  167. package/esm/table/ColumnHeader.js.map +1 -1
  168. package/esm/tabs/Tabs.context.d.ts +1 -1
  169. package/esm/tabs/useTabs.d.ts +1 -1
  170. package/esm/toggle-group/ToggleGroup.context.d.ts +1 -1
  171. package/esm/toggle-group/useToggleGroup.d.ts +1 -1
  172. package/esm/utils/components/dismissablelayer/DismissableLayer.js +1 -0
  173. package/esm/utils/components/dismissablelayer/DismissableLayer.js.map +1 -1
  174. package/esm/utils/components/dismissablelayer/util/useFocusOutside.d.ts +1 -0
  175. package/esm/utils/components/dismissablelayer/util/useFocusOutside.js +12 -2
  176. package/esm/utils/components/dismissablelayer/util/useFocusOutside.js.map +1 -1
  177. package/esm/utils/hooks/useControllableState.d.ts +1 -1
  178. package/esm/utils/hooks/useControllableState.js.map +1 -1
  179. package/package.json +25 -5
  180. package/src/data/drag-and-drop/drag-handler/DragAndDropDragHandler.tsx +5 -1
  181. package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +55 -25
  182. package/src/data/stories/Data.test-data.tsx +53 -51
  183. package/src/data/table/base-cell/DataTableBaseCell.tsx +6 -6
  184. package/src/data/table/column-header/DataTableColumnHeader.tsx +17 -20
  185. package/src/data/table/column-header/useTableColumnResize.ts +19 -16
  186. package/src/data/table/helpers/collectTableRowEntries.ts +1 -1
  187. package/src/data/table/helpers/selection/getMultipleSelectProps.ts +11 -5
  188. package/src/data/table/helpers/selection/getSingleSelectProps.ts +4 -4
  189. package/src/data/table/helpers/selection/selection.types.ts +18 -29
  190. package/src/data/table/helpers/selection/selection.utils.test.ts +1 -1
  191. package/src/data/table/helpers/selection/selection.utils.ts +1 -1
  192. package/src/data/table/helpers/table-focus.ts +1 -1
  193. package/src/data/table/hooks/__tests__/useTableItems.test.ts +1 -1
  194. package/src/data/table/hooks/useColumnOptions.ts +50 -15
  195. package/src/data/table/hooks/useTableDetailsPanel.tsx +14 -18
  196. package/src/data/table/hooks/useTableItems.ts +37 -23
  197. package/src/data/table/hooks/useTableSelection.ts +62 -45
  198. package/src/data/table/hooks/useTableSort.ts +29 -17
  199. package/src/data/table/index.tsx +4 -21
  200. package/src/data/table/root/{DataTable.types.ts → DataGridTable.types.ts} +17 -30
  201. package/src/data/table/root/{DataTableRoot.tsx → DataGridTableRoot.tsx} +198 -144
  202. package/src/data/table/root/DataTableRoot.context.ts +10 -8
  203. package/src/data/table/sub-row-toggle/DataTableSubRowToggle.tsx +1 -1
  204. package/src/data/table/tbody/DataTableTbody.tsx +3 -3
  205. package/src/data/table/tr/DataTableTr.tsx +51 -20
  206. package/src/data/token-filter/TokenFilter.tsx +1 -1
  207. package/src/data-grid/index.ts +3 -0
  208. package/src/data-grid/root/DataGrid.types.ts +46 -0
  209. package/src/data-grid/root/DataGridRoot.context.ts +21 -0
  210. package/src/data-grid/root/DataGridRoot.tsx +154 -0
  211. package/src/preview.ts +2 -0
  212. package/src/primitives/bleed/Bleed.tsx +0 -2
  213. package/src/table/ColumnHeader.tsx +1 -0
  214. package/src/utils/components/dismissablelayer/DismissableLayer.tsx +1 -0
  215. package/src/utils/components/dismissablelayer/util/useFocusOutside.ts +14 -2
  216. package/src/utils/hooks/useControllableState.ts +10 -8
  217. package/cjs/data/data-grid/index.d.ts +0 -2
  218. package/cjs/data/data-grid/index.js.map +0 -1
  219. package/cjs/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
  220. package/cjs/data/data-grid/root/DataGridRoot.context.js.map +0 -1
  221. package/cjs/data/data-grid/root/DataGridRoot.d.ts +0 -38
  222. package/cjs/data/data-grid/root/DataGridRoot.js.map +0 -1
  223. package/cjs/data/table/root/DataTable.types.js.map +0 -1
  224. package/cjs/data/table/root/DataTableRoot.d.ts +0 -118
  225. package/cjs/data/table/root/DataTableRoot.js.map +0 -1
  226. package/cjs/data/table/root/DataTableRoot.legacy.d.ts +0 -172
  227. package/cjs/data/table/root/DataTableRoot.legacy.js +0 -118
  228. package/cjs/data/table/root/DataTableRoot.legacy.js.map +0 -1
  229. package/esm/data/data-grid/index.d.ts +0 -2
  230. package/esm/data/data-grid/index.js +0 -3
  231. package/esm/data/data-grid/index.js.map +0 -1
  232. package/esm/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
  233. package/esm/data/data-grid/root/DataGridRoot.context.js.map +0 -1
  234. package/esm/data/data-grid/root/DataGridRoot.d.ts +0 -38
  235. package/esm/data/data-grid/root/DataGridRoot.js +0 -32
  236. package/esm/data/data-grid/root/DataGridRoot.js.map +0 -1
  237. package/esm/data/table/root/DataTable.types.js +0 -2
  238. package/esm/data/table/root/DataTable.types.js.map +0 -1
  239. package/esm/data/table/root/DataTableRoot.d.ts +0 -118
  240. package/esm/data/table/root/DataTableRoot.js.map +0 -1
  241. package/esm/data/table/root/DataTableRoot.legacy.d.ts +0 -172
  242. package/esm/data/table/root/DataTableRoot.legacy.js +0 -73
  243. package/esm/data/table/root/DataTableRoot.legacy.js.map +0 -1
  244. package/src/data/data-grid/index.ts +0 -3
  245. package/src/data/data-grid/root/DataGridRoot.context.ts +0 -16
  246. package/src/data/data-grid/root/DataGridRoot.tsx +0 -71
  247. package/src/data/table/Readme.md +0 -11
  248. package/src/data/table/agent-component-review.md +0 -175
  249. package/src/data/table/root/DataTableRoot.legacy.tsx +0 -305
@@ -7,12 +7,12 @@ interface DataTableBaseCellProps extends Omit<
7
7
  "width"
8
8
  > {
9
9
  /**
10
- * Content alignment inside cell.
10
+ * Text alignment inside cell.
11
11
  *
12
12
  * Quantitative figures like amounts and percentages should be right‑aligned (but not phone numbers, postal codes etc.)
13
13
  * @default "left"
14
14
  */
15
- textAlign?: "left" | "center" | "right";
15
+ align?: "left" | "center" | "right";
16
16
  /**
17
17
  * Internal cell type that controls padding, alignment, row-click prevention, and resize behavior.
18
18
  * - `"action"`: Centers content, removes cell padding, prevents row click, and disables column resize.
@@ -20,7 +20,7 @@ interface DataTableBaseCellProps extends Omit<
20
20
  */
21
21
  cellType?: "action";
22
22
  /**
23
- * When true, clicking this cell will not trigger `onRowClick` on the row.
23
+ * When true, clicking this cell will not trigger `onRowAction` on the row.
24
24
  * Useful for cells that contain their own interactive content or actions
25
25
  * that should be independent of row-level click handling.
26
26
  */
@@ -28,7 +28,7 @@ interface DataTableBaseCellProps extends Omit<
28
28
  /**
29
29
  * Sets a max-width on the content wrapper div inside the cell.
30
30
  * This is only needed when using `layout="auto"` together with
31
- * `truncateContent` on `<DataTable>` and you want the cell to be truncated.
31
+ * `truncateContent` on `<DataGrid.Table>` and you want the cell to be truncated.
32
32
  */
33
33
  contentMaxWidth?: number | string;
34
34
  /**
@@ -58,7 +58,7 @@ const DataTableBaseCell = forwardRef<
58
58
  children,
59
59
  as: Component,
60
60
  beforeContent,
61
- textAlign = "left",
61
+ align = "left",
62
62
  cellType,
63
63
  preventRowClick,
64
64
  contentMaxWidth,
@@ -77,7 +77,7 @@ const DataTableBaseCell = forwardRef<
77
77
  ref={forwardedRef}
78
78
  className={cl("aksel-data-table__cell", className)}
79
79
  tabIndex={withKeyboardNav ? -1 : undefined}
80
- data-align={textAlign}
80
+ data-align={align}
81
81
  data-cell-type={cellType || undefined}
82
82
  data-prevent-row-click={
83
83
  preventRowClick || cellType === "action" || undefined
@@ -6,21 +6,21 @@ import {
6
6
  SortDownIcon,
7
7
  SortUpIcon,
8
8
  } from "@navikt/aksel-icons";
9
+ import { useDataGridContext } from "../../../data-grid/root/DataGridRoot.context";
9
10
  import { cl } from "../../../utils/helpers";
10
11
  import { useMergeRefs } from "../../../utils/hooks";
11
12
  import {
12
13
  DataTableBaseCell,
13
14
  type DataTableBaseCellProps,
14
15
  } from "../base-cell/DataTableBaseCell";
15
- import type { SortDirection } from "../root/DataTable.types";
16
16
  import { useDataTableContext } from "../root/DataTableRoot.context";
17
17
  import { type ResizeProps, useTableColumnResize } from "./useTableColumnResize";
18
18
 
19
19
  interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
20
20
  /**
21
- * Unique identifier for the column. Required for sortable columns to identify which column is being sorted.
21
+ * Unique identifier for the column. Used when sorting to identify which column is being sorted.
22
22
  */
23
- id?: string;
23
+ id: string;
24
24
  /**
25
25
  * Accessible name of the column.
26
26
  */
@@ -29,18 +29,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
29
29
  * Makes the column sortable by clicking on the header.
30
30
  * The entire header cell content becomes a clickable button when true.
31
31
  */
32
- sortable?: boolean; // TODO: Consider merging sortable, sortDirection and onSortClick into a single "sort" object prop
33
- /**
34
- * Current sort direction. Only relevant when `sortable` is true.
35
- * Uses values matching the `aria-sort` attribute directly. // TODO: What does this mean? (Can we just remove it?)
36
- * @default "none"
37
- */
38
- sortDirection?: SortDirection; // TODO Not in use???
39
- /**
40
- * Called when the user clicks the header. Only relevant when `sortable` is true.
41
- * The consumer is responsible for determining and setting the next sort state. // TODO: We don't use the term "consumer" in JSDoc anywhere else
42
- */
43
- onSortClick?: (event: React.MouseEvent<HTMLElement>) => void; // TODO Not in use???
32
+ sortable?: boolean;
44
33
  /**
45
34
  * Object with props related to column width and resizing. Summary:
46
35
  *
@@ -49,7 +38,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
49
38
  * - `resizeMin?: number` - Minimum width of the column when resizing.
50
39
  * - `resizeMax?: number` - Maximum width of the column when resizing.
51
40
  * - `value?: number | string` - Controlled width of the column.
52
- * - `default?: number | string` - Initial width of the column.
41
+ * - `defaultValue?: number | string` - Initial width of the column.
53
42
  * - `onChange?: (width: number) => void` - Called when the column width changes.
54
43
  *
55
44
  * See individual props for details and defaults.
@@ -57,7 +46,7 @@ interface DataTableColumnHeaderProps extends DataTableBaseCellProps {
57
46
  width?: ResizeProps;
58
47
  }
59
48
 
60
- const SORT_ICON: Record<SortDirection, React.ElementType> = {
49
+ const SORT_ICON: Record<"asc" | "desc" | "none", React.ElementType> = {
61
50
  asc: SortUpIcon,
62
51
  desc: SortDownIcon,
63
52
  none: ArrowsUpDownIcon,
@@ -86,6 +75,7 @@ const DataTableColumnHeader = forwardRef<
86
75
  },
87
76
  forwardedRef,
88
77
  ) => {
78
+ const { isLoading } = useDataGridContext();
89
79
  const thRef = useRef<HTMLTableCellElement>(null);
90
80
  const mergedRef = useMergeRefs(forwardedRef, thRef);
91
81
  const { sortingState } = useDataTableContext();
@@ -106,6 +96,8 @@ const DataTableColumnHeader = forwardRef<
106
96
 
107
97
  const SortIcon = canSort ? SORT_ICON[sortDirection] : null;
108
98
 
99
+ const contentId = `th-content-${id.replace(/\s/g, "-")}`;
100
+
109
101
  return (
110
102
  <DataTableBaseCell
111
103
  as="th"
@@ -116,14 +108,18 @@ const DataTableColumnHeader = forwardRef<
116
108
  style={{ ...style, width: resizeResult.width }}
117
109
  aria-sort={canSort ? getAriaSort(sortDirection) : undefined}
118
110
  cellType={cellType}
111
+ aria-labelledby={contentId} // Avoids VO announcing "Endre bredde" when navigating horizontally in tbody
119
112
  >
120
113
  {canSort ? (
121
114
  <button
122
115
  type="button"
123
116
  className="aksel-data-table__th-sort-button"
124
117
  onClick={(event) => onSortClick(id, event)}
118
+ disabled={isLoading}
125
119
  >
126
- <div className="aksel-data-table__th-content">{children}</div>
120
+ <div id={contentId} className="aksel-data-table__th-content">
121
+ {children}
122
+ </div>
127
123
  {SortIcon && (
128
124
  <SortIcon
129
125
  aria-hidden
@@ -135,6 +131,7 @@ const DataTableColumnHeader = forwardRef<
135
131
  </button>
136
132
  ) : (
137
133
  <div
134
+ id={contentId}
138
135
  className={cl({
139
136
  "aksel-data-table__th-content": cellType !== "action",
140
137
  })}
@@ -164,7 +161,7 @@ const DataTableColumnHeader = forwardRef<
164
161
  typeof resizeResult.width === "number" &&
165
162
  resizeResult.isResizingWithKeyboard
166
163
  ? resizeResult.width.toString()
167
- : "" // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
164
+ : " " // Needs to be blank when not in keyboard resizing mode to avoid NVDA announcing the value as part of the column heading
168
165
  } // Need either this or aria-valuemax to get SR (at least NVDA) to announce the value
169
166
  >
170
167
  {resizeResult.isResizingWithKeyboard && (
@@ -185,7 +182,7 @@ const DataTableColumnHeader = forwardRef<
185
182
  );
186
183
 
187
184
  function getAriaSort(
188
- sortDirection: SortDirection | undefined,
185
+ sortDirection: "asc" | "desc" | "none" | undefined,
189
186
  ): "ascending" | "descending" | "none" | undefined {
190
187
  if (sortDirection === "asc") return "ascending";
191
188
  if (sortDirection === "desc") return "descending";
@@ -26,8 +26,6 @@ type ResizeProps = {
26
26
  * consider using `layout="auto"` on the root instead for better performance.
27
27
  *
28
28
  * **NB:** This can cause a layout shift. Set a good initial width with `width` or `defaultWidth` to mitigate this.
29
- *
30
- * **NB:** Does not work with block content.
31
29
  */
32
30
  autoResizeOnce?: boolean;
33
31
  /**
@@ -55,7 +53,7 @@ type ResizeProps = {
55
53
  * **NB:** Percentage as initial width does not work well with resizing.
56
54
  * @default 140px
57
55
  */
58
- default?: number | string;
56
+ defaultValue?: number | string;
59
57
  /**
60
58
  * Called when the column width changes.
61
59
  * @param width New width in pixels.
@@ -98,7 +96,7 @@ function useTableColumnResize({
98
96
  resizeMin = 40,
99
97
  resizeMax = Infinity,
100
98
  value,
101
- default: defaultProp,
99
+ defaultValue,
102
100
  onChange,
103
101
  thRef,
104
102
  colSpan,
@@ -110,7 +108,7 @@ function useTableColumnResize({
110
108
 
111
109
  const [width, setWidth] = useControllableState({
112
110
  value,
113
- defaultValue: defaultProp ?? (colSpan ?? 1) * 140,
111
+ defaultValue: defaultValue ?? (colSpan ?? 1) * 140,
114
112
  /**
115
113
  * TODO:
116
114
  * - Potential optimization: Only call when width as "stopped" changing, e.g. on mouse up or after a debounce when resizing with keyboard.
@@ -292,7 +290,6 @@ function useTableColumnResize({
292
290
 
293
291
  /**
294
292
  * Figures out how wide the column needs to be to fit all the content without truncation.
295
- * NB: Does not work with block content!
296
293
  */
297
294
  function getAutoColumnWidth(
298
295
  thRef: React.RefObject<HTMLTableCellElement | null>,
@@ -344,18 +341,24 @@ function getAutoColumnWidth(
344
341
  // Find needed width
345
342
  const cellContent = cell.querySelector(
346
343
  ".aksel-data-table__cell-content",
347
- ) as HTMLElement;
348
- range.selectNodeContents(cellContent);
349
- const cellContentWidth = range.getBoundingClientRect().width;
350
- const contentElStyle = window.getComputedStyle(cellContent);
351
- const inlinePadding =
352
- parseInt(contentElStyle.paddingLeft, 10) +
353
- parseInt(contentElStyle.paddingRight, 10);
354
- const marginLeft = parseInt(contentElStyle.marginLeft, 10); // We don't have right margin for now
344
+ ) as HTMLElement | null;
345
+
346
+ if (!cellContent) {
347
+ continue;
348
+ }
349
+
350
+ cellContent.style.width = "fit-content";
351
+ const cellContentWidth = cellContent.scrollWidth;
352
+ cellContent.style.removeProperty("width");
353
+ let marginLeft = 0;
354
+ if (cell.dataset.nested === "true") {
355
+ const contentElStyle = window.getComputedStyle(cellContent);
356
+ marginLeft = parseInt(contentElStyle.marginLeft, 10);
357
+ }
355
358
  const widthNeededForThisCell =
356
- (cellContentWidth + inlinePadding + marginLeft) / cell.colSpan;
359
+ (cellContentWidth + marginLeft + 1) / cell.colSpan;
357
360
  if (widthNeededForThisCell > newColumnWidth) {
358
- newColumnWidth = widthNeededForThisCell;
361
+ newColumnWidth = Math.ceil(widthNeededForThisCell);
359
362
  }
360
363
  }
361
364
 
@@ -1,4 +1,4 @@
1
- import type { TableRowEntryId } from "../root/DataTable.types";
1
+ import type { TableRowEntryId } from "../root/DataGridTable.types";
2
2
 
3
3
  type CollectTableRowEntriesArgs<T> = {
4
4
  items: T[];
@@ -2,15 +2,16 @@ import type { ChangeEventHandler, SetStateAction } from "react";
2
2
  import type { CheckboxInputProps } from "../../../../form/checkbox/checkbox-input/CheckboxInput";
3
3
  import { consoleWarning } from "../../../../utils/helpers/consoleWarning";
4
4
  import type { UseTableItemsReturn } from "../../hooks/useTableItems";
5
- import type { TableRowEntryId } from "../../root/DataTable.types";
6
- import type { SelectedKeysT, SelectionProps } from "./selection.types";
5
+ import type { TableRowEntryId } from "../../root/DataGridTable.types";
6
+ import type { SelectionProps } from "./selection.types";
7
7
  import { canSelectTableRow, mutateRowSelection } from "./selection.utils";
8
8
 
9
9
  type GetMultipleSelectPropsArgs<T> = {
10
10
  selectedKeysSet: Set<TableRowEntryId>;
11
- selectedKeys: SelectedKeysT;
12
- setSelectedKeys: (next: SetStateAction<SelectedKeysT>) => void;
11
+ selectedKeys: string[];
12
+ setSelectedKeys: (next: SetStateAction<string[]>) => void;
13
13
  tableItems: UseTableItemsReturn<T>;
14
+ isLoading?: boolean;
14
15
  } & Pick<SelectionProps<T>, "enableRowSelection">;
15
16
 
16
17
  function getMultipleSelectProps<T>({
@@ -19,6 +20,7 @@ function getMultipleSelectProps<T>({
19
20
  setSelectedKeys,
20
21
  enableRowSelection,
21
22
  tableItems,
23
+ isLoading,
22
24
  }: GetMultipleSelectPropsArgs<T>) {
23
25
  const selectableIdsSet: Set<TableRowEntryId> = new Set();
24
26
 
@@ -40,7 +42,7 @@ function getMultipleSelectProps<T>({
40
42
  const handleToggleRow = (key: TableRowEntryId, row: T) => {
41
43
  if (!row) {
42
44
  consoleWarning(
43
- `Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
45
+ `DataGrid.Table: Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
44
46
  );
45
47
  }
46
48
 
@@ -62,6 +64,9 @@ function getMultipleSelectProps<T>({
62
64
  const toggleAllRowSelected: ChangeEventHandler<HTMLInputElement> = (
63
65
  event,
64
66
  ) => {
67
+ if (isLoading) {
68
+ return;
69
+ }
65
70
  if (event.target.checked) {
66
71
  const preserved = selectedKeys.filter((k) => !selectableIdsSet.has(k));
67
72
  setSelectedKeys([...preserved, ...selectableIdsSet]);
@@ -75,6 +80,7 @@ function getMultipleSelectProps<T>({
75
80
  checked: isAllSelected,
76
81
  indeterminate: !isAllSelected && someSelected,
77
82
  onChange: toggleAllRowSelected,
83
+ disabled: selectableIdsSet.size === 0 || isLoading,
78
84
  }),
79
85
  getRowCheckboxProps: (key: TableRowEntryId, row: T): CheckboxInputProps => {
80
86
  return {
@@ -1,12 +1,12 @@
1
1
  import type { RadioInputProps } from "../../../../form/radio/radio-input/RadioInput";
2
2
  import { consoleWarning } from "../../../../utils/helpers/consoleWarning";
3
- import type { TableRowEntryId } from "../../root/DataTable.types";
4
- import type { SelectedKeysT, SelectionProps } from "./selection.types";
3
+ import type { TableRowEntryId } from "../../root/DataGridTable.types";
4
+ import type { SelectionProps } from "./selection.types";
5
5
  import { canSelectTableRow } from "./selection.utils";
6
6
 
7
7
  type GetSingleSelectPropsArgs<T> = {
8
8
  selectedKeysSet: Set<TableRowEntryId>;
9
- setSelectedKeys: (keys: SelectedKeysT) => void;
9
+ setSelectedKeys: (keys: string[]) => void;
10
10
  name: string;
11
11
  } & Pick<SelectionProps<T>, "enableRowSelection">;
12
12
 
@@ -19,7 +19,7 @@ function getSingleSelectProps<T>({
19
19
  const handleSelectionChange = (key: TableRowEntryId, row: T) => {
20
20
  if (!row) {
21
21
  consoleWarning(
22
- `Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
22
+ `DataGrid.Table: Row data is undefined for key ${key}. This may cause issues with selection if enableRowSelection is used.`,
23
23
  );
24
24
  }
25
25
  if (!canSelectTableRow(enableRowSelection, { row, id: key })) {
@@ -1,11 +1,7 @@
1
1
  import type { CheckboxInputProps } from "../../../../form/checkbox/checkbox-input/CheckboxInput";
2
2
  import type { RadioInputProps } from "../../../../form/radio/radio-input/RadioInput";
3
- import type { TableRowEntryId } from "../../root/DataTable.types";
4
3
 
5
- type SelectedKeysT = TableRowEntryId[];
6
-
7
- // TODO: Remove `any` if possible
8
- type SelectionProps<T = any> = {
4
+ type SelectionProps<T = unknown> = {
9
5
  /**
10
6
  * Enables selection of rows.
11
7
  *
@@ -16,57 +12,51 @@ type SelectionProps<T = any> = {
16
12
  *
17
13
  * @default "none"
18
14
  */
19
- selectionMode: "none" | "single" | "multiple";
15
+ mode: "none" | "single" | "multiple";
20
16
  /**
21
- * Controlled selected keys. Should be used in conjunction with `onSelectionChange`.
17
+ * Controlled selected keys. Should be used in conjunction with `onSelectedRowIdsChange`.
22
18
  */
23
- selectedKeys?: SelectedKeysT;
19
+ selectedRowIds?: string[];
24
20
  /**
25
21
  * Default selected keys when using uncontrolled selection. Should not be used together with `selectedKeys`.
26
22
  */
27
- defaultSelectedKeys?: SelectedKeysT;
23
+ defaultSelectedRowIds?: string[];
28
24
  /**
29
25
  * Callback with array of selected keys.
30
26
  */
31
- onSelectionChange?: (keys: SelectedKeysT) => void;
27
+ onSelectedRowIdsChange?: (ids: string[]) => void;
32
28
  /**
33
29
  * Callback to determine if a row should be enabled for selection.
34
30
  *
35
- *
36
31
  * If set to a boolean, it will enable selection for all rows when true, and disable selection for all rows when false.
37
32
  */
38
33
  enableRowSelection?:
39
- | (({ row, id }: { row: T; id: TableRowEntryId }) => boolean)
34
+ | (({ row, id }: { row: T; id: string }) => boolean)
40
35
  | boolean;
41
- /**
42
- * Determines if selection is triggered by clicking the row or the selection control (checkbox/radio).
43
- * @default "row"
44
- */
45
- selectionTrigger?: "row" | "control";
46
36
  };
47
37
 
48
38
  type NoneSelection = {
49
- selectionMode: "none";
50
- selectedKeys: SelectedKeysT;
39
+ mode: "none";
40
+ selectedKeys: string[];
51
41
  };
52
42
 
53
43
  type SingleSelection = {
54
- selectionMode: "single";
55
- selectedKeys: SelectedKeysT;
56
- getRowRadioProps: (key: TableRowEntryId, row: any) => RadioInputProps;
57
- toggleSelection: (key: TableRowEntryId, row: any) => void;
44
+ mode: "single";
45
+ selectedKeys: string[];
46
+ getRowRadioProps: (key: string, row: any) => RadioInputProps;
47
+ toggleSelection: (key: string, row: any) => void;
58
48
  };
59
49
 
60
50
  type MultipleSelection = {
61
- selectionMode: "multiple";
62
- selectedKeys: SelectedKeysT;
51
+ mode: "multiple";
52
+ selectedKeys: string[];
63
53
  getTheadCheckboxProps: () => CheckboxInputProps;
64
- getRowCheckboxProps: (key: TableRowEntryId, row: any) => CheckboxInputProps;
65
- toggleSelection: (key: TableRowEntryId, row: any) => void;
54
+ getRowCheckboxProps: (key: string, row: any) => CheckboxInputProps;
55
+ toggleSelection: (key: string, row: any) => void;
66
56
  };
67
57
 
68
58
  type TableSelectionBase = {
69
- isRowSelected: (rowId: TableRowEntryId) => boolean;
59
+ isRowSelected: (rowId: string) => boolean;
70
60
  };
71
61
 
72
62
  type TableSelection = TableSelectionBase &
@@ -75,7 +65,6 @@ type TableSelection = TableSelectionBase &
75
65
  export type {
76
66
  MultipleSelection,
77
67
  NoneSelection,
78
- SelectedKeysT,
79
68
  SelectionProps,
80
69
  SingleSelection,
81
70
  TableSelection,
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import type { TableRowEntryId } from "../../root/DataTable.types";
2
+ import type { TableRowEntryId } from "../../root/DataGridTable.types";
3
3
  import type { ItemDetail } from "../collectTableRowEntries";
4
4
  import { mutateRowSelection } from "./selection.utils";
5
5
 
@@ -1,4 +1,4 @@
1
- import type { TableRowEntryId } from "../../root/DataTable.types";
1
+ import type { TableRowEntryId } from "../../root/DataGridTable.types";
2
2
  import type { ItemDetail } from "../collectTableRowEntries";
3
3
  import type { SelectionProps } from "./selection.types";
4
4
 
@@ -137,7 +137,7 @@ function getStickyOffsets(element: HTMLElement): {
137
137
  }
138
138
 
139
139
  const stickyHeader = table.querySelector<HTMLElement>(
140
- `.aksel-data-table__tr[data-sticky="true"]`,
140
+ `.aksel-data-table__thead[data-sticky="true"]`,
141
141
  );
142
142
 
143
143
  const stickyNodesStart = table.querySelectorAll<HTMLElement>(
@@ -1,6 +1,6 @@
1
1
  import { renderHook } from "@testing-library/react";
2
2
  import { describe, expect, test } from "vitest";
3
- import type { TableRowEntryId } from "../../root/DataTable.types";
3
+ import type { TableRowEntryId } from "../../root/DataGridTable.types";
4
4
  import { useTableItems } from "../useTableItems";
5
5
 
6
6
  type TestRow = {
@@ -1,18 +1,23 @@
1
1
  import { useMemo } from "react";
2
+ import { consoleWarning } from "../../../utils/helpers/consoleWarning";
2
3
  import type {
3
4
  ColumnDefinition,
4
5
  ColumnDefinitions,
5
- } from "../root/DataTable.types";
6
+ } from "../root/DataGridTable.types";
6
7
  import { ACTION_CELL_WIDTH } from "../tr/DataTableTr";
7
8
 
8
9
  type UseColumnOptions = {
9
10
  stickyColumns?: {
10
- start?: "1";
11
- end?: "1";
11
+ start?: 1;
12
+ end?: 1;
12
13
  };
13
14
  hasSelection: boolean;
14
15
  hasDetailsPanel: boolean;
15
16
  layout: "fixed" | "auto";
17
+ columnDisplay?: {
18
+ id: string;
19
+ visible: boolean;
20
+ }[];
16
21
  };
17
22
 
18
23
  type StickyStartState = {
@@ -37,9 +42,15 @@ function useColumnOptions<T>(
37
42
  columnDefinitions: ColumnDefinitions<T>,
38
43
  options: UseColumnOptions,
39
44
  ): UseColumnOptionsResult<T> {
40
- const { stickyColumns, hasSelection, hasDetailsPanel, layout } = options;
45
+ const {
46
+ stickyColumns,
47
+ hasSelection,
48
+ hasDetailsPanel,
49
+ layout,
50
+ columnDisplay,
51
+ } = options;
41
52
 
42
- const hasStickyStart = stickyColumns?.start === "1";
53
+ const hasStickyStart = stickyColumns?.start === 1;
43
54
 
44
55
  const stickyExpansion = hasStickyStart && hasDetailsPanel;
45
56
  const stickySelection = hasStickyStart && hasSelection;
@@ -49,11 +60,15 @@ function useColumnOptions<T>(
49
60
  (stickyExpansion ? ACTION_CELL_WIDTH : 0) +
50
61
  (stickySelection ? ACTION_CELL_WIDTH : 0);
51
62
 
63
+ const visibleColumns = useMemo(() => {
64
+ return orderColumnsAndFilterByVisibility(columnDefinitions, columnDisplay);
65
+ }, [columnDefinitions, columnDisplay]);
66
+
52
67
  const columns = useMemo(() => {
53
- return columnDefinitions.map((colDef, index) => {
68
+ return visibleColumns.map((colDef, index) => {
54
69
  const isFirstSticky = hasStickyStart && index === 0;
55
70
  const isLastSticky =
56
- stickyColumns?.end === "1" && index === columnDefinitions.length - 1;
71
+ stickyColumns?.end === 1 && index === visibleColumns.length - 1;
57
72
 
58
73
  return {
59
74
  isSticky: isFirstSticky
@@ -66,12 +81,7 @@ function useColumnOptions<T>(
66
81
  colDef,
67
82
  };
68
83
  });
69
- }, [
70
- columnDefinitions,
71
- hasStickyStart,
72
- stickyColumns,
73
- stickyFirstColumnOffset,
74
- ]);
84
+ }, [visibleColumns, hasStickyStart, stickyColumns, stickyFirstColumnOffset]);
75
85
 
76
86
  const totalColSpan =
77
87
  columns.length +
@@ -91,6 +101,31 @@ function useColumnOptions<T>(
91
101
  };
92
102
  }
93
103
 
104
+ function orderColumnsAndFilterByVisibility<T>(
105
+ columns: ColumnDefinition<T>[],
106
+ columnDisplay?: { id: string; visible: boolean }[],
107
+ ): ColumnDefinition<T>[] {
108
+ if (!columnDisplay) {
109
+ return columns;
110
+ }
111
+
112
+ const columnMap = new Map(columns.map((col) => [col.id, col]));
113
+
114
+ return columnDisplay.reduce<ColumnDefinition<T>[]>((acc, { id, visible }) => {
115
+ const col = columnMap.get(id);
116
+
117
+ if (!col) {
118
+ consoleWarning(
119
+ `DataGrid: Column with id "${id}" not found in column definitions. Please check your columnDisplay configuration.`,
120
+ );
121
+ }
122
+
123
+ if (col && visible) {
124
+ acc.push(col);
125
+ }
126
+ return acc;
127
+ }, []);
128
+ }
129
+
94
130
  export { useColumnOptions };
95
- export type { StickyStartState };
96
- export type { UseColumnOptionsResult };
131
+ export type { StickyStartState, UseColumnOptionsResult };