navius

Toggle

A two-state button that can be either on or off.

Features

  • Full keyboard navigation.
  • Can be controlled (@bind-Pressed) or uncontrolled (DefaultPressed).
  • aria-pressed reflects the on/off state.
  • Renders a native button, so it is focusable and form-aware by default.

Installation

Install the brain, or copy just this primitive in with the CLI.

Anatomy

Import the part and assemble it.

API Reference

The toggle button. Renders a button.

Prop Type Default
Pressed bool false
PressedChanged EventCallback<bool> -
DefaultPressed bool false
Disabled bool false
ChildContent RenderFragment? -
Data attribute Values
[data-pressed] Present when the toggle is pressed (on)
[data-disabled] Present when disabled

Accessibility

Adheres to the button WAI-ARIA design pattern.

Key Description
Space Activates the toggle, flipping its state.
Enter Activates the toggle, flipping its state.