@navikt/ds-react 8.10.6 → 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 (209) hide show
  1. package/cjs/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
  2. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js +2 -2
  3. package/cjs/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  4. package/cjs/data/stories/Data.test-data.d.ts +2 -2
  5. package/cjs/data/stories/Data.test-data.js +37 -42
  6. package/cjs/data/stories/Data.test-data.js.map +1 -1
  7. package/cjs/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
  8. package/cjs/data/table/base-cell/DataTableBaseCell.js +2 -2
  9. package/cjs/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  10. package/cjs/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
  11. package/cjs/data/table/column-header/DataTableColumnHeader.js +8 -5
  12. package/cjs/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  13. package/cjs/data/table/column-header/useTableColumnResize.d.ts +2 -2
  14. package/cjs/data/table/column-header/useTableColumnResize.js +10 -10
  15. package/cjs/data/table/column-header/useTableColumnResize.js.map +1 -1
  16. package/cjs/data/table/helpers/collectTableRowEntries.d.ts +1 -1
  17. package/cjs/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
  18. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
  19. package/cjs/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  20. package/cjs/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
  21. package/cjs/data/table/helpers/selection/getSingleSelectProps.js +1 -1
  22. package/cjs/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  23. package/cjs/data/table/helpers/selection/selection.types.d.ts +19 -27
  24. package/cjs/data/table/helpers/selection/selection.utils.d.ts +1 -1
  25. package/cjs/data/table/hooks/useColumnOptions.d.ts +3 -3
  26. package/cjs/data/table/hooks/useColumnOptions.js +2 -2
  27. package/cjs/data/table/hooks/useColumnOptions.js.map +1 -1
  28. package/cjs/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
  29. package/cjs/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  30. package/cjs/data/table/hooks/useTableItems.d.ts +10 -11
  31. package/cjs/data/table/hooks/useTableItems.js +11 -3
  32. package/cjs/data/table/hooks/useTableItems.js.map +1 -1
  33. package/cjs/data/table/hooks/useTableSelection.d.ts +2 -1
  34. package/cjs/data/table/hooks/useTableSelection.js +46 -29
  35. package/cjs/data/table/hooks/useTableSelection.js.map +1 -1
  36. package/cjs/data/table/hooks/useTableSort.d.ts +13 -7
  37. package/cjs/data/table/hooks/useTableSort.js +8 -9
  38. package/cjs/data/table/hooks/useTableSort.js.map +1 -1
  39. package/cjs/data/table/index.d.ts +1 -1
  40. package/cjs/data/table/index.js +3 -23
  41. package/cjs/data/table/index.js.map +1 -1
  42. package/cjs/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
  43. package/cjs/data/table/root/DataGridTable.types.js +3 -0
  44. package/cjs/data/table/root/DataGridTable.types.js.map +1 -0
  45. package/cjs/data/table/root/DataGridTableRoot.d.ts +104 -0
  46. package/cjs/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +57 -37
  47. package/cjs/data/table/root/DataGridTableRoot.js.map +1 -0
  48. package/cjs/data/table/root/DataTableRoot.context.d.ts +6 -2
  49. package/cjs/data/table/root/DataTableRoot.context.js.map +1 -1
  50. package/cjs/data/table/tbody/DataTableTbody.js +3 -3
  51. package/cjs/data/table/tbody/DataTableTbody.js.map +1 -1
  52. package/cjs/data/table/tr/DataTableTr.d.ts +3 -3
  53. package/cjs/data/table/tr/DataTableTr.js +44 -20
  54. package/cjs/data/table/tr/DataTableTr.js.map +1 -1
  55. package/cjs/data/token-filter/TokenFilter.d.ts +0 -6
  56. package/cjs/data/token-filter/TokenFilter.js +1 -1
  57. package/cjs/data-grid/index.d.ts +2 -0
  58. package/cjs/data-grid/index.js +9 -0
  59. package/cjs/data-grid/index.js.map +1 -0
  60. package/cjs/data-grid/root/DataGrid.types.d.ts +35 -0
  61. package/cjs/{data/table/root/DataTable.types.js → data-grid/root/DataGrid.types.js} +1 -1
  62. package/cjs/data-grid/root/DataGrid.types.js.map +1 -0
  63. package/cjs/data-grid/root/DataGridRoot.context.d.ts +16 -0
  64. package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
  65. package/cjs/data-grid/root/DataGridRoot.context.js.map +1 -0
  66. package/cjs/data-grid/root/DataGridRoot.d.ts +89 -0
  67. package/cjs/{data/data-grid → data-grid}/root/DataGridRoot.js +33 -8
  68. package/cjs/data-grid/root/DataGridRoot.js.map +1 -0
  69. package/cjs/preview.d.ts +1 -0
  70. package/cjs/{data/data-grid/index.js → preview.js} +3 -3
  71. package/cjs/preview.js.map +1 -0
  72. package/cjs/table/ColumnHeader.js.map +1 -1
  73. package/esm/data/drag-and-drop/root/DragAndDropRoot.d.ts +1 -1
  74. package/esm/data/drag-and-drop/root/DragAndDropRoot.js +2 -2
  75. package/esm/data/drag-and-drop/root/DragAndDropRoot.js.map +1 -1
  76. package/esm/data/stories/Data.test-data.d.ts +2 -2
  77. package/esm/data/stories/Data.test-data.js +37 -42
  78. package/esm/data/stories/Data.test-data.js.map +1 -1
  79. package/esm/data/table/base-cell/DataTableBaseCell.d.ts +4 -4
  80. package/esm/data/table/base-cell/DataTableBaseCell.js +2 -2
  81. package/esm/data/table/base-cell/DataTableBaseCell.js.map +1 -1
  82. package/esm/data/table/column-header/DataTableColumnHeader.d.ts +3 -15
  83. package/esm/data/table/column-header/DataTableColumnHeader.js +8 -5
  84. package/esm/data/table/column-header/DataTableColumnHeader.js.map +1 -1
  85. package/esm/data/table/column-header/useTableColumnResize.d.ts +2 -2
  86. package/esm/data/table/column-header/useTableColumnResize.js +10 -10
  87. package/esm/data/table/column-header/useTableColumnResize.js.map +1 -1
  88. package/esm/data/table/helpers/collectTableRowEntries.d.ts +1 -1
  89. package/esm/data/table/helpers/selection/getMultipleSelectProps.d.ts +6 -5
  90. package/esm/data/table/helpers/selection/getMultipleSelectProps.js +6 -2
  91. package/esm/data/table/helpers/selection/getMultipleSelectProps.js.map +1 -1
  92. package/esm/data/table/helpers/selection/getSingleSelectProps.d.ts +3 -3
  93. package/esm/data/table/helpers/selection/getSingleSelectProps.js +1 -1
  94. package/esm/data/table/helpers/selection/getSingleSelectProps.js.map +1 -1
  95. package/esm/data/table/helpers/selection/selection.types.d.ts +19 -27
  96. package/esm/data/table/helpers/selection/selection.utils.d.ts +1 -1
  97. package/esm/data/table/hooks/useColumnOptions.d.ts +3 -3
  98. package/esm/data/table/hooks/useColumnOptions.js +2 -2
  99. package/esm/data/table/hooks/useColumnOptions.js.map +1 -1
  100. package/esm/data/table/hooks/useTableDetailsPanel.d.ts +8 -9
  101. package/esm/data/table/hooks/useTableDetailsPanel.js.map +1 -1
  102. package/esm/data/table/hooks/useTableItems.d.ts +10 -11
  103. package/esm/data/table/hooks/useTableItems.js +11 -3
  104. package/esm/data/table/hooks/useTableItems.js.map +1 -1
  105. package/esm/data/table/hooks/useTableSelection.d.ts +2 -1
  106. package/esm/data/table/hooks/useTableSelection.js +46 -29
  107. package/esm/data/table/hooks/useTableSelection.js.map +1 -1
  108. package/esm/data/table/hooks/useTableSort.d.ts +13 -7
  109. package/esm/data/table/hooks/useTableSort.js +9 -10
  110. package/esm/data/table/hooks/useTableSort.js.map +1 -1
  111. package/esm/data/table/index.d.ts +1 -1
  112. package/esm/data/table/index.js +1 -21
  113. package/esm/data/table/index.js.map +1 -1
  114. package/esm/data/table/root/{DataTable.types.d.ts → DataGridTable.types.d.ts} +16 -26
  115. package/esm/data/table/root/DataGridTable.types.js +2 -0
  116. package/esm/data/table/root/DataGridTable.types.js.map +1 -0
  117. package/esm/data/table/root/DataGridTableRoot.d.ts +104 -0
  118. package/esm/data/table/root/{DataTableRoot.js → DataGridTableRoot.js} +59 -38
  119. package/esm/data/table/root/DataGridTableRoot.js.map +1 -0
  120. package/esm/data/table/root/DataTableRoot.context.d.ts +6 -2
  121. package/esm/data/table/root/DataTableRoot.context.js.map +1 -1
  122. package/esm/data/table/tbody/DataTableTbody.js +3 -3
  123. package/esm/data/table/tbody/DataTableTbody.js.map +1 -1
  124. package/esm/data/table/tr/DataTableTr.d.ts +3 -3
  125. package/esm/data/table/tr/DataTableTr.js +44 -20
  126. package/esm/data/table/tr/DataTableTr.js.map +1 -1
  127. package/esm/data/token-filter/TokenFilter.d.ts +0 -6
  128. package/esm/data/token-filter/TokenFilter.js +1 -1
  129. package/esm/data-grid/index.d.ts +2 -0
  130. package/esm/data-grid/index.js +4 -0
  131. package/esm/data-grid/index.js.map +1 -0
  132. package/esm/data-grid/root/DataGrid.types.d.ts +35 -0
  133. package/esm/data-grid/root/DataGrid.types.js +2 -0
  134. package/esm/data-grid/root/DataGrid.types.js.map +1 -0
  135. package/esm/data-grid/root/DataGridRoot.context.d.ts +16 -0
  136. package/esm/{data/data-grid → data-grid}/root/DataGridRoot.context.js +1 -1
  137. package/esm/data-grid/root/DataGridRoot.context.js.map +1 -0
  138. package/esm/data-grid/root/DataGridRoot.d.ts +89 -0
  139. package/esm/data-grid/root/DataGridRoot.js +57 -0
  140. package/esm/data-grid/root/DataGridRoot.js.map +1 -0
  141. package/esm/preview.d.ts +1 -0
  142. package/esm/preview.js +3 -0
  143. package/esm/preview.js.map +1 -0
  144. package/esm/table/ColumnHeader.js.map +1 -1
  145. package/package.json +23 -3
  146. package/src/data/drag-and-drop/root/DragAndDropRoot.tsx +3 -3
  147. package/src/data/stories/Data.test-data.tsx +53 -51
  148. package/src/data/table/base-cell/DataTableBaseCell.tsx +6 -6
  149. package/src/data/table/column-header/DataTableColumnHeader.tsx +17 -20
  150. package/src/data/table/column-header/useTableColumnResize.ts +14 -14
  151. package/src/data/table/helpers/collectTableRowEntries.ts +1 -1
  152. package/src/data/table/helpers/selection/getMultipleSelectProps.ts +11 -5
  153. package/src/data/table/helpers/selection/getSingleSelectProps.ts +4 -4
  154. package/src/data/table/helpers/selection/selection.types.ts +19 -29
  155. package/src/data/table/helpers/selection/selection.utils.test.ts +1 -1
  156. package/src/data/table/helpers/selection/selection.utils.ts +1 -1
  157. package/src/data/table/hooks/__tests__/useTableItems.test.ts +1 -1
  158. package/src/data/table/hooks/useColumnOptions.ts +5 -5
  159. package/src/data/table/hooks/useTableDetailsPanel.tsx +14 -18
  160. package/src/data/table/hooks/useTableItems.ts +37 -23
  161. package/src/data/table/hooks/useTableSelection.ts +62 -45
  162. package/src/data/table/hooks/useTableSort.ts +29 -17
  163. package/src/data/table/index.tsx +4 -21
  164. package/src/data/table/root/{DataTable.types.ts → DataGridTable.types.ts} +17 -30
  165. package/src/data/table/root/{DataTableRoot.tsx → DataGridTableRoot.tsx} +196 -143
  166. package/src/data/table/root/DataTableRoot.context.ts +10 -8
  167. package/src/data/table/sub-row-toggle/DataTableSubRowToggle.tsx +1 -1
  168. package/src/data/table/tbody/DataTableTbody.tsx +3 -3
  169. package/src/data/table/tr/DataTableTr.tsx +51 -16
  170. package/src/data/token-filter/TokenFilter.tsx +1 -1
  171. package/src/data-grid/index.ts +3 -0
  172. package/src/data-grid/root/DataGrid.types.ts +36 -0
  173. package/src/data-grid/root/DataGridRoot.context.ts +21 -0
  174. package/src/data-grid/root/DataGridRoot.tsx +152 -0
  175. package/src/preview.ts +2 -0
  176. package/src/table/ColumnHeader.tsx +1 -0
  177. package/cjs/data/data-grid/index.d.ts +0 -2
  178. package/cjs/data/data-grid/index.js.map +0 -1
  179. package/cjs/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
  180. package/cjs/data/data-grid/root/DataGridRoot.context.js.map +0 -1
  181. package/cjs/data/data-grid/root/DataGridRoot.d.ts +0 -38
  182. package/cjs/data/data-grid/root/DataGridRoot.js.map +0 -1
  183. package/cjs/data/table/root/DataTable.types.js.map +0 -1
  184. package/cjs/data/table/root/DataTableRoot.d.ts +0 -118
  185. package/cjs/data/table/root/DataTableRoot.js.map +0 -1
  186. package/cjs/data/table/root/DataTableRoot.legacy.d.ts +0 -172
  187. package/cjs/data/table/root/DataTableRoot.legacy.js +0 -118
  188. package/cjs/data/table/root/DataTableRoot.legacy.js.map +0 -1
  189. package/esm/data/data-grid/index.d.ts +0 -2
  190. package/esm/data/data-grid/index.js +0 -3
  191. package/esm/data/data-grid/index.js.map +0 -1
  192. package/esm/data/data-grid/root/DataGridRoot.context.d.ts +0 -11
  193. package/esm/data/data-grid/root/DataGridRoot.context.js.map +0 -1
  194. package/esm/data/data-grid/root/DataGridRoot.d.ts +0 -38
  195. package/esm/data/data-grid/root/DataGridRoot.js +0 -32
  196. package/esm/data/data-grid/root/DataGridRoot.js.map +0 -1
  197. package/esm/data/table/root/DataTable.types.js +0 -2
  198. package/esm/data/table/root/DataTable.types.js.map +0 -1
  199. package/esm/data/table/root/DataTableRoot.d.ts +0 -118
  200. package/esm/data/table/root/DataTableRoot.js.map +0 -1
  201. package/esm/data/table/root/DataTableRoot.legacy.d.ts +0 -172
  202. package/esm/data/table/root/DataTableRoot.legacy.js +0 -73
  203. package/esm/data/table/root/DataTableRoot.legacy.js.map +0 -1
  204. package/src/data/data-grid/index.ts +0 -3
  205. package/src/data/data-grid/root/DataGridRoot.context.ts +0 -16
  206. package/src/data/data-grid/root/DataGridRoot.tsx +0 -71
  207. package/src/data/table/Readme.md +0 -11
  208. package/src/data/table/agent-component-review.md +0 -175
  209. package/src/data/table/root/DataTableRoot.legacy.tsx +0 -305
