shadcn.io is not affiliated with official shadcn/ui
Billing Address Dialog Block for React
An invoice page with its billing-address dialog shown open: the form relabels, reorders and revalidates for the United States, the United Kingdom, Germany and Japan, a switch fills the company's address, and the address is printed the way an envelope would carry it.
Installation
Overview
Collect an address that a country's post would accept, with this billing-address dialog for React with Base UI. It opens from an invoice of Ledgerlark, an invoicing tool: the page's header holds an outline Edit billing address Button, and the invoice, its Bill to block, its line items and a total, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The dialog's form follows the country. A Select offers the United States, the United Kingdom, Germany and Japan, and the fields below it relabel (ZIP code, Postcode, Postal code), reorder (the postal code comes first in Germany's pair and in Japan), swap a free text for a list where the country has one (a state, a prefecture), and check the postal code against that country's shape with its own message. A switch fills the form with the company's own address, in its country, and locks it; beside the fields the address is printed as an envelope in that country would carry it, and Save address, the only Shine Button, reprints the invoice behind the dialog in the new format. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same fields and the same state. For invoices, checkouts, billing settings and any form that takes a postal address.
FAQ
Why is the dialog already open, and what do I keep?
So you can see it without a click. On load the dialog is a copy drawn in place over the page: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Edit billing address button opens the real Dialog, modal, with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same AddressFields component and share the block's state, so what was typed in the copy is there in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How do I add a country?
Add one object to COUNTRIES: its cells in the order that country writes an address (each with a label, an autofill token, whether it is required, and whether it spans the form), its postal pattern and the sentence to show when it doesn't fit, and its region options if the country has a list. Then say how it prints in printedOf. The four here are only examples of the idea: their patterns are typed in the file and check a code's shape, not that it exists, because nothing is looked up in a postal database. Check the real rules of every country you sell to, or use a service that knows them.
What does Save address check?
Every field the country marks as required, in the order they appear, and the postal code's shape, each with its own sentence under its field; focus goes to the first problem and the dialog stays open. Optional fields (a second address line, a county) are never flagged. Once a message shows it follows your typing and clears as soon as that field is right. Changing the country starts the region again and checks the postal code again if it had been flagged, since another country means another shape.
What does Same as company address do?
It fills the whole form with the company's address, which is in another country than the invoice's, so the country list changes too, then locks every field so it can't drift from it. Turn it off and the fields open again with those values to edit. The company address is a constant in the file; in your app read it from the account.
Does it save the address anywhere?
No. Save address keeps the address in the block's state and reprints the invoice behind the dialog, and the polite status message says nothing was stored or sent. In your app post the fields to your server in save, show its refusals in the field they belong to, and update the invoice from the response, keeping the dialog open until it succeeds.
Is it accessible from the keyboard?
Yes. The real dialog is named by its title and described by its sentence, focus starts inside it and stays there until it closes, and Escape, Cancel and the close button all return focus to Edit billing address. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. The state and prefecture lists are native selects, so a phone shows its own picker; each field's message is tied to it with aria-describedby, the printed address is a labelled address element, and one polite status message reports what changed. The copy shown on load moves no focus; Escape inside it, Cancel and its close button close it and put focus on the header button.
Related
- Pro
Address Autocomplete Dialog
Pickers and searchA meal-kit delivery page with its address dialog shown open: typing filters eight addresses of an invented town into an inline list you can arrow through, a choice fills four editable fields, and Enter it manually offers the same four, empty.
- Pro
Add Card Dialog
Payments and plansA transit wallet's payment methods page with its add-card dialog shown open: a card drawn in greys that fills in as you type, a number that groups itself and names its network, checks on the number, expiry and code, and an Add card button that keeps only the last four digits.
- Pro
Tax Details Billing
Payment and invoicesBilling address and tax ID in app settings: a form that checks the postal code and tax number against the country, an optional invoice note, and a live preview of the invoice header.
- Pro
Add to Cart Dialog
Payments and plansA stool shop's product page with its add-to-cart dialog shown open: two heights that redraw the stool and move the price, three finishes with a sentence each, a quantity that stops at the stock left, and a total that follows the choices.
- Pro
Apply Coupon Dialog
Payments and plansA cookware shop's basket with its promo-code dialog shown open: one field that judges five typed codes with five different answers, applied codes kept as removable chips, and a summary that is worked out again after every change.
- Pro
Gift Card Dialog
Payments and plansA café's gift cards page with its builder dialog shown open: a card drawn in greys that reads as you build it, preset or custom amounts, three printed patterns, a recipient and a message, and delivery now or on a day picked in an inline calendar.