Switch

Switch Primitive

Headless, unstyled switch primitive with full accessibility support.

Basic Headless Primitive

The primitive provides behavior and accessibility without styling.

State: Off

Controlled State

Control the primitive state externally with buttons.

Disabled State

Switches can be disabled to prevent interaction.

Accessibility Features

Built-in accessibility features following WAI-ARIA patterns.

Keyboard Shortcuts

Navigate and interact with switches using keyboard.

Toggle switch Space
Toggle switch Enter
Navigate to switch Tab

When to Use Primitives

Choose between primitives and styled components based on your needs.

Use Switch Primitive

  • Building a custom design system
  • Need complete control over styling
  • Want to apply your own CSS framework
  • Creating unique visual designs

Use Styled Component

  • Want shadcn/ui design out of the box
  • Need quick implementation
  • Like the default styling
  • Prefer convention over configuration

API Reference

Component parameters and their types.

Prop Type Default Description
Checked bool false Controls whether the switch is on. Supports two-way binding with @bind-Checked.
CheckedChanged EventCallback<bool> Callback invoked when the checked state changes.
Disabled bool false Prevents toggling when true.
Id string? Identifier used for label association.
ChildContent RenderFragment? Optional custom thumb/content rendered inside the switch button.

Reconnecting...

Attempting to rejoin the server

Connection Lost

Retrying in seconds

Connection Failed

Failed to rejoin the server.
Please retry or reload the page.

Session Paused

The session has been paused by the server

Resume Failed

Failed to resume the session.
Please reload the page.