Tinyrack

Toggle

A two-state button for formatting or view options. It exposes aria-pressed; it is not a form field and does not submit a value by itself.

Contract

AxisValuesDefault
statecontrolled pressed or uncontrolled defaultPressedoff
availabilityenabled or disabledenabled
labelvisible textrequired

Install

pnpm add @tinyrack/ui

Scroll inside the code area to read long lines.

Styles

@import '@tinyrack/ui/components/toggle.css';

Scroll inside the code area to read long lines.

Imports

import { TRToggle } from '@tinyrack/ui/components/toggle';

Scroll inside the code area to read long lines.

Playground

Usage

Examples

API

PropTypeDefaultPurpose
pressedbooleanControls the pressed state.
defaultPressedbooleanfalseSets the initial uncontrolled state.
onPressedChange(pressed, details) => voidReports a requested state change; call details.cancel() to veto it.
disabledbooleanfalseRemoves the button from interaction and sequential focus.
valuestringgeneratedIdentifies an item inside TRToggleGroup; provide a stable value there.
classNamestring | (state) => stringAdds consumer classes, optionally from TRToggleState.
renderReactElement | (props, state) => ReactElement<button>Replaces the rendered element while preserving merged behavior.

TRToggleProps and TRToggleState are exported from @tinyrack/ui/components/toggle. TRToggle also preserves button refs, styles, native attributes, and event handlers. Native Space/Enter activation, focus, and disabled semantics follow button behavior, and the default button type does not submit an enclosing form. Give every toggle an accessible name. A polymorphic render must preserve button keyboard semantics. Use TRCheckbox or TRSwitch when a value must participate in form submission or required validation.