From 01b0e5adbb8157fc2fcbd566c24d40206fab577c Mon Sep 17 00:00:00 2001 From: IzumiSy Date: Tue, 13 Oct 2026 14:19:38 +0900 Subject: [PATCH 1/2] feat(data-table): add controlled and default row selection --- .changeset/clear-kites-select.md | 13 + docs-manifest.json | 9 +- .../components/data-table.docs.outline.md | 46 ++- docs/components/data-table.md | 46 ++- .../core/src/components/data-table/index.ts | 1 + .../data-table/row-selection.test.tsx | 310 ++++++++++++++++++ .../core/src/components/data-table/types.ts | 29 +- .../components/data-table/use-data-table.ts | 111 +++++-- packages/core/src/index.ts | 1 + 9 files changed, 521 insertions(+), 45 deletions(-) create mode 100644 .changeset/clear-kites-select.md create mode 100644 packages/core/src/components/data-table/row-selection.test.tsx diff --git a/.changeset/clear-kites-select.md b/.changeset/clear-kites-select.md new file mode 100644 index 000000000..a810261c6 --- /dev/null +++ b/.changeset/clear-kites-select.md @@ -0,0 +1,13 @@ +--- +"@tailor-platform/app-shell": minor +--- + +Add controlled and uncontrolled row selection through `useDataTable`'s `rowSelection` option. Pass `selectedIds` with `onChange` to control selection, or `defaultSelectedIds` to initialize table-owned selection. The existing `onSelectionChange` callback remains supported. + +```tsx +const table = useDataTable({ + columns, + data, + rowSelection: { selectedIds, onChange: setSelectedIds }, +}); +``` diff --git a/docs-manifest.json b/docs-manifest.json index 06036a7e7..b37762a98 100644 --- a/docs-manifest.json +++ b/docs-manifest.json @@ -421,6 +421,7 @@ "PageInfo", "PaginationVariables", "RowAction", + "RowSelectionOptions", "SelectOption", "SelectionAction", "SelectionActionHelpers", @@ -446,10 +447,10 @@ "withURLCollectionState" ], "hashes": { - "typeSurface": "fe43108015be4a00", - "outline": "dc0b82256114191b", + "typeSurface": "6420153668673350", + "outline": "f0023a7c1ef0c535", "snapshot": null, - "outputMd": "3e8474e4d1437c91", + "outputMd": "af7a5f615cc91888", "examples": null } }, @@ -1693,7 +1694,7 @@ "packages/core/skills/app-shell-patterns/references/components/combobox.md": "dfb775c7c4307409", "packages/core/skills/app-shell-patterns/references/components/command-palette.md": "7e5bc675a593791a", "packages/core/skills/app-shell-patterns/references/components/csv-importer.md": "53d3c795ca21b9dc", - "packages/core/skills/app-shell-patterns/references/components/data-table.md": "3e8474e4d1437c91", + "packages/core/skills/app-shell-patterns/references/components/data-table.md": "af7a5f615cc91888", "packages/core/skills/app-shell-patterns/references/components/date-picker.md": "f39002ad79625dc4", "packages/core/skills/app-shell-patterns/references/components/default-header.md": "375e55f4b12fa2be", "packages/core/skills/app-shell-patterns/references/components/default-sidebar.md": "3422388a0cc78571", diff --git a/docs-src/components/data-table.docs.outline.md b/docs-src/components/data-table.docs.outline.md index 8e4b23a06..d33737243 100644 --- a/docs-src/components/data-table.docs.outline.md +++ b/docs-src/components/data-table.docs.outline.md @@ -30,6 +30,7 @@ import { type DataTablePaginationProps, type DataTableAction, type RowAction, + type RowSelectionOptions, type SelectionAction, type UseDataTableOptions, type UseDataTableReturn, @@ -228,7 +229,7 @@ By default `DataTable.Filters` renders the active filter chips plus the **Add fi | Rows selected and `total` is not provided | `Y row(s) selected` | | No selection enabled and no `total` | _(nothing displayed)_ | -Row selection is enabled by providing `onSelectionChange` or `selectionActions` to `useDataTable`. The `total` value comes from `DataTableData.total`. While the footer shows the bulk-action bar (see [Selection actions](#selection-actions)), the bar owns the selection count and this text is omitted. +Row selection is enabled by providing `rowSelection`, `onSelectionChange`, or a non-empty `selectionActions` array to `useDataTable`. The `total` value comes from `DataTableData.total`. While the footer shows the bulk-action bar (see [Selection actions](#selection-actions)), the bar owns the selection count and this text is omitted. When pagination changes page or page size, `DataTable.Table` resets its own scroll container to the top automatically. That applies whether navigation comes from the built-in `DataTable.Pagination` or from custom controls using the same table context. @@ -376,9 +377,45 @@ The trigger is a native `