Skip to content
navius

Switch

A control that toggles between an on and off state.

Features

  • Full keyboard navigation.
  • Can be controlled (@bind-Checked) or uncontrolled (DefaultChecked).
  • Renders a hidden input so it participates in native form submission.
  • role="switch" with the correct aria-checked state.

Installation

Reference the Navius.Primitives package for the headless primitive, or vendor a styled version with the CLI: navius add copies the styled zits/ui component plus the brain files it depends on.

Anatomy

Import the part and assemble it.

API Reference

Contains all the parts of a switch. Renders a button.

Prop Type Default
Checked bool false
CheckedChanged EventCallback<bool> -
DefaultChecked bool false
Disabled bool false
Required bool false
Name string? -
Value string "on"
Form string? -
Data attribute Values
[data-checked] Present when checked
[data-unchecked] Present when unchecked
[data-disabled] Present when disabled

The thumb that is toggled to indicate state. Renders a span.

Prop Type Default
ChildContent RenderFragment? -
Data attribute Values
[data-checked] Present when checked
[data-unchecked] Present when unchecked
[data-disabled] Present when disabled

Accessibility

Implements the role, state, and keyboard map of the switch WAI-ARIA APG pattern. Covered by the browser test suite and an axe-core WCAG gate in CI.

Key Description
Space Toggles the component's state.
Enter Toggles the component's state.