Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Split Bill Dialog Block for React

A group-dining app's open check with a dialog that splits it by item: each item has a row of initials that toggle who shared it, and beside them what each person pays, reconciled to the cent, with the tax and tip spread fairly.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Let a table settle the check item by item, with this split-bill dialog for React with Base UI. It opens from the check of table 6 in Forkwick, a group-dining app: the page's header holds an outline Split the check Button, and the check itself, item lines with dotted leaders, the tax, tip and total, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The dialog has the six items at the start, each with a row of four initials, a Toggle Group of the people who shared it, and at the end what each person pays: a stacked bar of the four shares, a name and an amount per person with the breakdown under it, and one line that says the shares add up to the check. An item is cut among its sharers in whole cents, tax at 8% and tip at 18% are spread by what each person ordered, and until every item has someone the dialog lists what is unassigned and Save split, the only Shine Button, waits. Saving writes Split 4 ways and each amount on the drawn check. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same toggles and the same state. For restaurants, group trips, shared houses and any bill that is paid by several people.

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 Split the check 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 SplitFields component and share the block's state, so an item shared in the copy is shared 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 the shares reconcile to the cent?

Everything is whole cents. Each item is cut among the people who shared it with evenParts: every sharer gets the same whole number of cents and the odd cents go to the first sharers in table order. Tax and tip are each worked out once, from the items that have someone, and rounded to a cent; then apportion spreads each of them over the people in proportion to what they ordered, with the largest-remainder rule, so the parts add up to the total exactly. A person's total is items plus their tax plus their tip, and the line under the list adds the four shares back up to prove they match the check.

What if an item has nobody on it?

The totals count only the items that have someone, and the line under them lists the rest ("Unassigned: Fries $6.00", two items by name, more as a count and a sum). Save split stays on the page with a quiet look and says it is waiting to anyone who points at it; pressing it names the first item that still needs a person, moves focus to that item's initials and speaks it in the status message. Clear every initial in a row to unassign an item again.

How does it fit on a phone?

The list scrolls and the totals become a strip pinned above the actions: four names and their amounts and the unassigned line, so you see what each toggle does without scrolling. The per-person breakdown and the proof line are kept for wider screens, and the real dialog keeps the Dialog's own phone layout, a sheet stuck to the bottom of the screen.

Does it charge anyone, and how do I wire it up?

No. Save split keeps the shares in local state, writes Split 4 ways and each amount on the drawn check behind the dialog, closes, and says in a polite status message that nothing was shared or charged. In your app send the assignments to your server in save and let the server do the cents arithmetic too, since it owns the check; show a refusal in the status message with the dialog still open. The people, items, tax and tip rates are typed constants at the top of the file.

Is it accessible from the keyboard?

Yes. The real dialog is named by its title and described by its sentence, focus starts at the first row of initials and stays inside until it closes, and Escape, Cancel and the close button all return focus to Split the check. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. Each row is a group you move through with the arrow keys, named for its item and its sharers ("Burrata shared by Maya, Jo"), and each initial is a toggle named with the person's name. 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.

  • Pro

    Split Payment Dialog

    Payments and plans

    A point-of-sale ticket with its split-payment dialog shown open: methods added from a select, an amount for each, a running total with a bar by method, and Pay held back until the remainder is exactly zero.

  • Pro

    Tip Calculator Dialog

    Drawers and popovers

    A café terminal's pay screen with a tip popover shown open beside it: the bill, a tip of 15, 18, 20 or 25 percent or your own, how many people share it, a switch that rounds each share up to a dollar, and four lines that add it up.

  • Pro

    Quick Transfer Dialog

    Payments and plans

    A payments app's account home with its send-money dialog shown open: five recent people in a scrolling row, an amount with quick chips, a note, the fee and balance after, and a review step before Send.

  • Pro

    Add Card Dialog

    Payments and plans

    A 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

    Add to Cart Dialog

    Payments and plans

    A 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 plans

    A 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.