Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DatatableV2): add option to disable selection toolbar #1170

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/DatatableV2/Datatable.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export interface ParsedDatatableOptions<D>
enableRowActions?: DatatableOptions<D>['enableRowActions'];
enableRowsPerPage?: DatatableOptions<D>['enableRowsPerPage'];
enableSelectAll?: DatatableOptions<D>['enableSelectAll'];
enableSelectionToolbar?: DatatableOptions<D>['enableSelectionToolbar'];
enableTopToolbar?: DatatableOptions<D>['enableTopToolbar'];
initialState?: DatatableOptions<D>['initialState'];
onShowColumnSettings?: DatatableOptions<D>['onShowColumnSettings'];
Expand Down Expand Up @@ -452,6 +453,14 @@ export interface DatatableOptions<D>
* @default true
*/
enableSelectAll?: boolean;
/**
* Enables/disables the selection toolbar with the batch action buttons. If this is set to `false`
* consumers has to control the selection state on their own as the Datatable doesn't provide other
* way how to access the interal state.
*
* @default true
*/
enableSelectionToolbar?: boolean;
/**
* Enables/disables table sorting
*
Expand Down
2 changes: 2 additions & 0 deletions src/components/DatatableV2/hooks/useOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useOptions = <D>({
enableRowSelection = true,
enableRowsPerPage = false,
enableSelectAll = true,
enableSelectionToolbar = true,
enableSorting = true,
enableSortingRemoval = true,
enableTopToolbar = true,
Expand Down Expand Up @@ -80,6 +81,7 @@ export const useOptions = <D>({
enableRowSelection,
enableRowsPerPage,
enableSelectAll,
enableSelectionToolbar,
enableSorting,
enableSortingRemoval,
enableTopToolbar,
Expand Down
7 changes: 7 additions & 0 deletions src/components/DatatableV2/stories/Selection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ RowSelectionActions.parameters = {
screenshot: { skip: false },
};

export const DisabledSelectionToolbar: Story = Template.bind({});
DisabledSelectionToolbar.args = {
...SelectionEnabled.args,
initialState: RowSelectionActions.args.initialState,
enableSelectionToolbar: false,
};

export const SelectionManagedState: Story = (args) => {
const [rowSelection, setRowSelection] = useState<RowSelectionState>({
'e23968c3-3f19-44b2-aee9-c4a1d7c326ee': true,
Expand Down
3 changes: 2 additions & 1 deletion src/components/DatatableV2/table/TableSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const TableSurface = <D,>({ table }: { table: DatatableInstance<D> }) => {
{table.options.enableTopToolbar && <TopToolbar table={table} />}
<Table table={table} />
</Surface>
{table.options.enableRowSelection && <Selection table={table} />}
{table.options.enableRowSelection &&
table.options.enableSelectionToolbar && <Selection table={table} />}
{table.options.enablePagination &&
table.getRowModel().rows.length > 0 && <Pagination table={table} />}
</DatatableRoot>
Expand Down
Loading