Skip to the content

Kongens Nytorv

Metro M1, M2 and M3.

Show planned works on the map

Props

NameTypeDefaultDescription
onChange(event: Event, value: boolean, details: Checkbox.Root.ChangeEventDetails) => void—Called when a click or Space ticks or unticks the checkbox, with the new state as value; details.reason is 'none', and details.cancel() keeps the state as it was. event is details.event. Not called while disabled or read-only.
childrenReactNode—The label: what ticking the box turns on or agrees to, in sentence case, such as "Show planned works on the map". It names the checkbox and stays the same ticked or not. Left out, give the checkbox an aria-label or aria-labelledby.
classNamestring—Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
styleCSSProperties—Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
refRef<HTMLElement>—Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
slotProps{ indicator?: Omit<CheckboxIndicatorProps, "keepMounted" | "render"> | undefined; }—Props for each part: indicator.
onChange(event: Event, value: boolean, details: Checkbox.Root.ChangeEventDetails) => void, default —
Called when a click or Space ticks or unticks the checkbox, with the new state as value; details.reason is 'none', and details.cancel() keeps the state as it was. event is details.event. Not called while disabled or read-only.
childrenReactNode, default —
The label: what ticking the box turns on or agrees to, in sentence case, such as "Show planned works on the map". It names the checkbox and stays the same ticked or not. Left out, give the checkbox an aria-label or aria-labelledby.
classNamestring, default —
Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
styleCSSProperties, default —
Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
refRef<HTMLElement>, default —
Reaches the root, the <span role="checkbox">. className is merged after pn-Checkbox.
slotProps{ indicator?: Omit<CheckboxIndicatorProps, "keepMounted" | "render"> | undefined; }, default —
Props for each part: indicator.

Use it

import { Checkbox } from '@mylder/perron'

Ask your agent

get_reference({ library: "base-ui", component: "Checkbox" })

Keyboard and ARIA

From the Base UI reference for Checkbox and the installed CheckboxRoot and useButton. "From" says who does it.

KeyDoesFrom
Tab, Shift+TabMoves focus to the checkbox and away; a disabled checkbox is skipped, a read-only one is notThe browser, and Base UI's tabIndex
SpaceTicks or unticks the checkbox on release and calls onChange with the new state; its keydown doesn't scroll the pageBase UI
EnterDoesn't toggle; in a form, clicks the form's default submit button, as on a native checkboxBase UI

Checkbox adds no keys of its own. Checkboxes in a column are a tab stop each: each is an answer of its own.

ElementRoleAccessible name fromStates announced
rootcheckbox, from Base UI; a native button with the checkbox role when render gives a <button>Its text content, the label's children; the caller's aria-label or aria-labelledby win, and with no children, a <label htmlFor> on its id through Base UI's aria-labelledbyaria-checked, true, false or mixed; aria-disabled; aria-readonly; aria-required; aria-invalid inside an invalid Base UI field, on the root and the hidden input; with parent, aria-controls the ids of the checkboxes it controls
indicatornone: presentational inside the checkbox, its mark an aria-hidden SVGnonenone
labelnone: text inside the checkboxThe checkbox's namenone
hidden inputnone: aria-hidden, tabIndex −1, from Base UInonenone

What axe won't catch, from the contract, each with how this component meets it:

  • Everything the eye is told, the ear is told, for every shape each prop accepts: the tick is aria-checked="true", heard as "checked", the dash aria-checked="mixed", heard as "mixed" or "partially checked", the empty box aria-checked="false"; the marks are aria-hidden, since the state says them; the tertiary colour of a disabled checkbox is aria-disabled; the danger edge of an invalid one is the field's error text and aria-invalid, never the edge alone.
  • Every landmark and named region has an accessible name: none here; a checkbox is neither. The group of checkboxes is CheckboxGroup's, inside a Fieldset whose legend names it.
  • Every default label can be overridden: none here; Checkbox owns no strings.
  • Every shape the type accepts renders, in every variant: children renders a string, an element and a list alike, ticked, unticked, indeterminate and disabled, and nothing at all when it renders nothing, leaving the box alone.
  • A hidden copy kept for animation is aria-hidden, and a collapsed region is inert: none here; the box kept mounted is the box itself, not a copy, and nothing collapses.
  • Native semantics first: Base UI's role="checkbox" on a <span>, with a native <input type="checkbox"> beside it for the form; with render and nativeButton, a native <button>.
  • Focus moves in reading order and returns on close: each checkbox is one tab stop in document order, focus stays on the checkbox it toggles, and it opens nothing to return from.
  • Every target is at least size.target-min square: the smallest target is a checkbox with no label, its root size.target-min (24 px) square round the 16 px box; with a label, the whole row is the target.
  • Loops stop when the system asks for less motion: none here; Checkbox has no loop and no transition.

Owned strings

No owned strings: every word comes from the caller, as children or an aria-label, and the state is heard from aria-checked, in the screen reader's own words.

Do and don't

For a caller using the component, with the reason. Each row is a rule: a must row's Don't is never right, a should row's needs a reason, and Checked by says what catches the Don't in a caller's code.

RuleLevelDoDon'tChecked by
DD-1shouldUse Checkbox for an answer or a setting that is on or off on its own, applied when the form is sent, such as agreeing to a noticeUse it for a filter on the map that takes effect at once: that is a FilterChip's, pressed and seen at oncereview
DD-2mustWrite the label as what ticking it turns on, in sentence case, the same ticked or not: "Show planned works on the map"Write it as a question or a negative ("Don't show planned works?"): a tick on a negative reads backwardsreview
DD-3mustPut a link about the setting next to the checkbox, outside its childrenPut a link inside the label: a checkbox's content is flattened into its name, so the link can't be reached or pressedreview
DD-4shouldGive name, and value where the form needs more than "on", so the answer reaches the form; connect a form library through its controllerRead the state back from the DOM or keep a hidden input of your own: Base UI's hidden input already carries itreview
DD-5mustUse indeterminate for a box that stands for a set partly on, such as "All lines" over the lines below it, and set it from the set's state, or give it parent inside a CheckboxGroup with allValues, which sets it for youUse it as a third answer to one question: "mixed" says some of a set, and Space always turns it to ticked or untickedreview
DD-6mustShow why a box is invalid in words, from its fieldRely on the danger edge alone: colour is never the only sign (Accessibility)review
DD-7mustGroup related checkboxes in a CheckboxGroup, whose legend names the groupMake a list of checkboxes one tab stop, or use them for one choice among several: that is a radio group's or a SegmentedControl'sreview
DD-8mustKeep onChange for the box's state, and cancel it with details.cancel() when the change must not happenSet aria-checked yourself or toggle a class: Base UI keeps the state, the attribute and the input in stepreview