@@ -1,8 +1,10 @@
1
1
  import React from "react";
2
2
  import { MenuElipsisVerticalIcon } from "@navikt/aksel-icons";
3
+ import { ActionMenu } from "../../action-menu";
3
4
  import { Button } from "../../button";
5
+ import { HStack } from "../../primitives/stack";
4
6
  import { Tag } from "../../tag";
5
- import type { ColumnDefinitions } from "../table/root/DataTable.types";
7
+ import type { ColumnDefinitions } from "../table/root/DataGridTable.types";
6
8
 
7
9
  type SWData = {
8
10
  id: number;
@@ -22,47 +24,48 @@ type SWData = {
22
24
  const columnDef_TEST_DATA: ColumnDefinitions<SWData> = [
23
25
  {
24
26
  id: "id",
25
- label: "Id",
26
- cell: (row) => row.id,
27
+ header: "Id",
28
+ bodyCell: (row) => row.id,
27
29
  width: { autoResizeOnce: true },
28
30
  },
29
31
  {
30
- label: "Name",
32
+ header: "Name",
31
33
  id: "name",
32
- cell: (row) =>
34
+ isRowHeader: true,
35
+ bodyCell: (row) =>
33
36
  `${row.name} ${row?.nestedRows?.length > 0 ? `(${row?.nestedRows?.length})` : ""}`,
34
37
  },
35
38
  {
36
- label: "National id",
39
+ header: "National id",
37
40
  id: "nationalId",
38
- cell: (row) => row.nationalId,
41
+ bodyCell: (row) => row.nationalId,
39
42
  align: "right",
40
43
  width: { autoResizeOnce: true },
41
44
  },
42
45
  {
43
- label: "Day job",
46
+ header: "Day job",
44
47
  id: "dayJob",
45
- cell: (row) => row.dayJob,
48
+ bodyCell: (row) => row.dayJob,
46
49
  },
47
50
  {
48
- label: "Supervisor",
51
+ header: "Supervisor",
49
52
  id: "supervisor",
50
- cell: (row) => row.supervisor,
53
+ bodyCell: (row) => row.supervisor,
51
54
  },
52
55
  {
53
- label: "Date received",
56
+ header: "Date received",
54
57
  id: "dateReceived",
55
- cell: (row) => row.dateReceived,
58
+ bodyCell: (row) => row.dateReceived,
56
59
  },
57
60
  {
58
- label: "Message",
61
+ header: "Message",
59
62
  id: "message",
60
- cell: (row) => row.message,
63
+ bodyCell: (row) => row.message,
61
64
  },
62
65
  {
63
- label: "Age",
66
+ header: "Age",
64
67
  id: "age",
65
- cell: (row) => row.age,
68
+ bodyCell: (row) => row.age,
66
69
  align: "right",
67
70
  width: { autoResizeOnce: true },
68
71
 
@@ -77,9 +80,9 @@ const columnDef_TEST_DATA: ColumnDefinitions<SWData> = [
77
80
  }, */
78
81
  },
79
82
  {
80
- label: "Force sensitive",
83
+ header: "Force sensitive",
81
84
  id: "forceSensitive",
82
- cell: (row) => (
85
+ bodyCell: (row) => (
83
86
  <Tag
84
87
  size="small"
85
88
  variant="moderate"
@@ -90,41 +93,29 @@ const columnDef_TEST_DATA: ColumnDefinitions<SWData> = [
90
93
  align: "center",
91
94
  },
92
95
  {
93
- label: "Home system",
96
+ header: "Home system",
94
97
  id: "homeSystem",
95
- cell: (row) => row.homeSystem,
98
+ bodyCell: (row) => row.homeSystem,
96
99
  },
97
100
  {
98
- label: "Skills",
101
+ header: "Skills",
99
102
  id: "skills",
100
- cell: (row) =>
101
- row.skills.map((skill) => (
102
- <Tag key={skill} size="small" variant="moderate">
103
- {skill}
104
- </Tag>
105
- )),
106
- /* cell: (row) => (
107
- <Bleed marginBlock="space-4" marginInline="space-4">
103
+ bodyCell: (row) => (
104
+ <HStack gap="space-8" wrap={false}>
108
105
  {row.skills.map((skill) => (
109
- <Box
110
- key={skill}
111
- style={{ display: "inline-block" }}
112
- padding="space-4"
113
- >
114
- <Tag size="small" variant="moderate">
115
- {skill}
116
- </Tag>
117
- </Box>
106
+ <Tag key={skill} size="small" variant="moderate">
107
+ {skill}
108
+ </Tag>
118
109
  ))}
119
- </Bleed>
120
- ), */
110
+ </HStack>
111
+ ),
121
112
  },
122
113
  {
123
- label: "Actions",
114
+ header: "Actions",
124
115
  id: "actions",
125
116
  width: { autoResizeOnce: true },
126
- cell: (row) => (
127
- <>
117
+ bodyCell: (row) => (
118
+ <HStack gap="space-8">
128
119
  <Button
129
120
  size="xsmall"
130
121
  variant="secondary"
@@ -133,13 +124,24 @@ const columnDef_TEST_DATA: ColumnDefinitions<SWData> = [
133
124
  >
134
125
  Edit
135
126
  </Button>
136
- <Button
137
- size="xsmall"
138
- variant="secondary"
139
- data-color="neutral"
140
- icon={<MenuElipsisVerticalIcon title="Meny" />}
141
- />
142
- </>
127
+ <ActionMenu>
128
+ <ActionMenu.Trigger>
129
+ <Button
130
+ size="xsmall"
131
+ variant="secondary"
132
+ data-color="neutral"
133
+ icon={<MenuElipsisVerticalIcon title="Menu" />}
134
+ />
135
+ </ActionMenu.Trigger>
136
+ <ActionMenu.Content>
137
+ <ActionMenu.Group label="Actions">
138
+ <ActionMenu.Item>Delete</ActionMenu.Item>
139
+ <ActionMenu.Item>Assign</ActionMenu.Item>
140
+ <ActionMenu.Item>Change status</ActionMenu.Item>
141
+ </ActionMenu.Group>
142
+ </ActionMenu.Content>
143
+ </ActionMenu>
144
+ </HStack>
143
145
  ),
144
146
  },
145
147
  ];
@@ -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";
@@ -55,7 +55,7 @@ type ResizeProps = {
55
55
  * **NB:** Percentage as initial width does not work well with resizing.
56
56
  * @default 140px
57
57
  */
58
- default?: number | string;
58
+ defaultValue?: number | string;
59
59
  /**
60
60
  * Called when the column width changes.
61
61
  * @param width New width in pixels.
@@ -98,7 +98,7 @@ function useTableColumnResize({
98
98
  resizeMin = 40,
99
99
  resizeMax = Infinity,
100
100
  value,
101
- default: defaultProp,
101
+ defaultValue,
102
102
  onChange,
103
103
  thRef,
104
104
  colSpan,
@@ -110,7 +110,7 @@ function useTableColumnResize({
110
110
 
111
111
  const [width, setWidth] = useControllableState({
112
112
  value,
113
- defaultValue: defaultProp ?? (colSpan ?? 1) * 140,
113
+ defaultValue: defaultValue ?? (colSpan ?? 1) * 140,
114
114
  /**
115
115
  * TODO:
116
116
  * - Potential optimization: Only call when width as "stopped" changing, e.g. on mouse up or after a debounce when resizing with keyboard.
@@ -344,18 +344,18 @@ function getAutoColumnWidth(
344
344
  // Find needed width
345
345
  const cellContent = cell.querySelector(
346
346
  ".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
355
- const widthNeededForThisCell =
356
- (cellContentWidth + inlinePadding + marginLeft) / cell.colSpan;
347
+ ) as HTMLElement | null;
348
+
349
+ if (!cellContent) {
350
+ continue;
351
+ }
352
+
353
+ cellContent.style.width = "fit-content";
354
+ const cellContentWidth = cellContent.scrollWidth;
355
+ cellContent.style.removeProperty("width");
356
+ const widthNeededForThisCell = (cellContentWidth + 1) / cell.colSpan;
357
357
  if (widthNeededForThisCell > newColumnWidth) {
358
- newColumnWidth = widthNeededForThisCell;
358
+ newColumnWidth = Math.ceil(widthNeededForThisCell);
359
359
  }
360
360
  }
361
361
 
@@ -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,8 @@
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
+ // TODO: Remove `= unknown` if possible
5
+ type SelectionProps<T = unknown> = {
9
6
  /**
10
7
  * Enables selection of rows.
11
8
  *
@@ -16,57 +13,51 @@ type SelectionProps<T = any> = {
16
13
  *
17
14
  * @default "none"
18
15
  */
19
- selectionMode: "none" | "single" | "multiple";
16
+ mode: "none" | "single" | "multiple";
20
17
  /**
21
- * Controlled selected keys. Should be used in conjunction with `onSelectionChange`.
18
+ * Controlled selected keys. Should be used in conjunction with `onSelectedRowIdsChange`.
22
19
  */
23
- selectedKeys?: SelectedKeysT;
20
+ selectedRowIds?: string[];
24
21
  /**
25
22
  * Default selected keys when using uncontrolled selection. Should not be used together with `selectedKeys`.
26
23
  */
27
- defaultSelectedKeys?: SelectedKeysT;
24
+ defaultSelectedRowIds?: string[];
28
25
  /**
29
26
  * Callback with array of selected keys.
30
27
  */
31
- onSelectionChange?: (keys: SelectedKeysT) => void;
28
+ onSelectedRowIdsChange?: (ids: string[]) => void;
32
29
  /**
33
30
  * Callback to determine if a row should be enabled for selection.
34
31
  *
35
- *
36
32
  * If set to a boolean, it will enable selection for all rows when true, and disable selection for all rows when false.
37
33
  */
38
34
  enableRowSelection?:
39
- | (({ row, id }: { row: T; id: TableRowEntryId }) => boolean)
35
+ | (({ row, id }: { row: T; id: string }) => boolean)
40
36
  | 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
37
  };
47
38
 
48
39
  type NoneSelection = {
49
- selectionMode: "none";
50
- selectedKeys: SelectedKeysT;
40
+ mode: "none";
41
+ selectedKeys: string[];
51
42
  };
52
43
 
53
44
  type SingleSelection = {
54
- selectionMode: "single";
55
- selectedKeys: SelectedKeysT;
56
- getRowRadioProps: (key: TableRowEntryId, row: any) => RadioInputProps;
57
- toggleSelection: (key: TableRowEntryId, row: any) => void;
45
+ mode: "single";
46
+ selectedKeys: string[];
47
+ getRowRadioProps: (key: string, row: any) => RadioInputProps;
48
+ toggleSelection: (key: string, row: any) => void;
58
49
  };
59
50
 
60
51
  type MultipleSelection = {
61
- selectionMode: "multiple";
62
- selectedKeys: SelectedKeysT;
52
+ mode: "multiple";
53
+ selectedKeys: string[];
63
54
  getTheadCheckboxProps: () => CheckboxInputProps;
64
- getRowCheckboxProps: (key: TableRowEntryId, row: any) => CheckboxInputProps;
65
- toggleSelection: (key: TableRowEntryId, row: any) => void;
55
+ getRowCheckboxProps: (key: string, row: any) => CheckboxInputProps;
56
+ toggleSelection: (key: string, row: any) => void;
66
57
  };
67
58
 
68
59
  type TableSelectionBase = {
69
- isRowSelected: (rowId: TableRowEntryId) => boolean;
60
+ isRowSelected: (rowId: string) => boolean;
70
61
  };
71
62
 
72
63
  type TableSelection = TableSelectionBase &
@@ -75,7 +66,6 @@ type TableSelection = TableSelectionBase &
75
66
  export type {
76
67
  MultipleSelection,
77
68
  NoneSelection,
78
- SelectedKeysT,
79
69
  SelectionProps,
80
70
  SingleSelection,
81
71
  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
 
@@ -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 = {
@@ -2,13 +2,13 @@ import { useMemo } from "react";
2
2
  import type {
3
3
  ColumnDefinition,
4
4
  ColumnDefinitions,
5
- } from "../root/DataTable.types";
5
+ } from "../root/DataGridTable.types";
6
6
  import { ACTION_CELL_WIDTH } from "../tr/DataTableTr";
7
7
 
8
8
  type UseColumnOptions = {
9
9
  stickyColumns?: {
10
- start?: "1";
11
- end?: "1";
10
+ start?: 1;
11
+ end?: 1;
12
12
  };
13
13
  hasSelection: boolean;
14
14
  hasDetailsPanel: boolean;
@@ -39,7 +39,7 @@ function useColumnOptions<T>(
39
39
  ): UseColumnOptionsResult<T> {
40
40
  const { stickyColumns, hasSelection, hasDetailsPanel, layout } = options;
41
41
 
42
- const hasStickyStart = stickyColumns?.start === "1";
42
+ const hasStickyStart = stickyColumns?.start === 1;
43
43
 
44
44
  const stickyExpansion = hasStickyStart && hasDetailsPanel;
45
45
  const stickySelection = hasStickyStart && hasSelection;
@@ -53,7 +53,7 @@ function useColumnOptions<T>(
53
53
  return columnDefinitions.map((colDef, index) => {
54
54
  const isFirstSticky = hasStickyStart && index === 0;
55
55
  const isLastSticky =
56
- stickyColumns?.end === "1" && index === columnDefinitions.length - 1;
56
+ stickyColumns?.end === 1 && index === columnDefinitions.length - 1;
57
57
 
58
58
  return {
59
59
  isSticky: isFirstSticky