Toggle

PreviousNext

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

Component toggle-demo not found in registry.

Usage

import { Bold } from "lucide-react"
 
import * as Toggle from "@/registry/radix-ui/ui/toggle"
 
export function ToggleExample() {
  const [bold, setBold] = React.useState(false)
 
  return (
    <Toggle.Root
      pressed={bold}
      onPressedChange={setBold}
      variant="primary"
      appearance="outline"
    >
      <Toggle.Icon>
        <Bold className="size-4" />
      </Toggle.Icon>
      Bold
    </Toggle.Root>
  )
}

Examples

Basic Toggle

Component toggle-demo not found in registry.

Ghost Appearance

Component toggle-ghost not found in registry.

Different Sizes

Component toggle-sizes not found in registry.

Props

Toggle.Root

This component is based on the Radix UI Toggle primitive and supports all of its props.

Prop

Type

Default

appearance
outline
ghost
outline
size
xs
sm
md
lg
md
pressed
boolean
-
defaultPressed
boolean
-
onPressedChange
(pressed: boolean) => void
-
disabled
boolean
-
asChild
boolean
false
className
string
-
children
ReactNode
-