Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Dialog examples · Standard

Checkout Dialog for React

A checkout dialog with a billing cycle choice, card details and a total that follows the chosen cycle.

Framework
UI library

A checkout that spans several pages loses people. This React dialog puts the billing cycle and the payment details in one place, and the Complete Purchase button shows the price for the cycle picked. It's shadcn.io's Dialog on Base UI with a Radio Group of choice cards and Field inputs.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does the price follow the billing cycle?

The radio group is controlled, and the button reads the total for the selected cycle from a static list. Monthly shows $29, Yearly $290.

Why radio cards instead of buttons?

A billing cycle is one choice out of several, which is what a radio group is: arrow keys move between the options and screen readers announce the selection. Each card is a FieldLabel around a Field with the title, the price and the RadioGroupItem.

How is the yearly saving shown?

With a Badge using variant="success" inside the Yearly card, so it follows the theme's success color.

When should I validate the card fields?

When each field loses focus, with the error in a FieldError, and keep Complete Purchase disabled until everything is valid. Better still, use your payment provider's hosted fields.

What if the payment fails?

Keep the dialog open, show the error above the buttons and leave the fields filled so people can fix one and retry.

What happens after a successful payment?

Close the dialog from your handler and confirm with a toast or a receipt page. Pass open and update it in onOpenChange, which receives the new boolean.