Skip to content

[TypeScript] Fix <DeleteWithConfirmButton> does not accept the component prop - #11386

Open
bipul724 wants to merge 1 commit into
marmelab:masterfrom
bipul724:fix/9389-delete-button-component
Open

bipul724 wants to merge 1 commit into
marmelab:masterfrom
bipul724:fix/9389-delete-button-component

Conversation

@bipul724

@bipul724 bipul724 commented Sep 26, 2026 •

Copy link
Copy Markdown

Problem

Closes #9389. <DeleteWithConfirmButton component="a" /> fails to typecheck (Type '"a"' is not assignable to type '"button"'), although react-admin's <Button> and MUI's <Button> both accept a custom component. DeleteWithConfirmButtonProps extended the non-generic ButtonProps, which defaults the root component to 'button'.

Solution

  • Make DeleteWithConfirmButton generic over its root component, following the same pattern as <Button> (forwardRef cast to a generic component type).
  • DeleteWithConfirmButtonProps becomes a type alias with a new optional RootComponent type parameter (defaulting to 'button'), since an interface can't extend a type depending on a generic parameter. Existing usages are unaffected.
  • DeleteButton now has an explicit type annotation (same style as Datagrid and Logout). Without it, the declaration emit fails with TS4023, because its inferred type expands the new type alias down to Button's non-exported Props. The emitted declaration resolves to the same type as before, so the public API is unchanged.

` (also mentioned in the issue) is intentionally typed like , and the other navigation buttons, with a LinkBase root since it navigates via to, so I left it unchanged.

How To Test

  • Storybook: ra-ui-materialui/button/DeleteWithConfirmButton → With Component
  • yarn test-unit packages/ra-ui-materialui/src/button/DeleteWithConfirmButton.spec.tsx packages/ra-ui-materialui/src/button/DeleteButton.spec.tsx
  • yarn typecheck

Additional Checks

  • The PR targets master for a bugfix
  • The PR includes unit tests
  • The PR includes one or several stories
  • The documentation is up to date (types-only change, no doc update needed)

Copilot AI lite review requested due to automatic review settings September 26, 2026 22:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The component property is not definable in <DeleteWithConfirmButton>

2 participants