HextaUI

Button: Error details

Pass a function to errorLabel to show the rejection reason. While the pointer or keyboard focus stays on the button, the error stays on screen.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonErrorDetails() {
  return (
    <Button
      feedback
      variant="outline"
      errorLabel={(error) =>
        error instanceof Error ? error.message : "Failed"
      }
      onClick={async () => {
        await new Promise((resolve) => setTimeout(resolve, 700))
        throw new Error("Card declined")
      }}
    >
      Pay $24
    </Button>
  )
}

This adds the example as components/examples/button/error-details.tsx, together with the Button component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/button-error-details.json

To add only the component, follow the Button installation.

Props in this example

The Button props this example sets, from the API reference.

PropTypeDefault
variant
"default" | "outline" | "secondary" | "ghost" | "ghost-destructive" | "destructive" | "link""default"
feedbackTrack the promise returned from onClick and show its status.
booleanfalse
onClickReturn a promise to drive feedback.
(event) => unknown–
errorLabel
ReactNode | (error: unknown) => ReactNode"Failed"

Every prop is in the Button API reference.

See them all, with keyboard support and accessibility notes, on the Button page.