Back to Shark UI

Toggle

docs/components/toggle

latest6.8 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Toggle

Copy Markdown

Two-state button that can be toggled on or off.

DocsAPI

PreviewCode

Toggle

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/toggle

Usage#

import { 
  Toggle,   
  ToggleIndicator 
} from "@/components/ui/toggle";
<Toggle>
  <ToggleIndicator />
</Toggle>

Controlled#

Use the pressed and onPressedChange props to control the toggle state programmatically.

PreviewCode

Toggle

States#

Disabled#

Use the disabled prop to disable the toggle.

PreviewCode

Disabled

Variants#

Default#

PreviewCode

Toggle

Outline#

PreviewCode

Toggle

Sizes#

Small#

PreviewCode

Small

Medium#

PreviewCode

Medium

Large#

PreviewCode

Large

Examples#

Icon Group#

Use multiple toggles with icons for toolbar-style controls.

PreviewCode

API Reference#

Toggle#

Toggle button for on/off or selected state. Use asChild for custom elements.

PropTypeDefault
variant`"outline""ghost"`
size`"sm""md"
pressedboolean-
defaultPressedbooleanfalse
disabledbooleanfalse
onPressedChange(details: PressedChangeDetails) => void-
classNamestring-
asChildbooleanfalse

ToggleIndicator#

Icon or indicator shown when toggle is active. Omitted when used as child.

PropTypeDefault
classNamestring-
asChildbooleanfalse

For a complete list of props, see the Ark UI documentation.

[

Previous page

Toggle Tooltip ](/docs/components/toggle-tooltip)[

Next page

Tooltip ](/docs/components/tooltip)

On This Page

InstallationUsageControlledStatesDisabledVariantsDefaultOutlineSizesSmallMediumLargeExamplesIcon GroupAPI ReferenceToggleToggleIndicator