shadcn.io is not affiliated with official shadcn/ui
Button Group examples · Badges
Messages and Followers Button Group for React
A Messages button with a red unread badge, and Follow and Following buttons joined to a follower count.
Profile header controls. Messages carries a destructive Badge with the unread count on its corner. Follow and Following each sit beside a ButtonGroupText with the follower count; the Following button is filled and pressed, so the state is visible and announced.
Preview
Installation
FAQ
How is the unread badge placed?
The Button has relative, and the Badge has absolute -end-1 -top-1, pill, size="sm" and variant="destructive". The logical -end-1 keeps it on the trailing corner in either reading direction.
How does Following differ from Follow?
It uses the default variant instead of outline, the label Following, and aria-pressed. Its count text is 2.4k instead of 2.4k followers.
Does Follow switch to Following?
No. The two groups are static samples. Keep a following flag and switch the variant, label and aria-pressed from it.
How is the unread count announced?
The badge text is inside the button, so it is read as Messages and 8. Set an aria-label such as Messages, 8 unread when you want a full phrase.
What about a large unread count?
The badge widens with its text. Cap it before you pass it, such as 99+, as the Notifications Button example does.
Related
- Notifications Button Button GroupTwo bell buttons joined in a group, each
- Like with Count Button GroupA like button joined to its count, shown
- Cart Button Button GroupA cart button with an item count badge on
- Circular Badge with Count (Destructive)A circular destructive badge showing a
- Social Actions Button GroupLike, Comment and Share in one button
- Bulk Actions Button GroupA row of bulk actions, Select All