BulkUpdateButton

Updates all selected records in a list with a fixed data payload.

Installation

pnpm dlx shadcn@latest add @shadmin/bulk-update-button

Usage

Use inside the bulkActionsButtons prop of a <DataTable> (which provides the necessary ListContext):

import { BulkUpdateButton, DataTable, List } from "@/components/admin";
 
const ResetViewsButton = () => (
  <BulkUpdateButton label="Reset Views" data={{ views: 0 }} />
);
 
export const PostList = () => (
  <List>
    <DataTable bulkActionsButtons={<ResetViewsButton />}>...</DataTable>
  </List>
);

Defaults to mutationMode="undoable" — the update fires immediately and a notification with an undo button is shown. Pass mutationMode="pessimistic" (or use <BulkUpdateWithConfirmButton>) to ask the user to confirm before firing the mutation.

Named exports

ExportBehavior
BulkUpdateButtonDispatches to one of the variants below based on mutationMode (default: undoable)
BulkUpdateWithUndoButtonFires immediately, shows undo notification
BulkUpdateWithConfirmButtonOpens a confirmation dialog, fires on confirm

Props

PropRequiredTypeDefaultDescription
dataRequiredobject-Object passed to dataProvider.updateMany()
classNameOptionalstring-Additional classes
confirmContentOptionalReactNodera.message.bulk_update_contentConfirmation dialog body (Confirm variant)
confirmTitleOptionalReactNodera.message.bulk_update_titleConfirmation dialog title (Confirm variant)
iconOptionalReactNodeRefreshCw iconCustom icon
labelOptionalstringra.action.updatei18n key / label
mutationModeOptional"undoable" | "optimistic" | "pessimistic"undoableWhen to apply the mutation
mutationOptionsOptionalUseUpdateManyOptions-Forwarded to useUpdateMany
resourceOptionalstringFrom contextResource name
successMessageOptionalstring-Custom success i18n key
variantOptionalshadcn button variantoutlineButton style

icon

Replaces the default <RefreshCw /> shown alongside the label. Pass any React node — typically another lucide-react icon.

import { RotateCcw } from "lucide-react";
 
<BulkUpdateButton
  icon={<RotateCcw />}
  label="Reset Views"
  data={{ views: 0 }}
/>;

mutationMode

{
  /* Default: optimistic update with undo notification */
}
<BulkUpdateButton label="Reset Views" data={{ views: 0 }} />;
 
{
  /* Equivalent */
}
<BulkUpdateWithUndoButton label="Reset Views" data={{ views: 0 }} />;
 
{
  /* Pessimistic with confirmation dialog */
}
<BulkUpdateButton
  label="Reset Views"
  data={{ views: 0 }}
  mutationMode="pessimistic"
/>;
 
{
  /* Equivalent */
}
<BulkUpdateWithConfirmButton label="Reset Views" data={{ views: 0 }} />;

ref

Forwards a ref to the underlying <Button> element.

import { useRef } from "react";
 
const ref = useRef<HTMLButtonElement>(null);
<BulkUpdateButton ref={ref} label="Reset Views" data={{ views: 0 }} />;

label

The default label is the translation of ra.action.update. Override per-resource via the resources.{resource}.action.update key, or pass label directly:

<BulkUpdateButton label="Reset Views" data={{ views: 0 }} />