Toggle
A two-state button that can be either on or off.
<NaviusToggle @bind-Pressed="_pressed" aria-label="Toggle italic"
class="... data-[pressed]:bg-accent data-[pressed]:text-accent-foreground">
<ItalicIcon />
</NaviusToggle>
@code { private bool _pressed; }Features
- Full keyboard navigation.
- Can be controlled (
@bind-Pressed) or uncontrolled (DefaultPressed). -
aria-pressedreflects 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.
navius add toggleAnatomy
Import the part and assemble it.
@using Navius.Primitives.Components.Toggle
<NaviusToggle>
Toggle
</NaviusToggle>API Reference
Root
The toggle button. Renders a button.
| Prop | Type | Default |
|---|---|---|
| Pressed | bool | false |
| PressedChanged | EventCallback<bool> | - |
| DefaultPressed | bool | false |
| Disabled | bool | false |
| ChildContent | RenderFragment? | - |
Data attributes
| 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.
Keyboard interactions
| Key | Description |
|---|---|
| Space | Activates the toggle, flipping its state. |
| Enter | Activates the toggle, flipping its state. |