DeleteButton

Lets the user delete the current record.

Installation

pnpm dlx shadcn@latest add @shadmin/delete-button

Usage

import { DeleteButton, Edit } from "@/components/admin";
 
const PostEdit = () => <Edit actions={<DeleteButton />}>...</Edit>;

By default, it reads the resource from ResourceContext and record from RecordContext.

Upon success, the button redirects to the list view, and notifies the user with the key resources.<resource>.notifications.deleted (fallback ra.notification.deleted).

Named exports

<DeleteButton> ships with two named variants for callers who want a specific behavior without setting mutationMode:

ExportBehavior
DeleteButtonDispatches based on mutationMode (default: undoable)
DeleteWithUndoButtonFires immediately, shows undo notification
DeleteWithConfirmButtonOpens a confirmation dialog, fires on confirm
import { DeleteWithConfirmButton, DeleteWithUndoButton } from '@/components/admin';
 
// Opens a confirm dialog
<DeleteWithConfirmButton />
 
// Fires immediately with undo
<DeleteWithUndoButton />

Props

PropRequiredTypeDefaultDescription
classNameOptionalstringdestructive stylesAdditional classes
labelOptionalstringi18n computedi18n key / custom label (includes record name)
mutationModeOptional"undoable" | "optimistic" | "pessimistic"undoableWhen to apply the mutation
mutationOptionsOptionalUseDeleteOptions-Mutation options (onSuccess, etc.)
redirectOptionalRedirectionSideEffectlistWhere to redirect after delete
sizeOptional"default" | "sm" | "lg" | "icon"-Size variant
successMessageOptionalstring-Custom success i18n key
variantOptional"default" | "destructive" | "outline" | "secondary" | "ghost" | "link"outlineButton style

label

By default, the label is computed from the ra.action.delete translation key, which reads "Delete".

You can customize the label for a specific resource by adding a resources.{resource}.action.delete key to your translation messages. It receives %{name} (singular resource name) and %{recordRepresentation} (string representation of the current record):

const messages = {
  resources: {
    posts: {
      action: {
        delete: "Remove %{recordRepresentation}",
      },
    },
  },
};

You can also pass a custom string or translation key directly via the label prop:

<DeleteButton label="Remove" />
<DeleteButton label="resources.posts.action.delete" />

ref

Forwards a ref to the underlying <Button> element.

import { useRef } from "react";
 
const ref = useRef<HTMLButtonElement>(null);
<DeleteButton ref={ref} />;

Soft Delete

If your data provider supports soft delete (see Soft Delete Features), you can use an alternative SoftDeleteButton that performs a soft delete instead of a permanent delete.

You can then choose to either restore the record with a RestoreButton, or delete it permanently with a DeletePermanentlyButton.