Skip to content

Displays a compact inline status counter or label. It sits in the flow — for a bubble or dot anchored OVER another element, use BbIndicator (includes the co-located BbBadgeButton export).

import { BbBadge } from 'bitboss-ui';

On this page

Props

NameDescription
append:icon Type: string

Icon rendered after the label. On a clearable badge it shares the trailing slot with the clear button: the icon shows at rest and the clear button reveals over it on hover/focus.

See example
clearable Type: booleanDefaultfalse

Renders a trailing clear button and emits click:clear when pressed — turns the badge into a dismissible token (the pattern formerly served by BbChip).

Opt-in, which is the one thing that changed on the way from BbChip: a chip was removable unless told otherwise. Swapping the tag straight across loses the × with no error.

See example
clearableLabel Type: string

Accessible name of the clear button, whole: set, it is the name on any body ("Remove the filter Deleted"). Rarely needed: unset, the name is composed from the localized badge.clearLabel verb and the badge text ("Remove Italy"), or the verb alone when a BbBadgeButton owns the body.

Set it when a BbBadgeButton owns the body: the × is then named by the bare verb ("Remove"), so the two controls do not both read the label, and "Remove priority filter" says what goes.

See example
iconOnly Type: Responsive<boolean>

Shows only the badge's icon (prepend:icon when it has both); the label (text or the slot) stays its visually hidden accessible name, so always write it. true, or per breakpoint: { default: true, md: false }.

Keep writing the label (text or the slot): it becomes the accessible name. An icon-only badge with no label is an error for npx bitboss-ui check and the ESLint rule require-accessible-name.

See example
loading Type: booleanDefaultfalse

Shows a spinner in place of the leftmost icon (prepend:icon; the append:icon when it is the only one; else the leading slot), as BbButton does, with a hidden loading announcement.

Also makes a slotted BbBadgeButton inert: clicks do not reach your @click, a link does not navigate, and the body leaves the tab order until loading clears.

See example
prepend:icon Type: string

Icon rendered before the label.

See example
pt Type: (PtCompoundOf<"", { readonly parts: readonly ["root", "icon", "spinner", "text", "clear"]; readonly states: readonly ["activeLink", "exactActiveLink", "loading"]; readonly wide: readonly ["activeLink", "exactActiveLink", "loading"]; readonly except: { readonly icon: readonly ["loading"]; }; readonly variant: { readonly names: readonly ["primary", "secondary", "destructive", "outline"]; readonly option: "badgeVariants"; }; }> & { text?: PtValue | undefined; root?: PtValue | undefined; icon?: PtValue | undefined; spinner?: PtValue | undefined; clear?: PtValue | undefined; "text:loading"?: PtValue | undefined; "text:activeLink"?: PtValue | undefined; "text:exactActiveLink"?: PtValue | undefined; "root:loading"?: PtValue | undefined; "root:activeLink"?: PtValue | undefined; "root:exactActiveLink"?: PtValue | undefined; "icon:activeLink"?: PtValue | undefined; "icon:exactActiveLink"?: PtValue | undefined; "spinner:loading"?: PtValue | undefined; "spinner:activeLink"?: PtValue | undefined; "spinner:exactActiveLink"?: PtValue | undefined; "clear:loading"?: PtValue | undefined; "clear:activeLink"?: PtValue | undefined; "clear:exactActiveLink"?: PtValue | undefined; } & { "text:outline"?: PtValue | undefined; "text:primary"?: PtValue | undefined; "text:destructive"?: PtValue | undefined; "root:outline"?: PtValue | undefined; "root:primary"?: PtValue | undefined; "root:destructive"?: PtValue | undefined; "icon:outline"?: PtValue | undefined; "icon:primary"?: PtValue | undefined; "icon:destructive"?: PtValue | undefined; "text:secondary"?: PtValue | undefined; "root:secondary"?: PtValue | undefined; "icon:secondary"?: PtValue | undefined; "spinner:outline"?: PtValue | undefined; "spinner:primary"?: PtValue | undefined; "spinner:destructive"?: PtValue | undefined; "spinner:secondary"?: PtValue | undefined; "clear:outline"?: PtValue | undefined; "clear:primary"?: PtValue | undefined; "clear:destructive"?: PtValue | undefined; "clear:secondary"?: PtValue | undefined; })

Passthrough, object form: { icon: '…', 'icon:loading': '…' } — the same keys as the pt:* attributes without the prefix. Parts: root, icon, spinner, text, clear. States: loading and the registered variants (an app's own included).

pt:<part> Type: PtValue

Passthrough, attribute form: one attribute per part, pt:<part>, and per part and state, pt:<part>:<state>. Parts: clear, icon, root, spinner, text. States: activeLink, destructive, exactActiveLink, loading, outline, primary, secondary.

See example
size Type: Responsive<keyof Sizes>Default'md'

Preset size of the badge: one size, or per breakpoint ({ default: 'sm', lg: 'md' }), as on BbButton.

Pick it from the control standing next to the badge, not from a remembered constant: lg matches an xs button, xl a sm one, 2xl an md one. The default md is sized for running text.

See example
text Type: string

The label, when the default slot is empty (the slot wins), as on BbButton.

variant Type: BadgeVariantTypeDefault'primary'

Visual variant: primary, secondary, destructive, or outline. Status colours are a registration (vite plugin components.BbBadge.variants, the soft-* palette in design-language.md) styled as .bb-badge--<variant>. 'none' renders no variant class: set --bg / --fg on the element.

See example

Events

NameDescription
click:clear Type: (event: MouseEvent): void

Emitted when the clear button is pressed (only rendered when clearable).

Fires when the clear button is pressed. The badge is controlled and removes nothing on its own — drop the item from your own state in the handler. Pressing the × never fires a slotted BbBadgeButton.

See example

Slots

The listed properties are the ones exposed to the slot scope.

NameDescription
append:icon Type: BbBadgeIconSlotProps

The trailing icon, replacing append:icon; inside the icon part.

default Type: object

The badge's label content. With icon-only this becomes the visually hidden accessible label. Render a BbBadgeButton here to make the badge body interactive (the wrapper stays a passive <span>).

A BbBadgeButton here must be a direct child: wrapped in anything else the badge keeps its body and you get a duplicated label. One per badge — there is only one body to take over.

See example
prepend:icon Type: BbBadgeIconSlotProps

The leading icon, replacing prepend:icon (the one icon-only shows). Renders inside the icon part: pt:icon, --icon-size and the loading spinner apply.

Renamed and removed

Names from v2 and from earlier 3.0 betas that no longer work, and what to write instead.

  • contentremovedfails silently
  • iconprepend:iconfails silently

    An icon-only badge: prepend:icon="…" icon-only; the default slot stays its hidden label.

  • sloticonprepend:iconfails silently

    An icon-only badge: #prepend:icon with icon-only.