Theme studio

Design a theme, preview it live, then export it. Saved in this browser.

Quick picks #10b981
Generated scale
50100200300400500600700800900
Some text is below AA

LegendItem

  • Stable
  • WCAG 2.2 evidence
  • RTL

One entry of a chart legend: the series' swatch and its name, with an optional value. The swatch comes from seriesStyle(seriesIndex), so it has the colour AND the dash or marker shape of the series in the plot (WCAG 1.4.1); the name is text, so nothing depends on colour. Two variants. **Static**: a plain span, presentational, renders in React Server Components; put it in a list (ChartFrame wraps each legend item in an li). **Interactive** (onChange set): a React Aria ToggleButton that shows or hides the series. It is a button with aria-pressed (pressed = shown): Tab reaches it, Enter and Space toggle it, keyboard focus shows the focus ring, it is at least 24 px tall (WCAG 2.1.1, 2.4.7, 2.5.8, 4.1.2), and a hidden series is muted, struck through and dimmed rather than only recoloured (1.4.1). Only the button part is client code. Consumer duties: use the same series wording as the data table; hide the series in the plot when onChange fires and keep at least one series visible; tell users when hiding changes what a chart summary says.

import { LegendItem } from "@nexera-ui/react";
Loading example…
8
examples
16
props
6
live controls
1
platform
10
WCAG criteria
2
blocks use it

Try every prop. Copy the code.

Change the props and the code updates. Check light and dark, LTR and RTL, and phone width.

Loading…
isSelected
defaultSelected
isDisabled
label
shape
hasMarker
Generated code
import { LegendItem } from "@nexera-ui/react";

<LegendItem />

Examples 7

The same examples as Storybook, rendered live. Open Code to copy one.

Series styles

All eight series in each swatch kind. Every series differs by glyph or dash as well as colour (WCAG 1.4.1); with hasMarker the line swatches show the glyph the plot draws on the line, which tells apart the series that share a dash.

Loading example…

Interactive

The interactive variant (onChange set): a toggle button with aria-pressed. Tab to an entry and press Enter or Space; a hidden series is struck through and dimmed as well as muted. Hover, press and keyboard focus have their own states.

Loading example…

Interactive states

Interactive entries in every state: shown, hidden, disabled, and with a value.

Loading example…

With values

An optional value after the label, for example a share or a total.

Loading example…

In chart frame

Inside a ChartFrame legend, which wraps each entry in a list item. Long names wrap instead of overflowing.

Loading example…

Long labels

A name longer than the room wraps inside its container (the swatch keeps its size).

Loading example…

Right to left

Right-to-left: the swatch is on the right of the label; the toggle's padding and hover fill mirror.

Loading example…

Props 16

Press "Try it" on a card to load that prop into the playground.

16 props shown

onChangeNexera
(isSelected: boolean) => void

Not set: a static entry has no interaction. Pass onChange to make the entry a toggle. Called with the new state when the entry is toggled: true = show the series, false = hide it. Setting it makes the entry interactive; leave it out for a static entry.

Default –
isSelectedNexera
boolean

Only on an interactive entry (with onChange). Whether the series is shown (controlled). A hidden series reads as muted, struck-through text with a dimmed marker. Pair it with onChange.

Default –
defaultSelectedNexera
boolean

Only on an interactive entry (with onChange). Whether the series is shown at first render (uncontrolled).

Default true
isDisabledNexera
boolean

Only on an interactive entry (with onChange). Disables the toggle.

Default false
label*Nexera
ReactNode

Name of the series. It is the accessible name of an interactive entry, so use the same wording as the table column and the tooltip. Long names wrap; they are never truncated.

Default –
seriesIndexNexera
number

Zero-based index of the series. It picks the colour (chart-1 to chart-8) and the dash and marker glyph from seriesStyle(index), so the entry matches the series in the plot and is not told by colour alone (WCAG 1.4.1).

Default 0
shapeNexera
"dot" | "line" | "dashed" | "square"

Kind of swatch. Pick what the chart draws: line for line charts, square for bars and areas, dot for points and slices, dashed for a line that is always dashed (a plan or target line). line follows the series' own dash pattern, so it matches the plot for every series.

Default "dot"
hasMarkerNexera
boolean

Draw the series' marker glyph on the middle of a line or dashed swatch. Set it when the plot draws markers on its line: eight dash patterns cannot tell eight series apart, a dash plus a glyph can (WCAG 1.4.1). Ignored for dot and square.

Default false
valueNexera
ReactNode

Value after the label, for example a total ("128") or a share ("42 %"). Shown when provided. UNVERIFIED: not in the Figma legend item. Format numbers for the locale before passing them.

Default –
classNameNexera
string

Extra classes for the root, merged last so they win over the defaults.

Default –
styleNexera
CSSProperties

Inline style for the root.

Default –
onPressReact Aria
(e: PressEvent) => void

Handler that is called when the press is released over the target.

Default –
onPressStartReact Aria
(e: PressEvent) => void

Handler that is called when a press interaction starts.

Default –
onPressEndReact Aria
(e: PressEvent) => void

Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.

Default –
onPressChangeReact Aria
(isPressed: boolean) => void

Handler that is called when the press state changes.

Default –
onPressUpReact Aria
(e: PressEvent) => void

Handler that is called when a press is released over the target, regardless of whether it started on the target or not.

Default –

* Required. React Aria props shown are the ones most apps use; the component accepts the rest of its React Aria props too.

Accessible by default.

Built on React Aria, and covered by the WCAG 2.2 evidence generated on every build.

WCAG 2.2 evidence

5 direct · 5 supporting
  • 1.1.1Non-text ContentLevel A · tested directly
  • 1.3.1Info and RelationshipsLevel A · tested directly
  • 1.3.2Meaningful SequenceLevel A · supporting test
  • 1.4.1Use of ColorLevel A · supporting test
  • 1.4.10ReflowLevel AA · supporting test
  • 1.4.12Text SpacingLevel AA · supporting test
  • 2.1.1KeyboardLevel A · tested directly
  • 2.4.7Focus VisibleLevel AA · tested directly
  • 2.5.8Target Size (Minimum)Level AA · supporting test
  • 4.1.2Name, Role, ValueLevel A · tested directly

Fits any width.

Nexera components respond to the space they are given. Drag the corner of the frame, or pick a width.

0 px · drag the corner

Styling hooks

Pass className to add Tailwind classes (merged last). State is exposed as data attributes, so you can style it with variants like data-pressed:.

  • data-disabled
  • data-hovered
  • data-pressed
  • data-selected
Usage
<LegendItem className="data-disabled:opacity-90 shadow-sm" />

Used in blocks

Related components