Skip to content

Badge

A small status pill. The text is not optional.

Preview

Code

The three render the same class names, the same ARIA and the same data attributes. That is checked when this site builds: a class in any of these samples that neither the markup contract nor the shipped stylesheet defines fails the build.

<span class="wsu-badge wsu-badge--success">Open</span>
<span class="wsu-badge wsu-badge--danger">Closed</span>
<span class="wsu-badge wsu-badge--accent">Waitlist</span>

Why it works this way

  • A badge is usually the only thing in its table cell, and its color is usually the only thing separating Open from Closed. A badge with no label is a colored dot, which is information carried by color alone.
  • srLabel on the Blade component adds the context a sighted reader gets from the column header and a screen reader user, hearing the cell on its own, does not.

Accessibility

  • Text plus color, never color alone (1.4.1).
  • Every variant meets its declared contrast against the surface it sits on.

Success criteria in brackets refer to WCAG 2.2. Every one of them is checked by axe-core in both themes at three viewport widths before this page can be published. See Accessibility for what the gates are.

Props

Blade

AttributeDefaultWhat it does
variant'neutral'neutral, brand, accent, success or danger.
iconnullOptional leading icon.
srLabelnullContext for a screen reader hearing the cell alone.

Vue

PropType and defaultWhat it does
variantString, 'neutral'neutral, brand, accent, success or danger.

In the markup contract

contract/markup-contract.json is extracted from the two static templates and every package tests against it. This is what it records for .wsu-badge.

TemplateElementsAccessibility attributesUses
internal apps/examples/static-html/index.htmlspannone recorded7
public apps/examples/static-html/public-app.htmlspannone recorded4