Skip to content

Toggle

The Toggle component is a button that switches between two states — selected and unselected. It supports variants, sizes, icons, and an optional tooltip, and can be used in controlled or uncontrolled mode.

Playground

Variations

Controlled and uncontrolled

The Toggle component can be used in both controlled and uncontrolled modes. In controlled mode, the selected prop drives the toggle’s state and onChange fires with the new boolean when the user activates it. In uncontrolled mode, defaultValue sets the initial state and the component manages its own state internally.

With tooltip

Pass tooltipProps to wrap the toggle in a Tooltip. It accepts the title, content, side, and align properties from TooltipProps.

Installation

import { Toggle } from "@harnessio/ui/components";
<Toggle
size="sm"
variant="outline"
selectedVariant="primary"
rounded
tooltipProps={{
content: <p>This is a tooltip</p>,
}}
text="Toggle"
/>;