Badge
A small dot or a short count or label, placed on an anchor with BadgedBox.
import { Badge, BadgedBox } from '@windmorph/react';Keyboard
None. A badge has no keyboard interaction of its own; it rides on whatever it is placed on, and that element's keys apply.
Screen reader
- Role
- No role of its own: a
spanread as part of the text around it. - Accessible name
- Not named on its own; its text joins the name of the element it sits in ("Inbox 5").
- States announced
- A large badge reads its count or label; a small dot reads "New notification" (
labels.newNotification).labelreplaces either ("3 unread messages"), and the visible text is then hidden (aria-hidden).
- On a
NavigationBarorNavigationRailitem, pass the badge through the item'sbadgeprop, not aBadgedBoxin its icon: the item reads it after its name, as M3 asks. A count reads itself (orbadgeLabel, "3 unread messages"), and a dot reads "New notification". - Counts are formatted for the locale and capped at
max(999 by default, so "999+"); a count stays left to right in right-to-left layouts, so it never reads as "+999".
Focus
None. A badge is never focusable; focus goes to the element it is placed on.
Touch target
None. A badge takes no presses; the touch target is that of the element it is placed on.
Motion
None. A badge has no motion of its own; it appears and disappears without animating.
What you need to do
- An anchor with its own
aria-label(anIconButton, say) hides the badge's text, so put the badge's meaning in that label: "Messages, 12 unread". - Pass
labelwhen the count alone is unclear ("3 unread messages"), andlabels.newNotificationto translate the dot's announcement. - Keep the default
errorcolours, or keep any custom colours at a 3:1 contrast or more against what surrounds the badge. - Remove an unread badge once its destination is opened; the badge doesn't hide itself.
- A bare SVG anchor in
BadgedBoxgets the 24px icon size; wrap it in a sized element for other sizes.