shadcn.io is not affiliated with official shadcn/ui
Button Group examples · Badges
Cart Button Button Group for React
A cart button with an item count badge on its corner, grouped with the cart total or the number of items.
The cart control in a store header. A small round Badge sits on the button's top corner with the item count, and ButtonGroupText beside it shows the total, $127.50, or the count in words. The second row is the icon-only version, named with an aria-label.
Preview
Installation
FAQ
How does the badge sit on the corner?
The Button has relative, and the Badge has absolute -end-2 -top-1. The badge is pill with size="sm", a small round count. -end-2 follows the reading direction, so it moves to the left corner in a right-to-left layout.
What is ButtonGroupText?
A non-interactive part of the group that shares its border, used here for $127.50 and 5 items. It's text, not a button, so it doesn't take focus.
How is the icon-only cart button named?
It has aria-label="Cart, 5 items", which replaces the badge's 5 as the button's name. The first button is read as Cart and 3.
Are the counts live?
No. 3, 5 and $127.50 are written into the file. Pass your cart's count and total as the badge's and the text's children, and keep the aria-label in step.
Related
- Notifications Button Button GroupTwo bell buttons joined in a group, each
- Messages and Followers Button GroupA Messages button with a red unread
- Like with Count Button GroupA like button joined to its count, shown
- Circular Badge with Count (Standard)A circular default badge showing a number
- Standard DialogA share dialog with a read-only link, a
- Bulk Actions Button GroupA row of bulk actions, Select All