HextaUI

Toggle: Controlled

Pass pressed and onPressedChange. The label stays the same while the icon follows the state.

Microphone is on
"use client"

import * as React from "react"
import { IconMicrophone, IconMicrophoneOff } from "@tabler/icons-react"

import { Toggle } from "@/components/ui/toggle"

export function ToggleControlled() {
  const [muted, setMuted] = React.useState(false)

  return (
    <div className="flex items-center gap-3 text-sm">
      <Toggle
        variant="outline"
        aria-label="Mute microphone"
        pressed={muted}
        onPressedChange={setMuted}
      >
        {muted ? <IconMicrophoneOff /> : <IconMicrophone />}
      </Toggle>
      <span className="text-muted-foreground">
        Microphone is {muted ? "muted" : "on"}
      </span>
    </div>
  )
}

This adds the example as components/examples/toggle/controlled.tsx, together with the Toggle component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/toggle-controlled.json

To add only the component, follow the Toggle installation.

Props in this example

The Toggle props this example sets, from the API reference.

PropTypeDefault
variant
"default" | "outline""default"
pressed
boolean–
onPressedChange
(pressed, details) => void–

Every prop is in the Toggle API reference.

See them all, with keyboard support and accessibility notes, on the Toggle page.