Skip to main content

Toggle

The TkToggle component is another basic element for user input. You can use this for turning settings, features or true/false inputs on and off.

import { TkToggle } from '@takeoff-ui/react'

Playground​

Preview

Generated Code

<TkToggle
label="Toggle me"
size="base"
variant="info"
icon="check"
showIcon
/>
<TkToggle
label="Toggle me"
size="base"
variant="info"
icon="check"
:showIcon.prop="true"
/>
<tk-toggle
label="Toggle me"
size="base"
variant="info"
icon="check"
[showIcon]="true"
/>

Controls

Basic​

This demo visualizes the checked, unchecked states of a toggle component.

View Code
<TkToggle />

Variant​

Use the variant prop to change the color scheme of the toggle.

View Code
<TkToggle label="Primary" variant="primary" value={true} showIcon={false} />
<TkToggle label="Secondary" variant="secondary" value={true} showIcon={false} />
<TkToggle label="Neutral" variant="neutral" value={true} showIcon={false} />
<TkToggle label="Info" variant="info" value={true} showIcon={false} />
<TkToggle label="Success" variant="success" value={true} showIcon={false} />
<TkToggle label="Warning" variant="warning" value={true} showIcon={false} />
<TkToggle label="Danger" variant="danger" value={true} showIcon={false} />
<TkToggle label="Verified" variant="verified" value={true} showIcon={false} />
<TkToggle label="Purple" variant="purple" value={true} showIcon={false} />
<TkToggle label="Cyan" variant="cyan" value={true} showIcon={false} />
<TkToggle label="Business" variant="business" value={true} showIcon={false} />
<TkToggle label="Teal" variant="teal" value={true} showIcon={false} />
<TkToggle label="Dark" variant="dark" value={true} showIcon={false} />
<TkToggle label="White" variant="white" value={true} showIcon={false} />

States​

This example illustrates the disabled state of the toggle.

View Code
<TkToggle label="Disabled" disabled value={true} />
<TkToggle label="Invalid" invalid value={true} />

Hint And Error​

Use the hint prop to show supporting text below the toggle. When invalid is true, the error prop is displayed instead of the hint.

View Code
<TkToggle label="Email notifications" hint="Recommended for account updates" />
<TkToggle label="Two-factor authentication" invalid error="This setting requires verification" value={true} />

API​

Props​

NameTypeDefaultDescription
stringnullThe aria-labelledby attribute of the toggle.
stringnullSets the data-testid attribute on the root container element.
booleanfalseWhether the toggle is disabled.
stringnullThis is the error message that will be displayed.
stringnullProvides a hint or additional information about the toggle.
string'check'Specifies a material icon name to be displayed.
booleanfalseWhether the toggle is in an invalid state.
stringnullThe label for the toggle.
stringnullThe name attribute of the toggle.
booleantrueWhether to show the icon in the toggle.
"base", "large", "small", "xlarge", "xsmall"'base'Sets size for the component.
booleanfalseThe current state of the toggle.
"business", "cyan", "danger", "dark", "info", "neutral", "primary", "purple", "secondary", "success", "teal", "verified", "warning", "white"'info'The variant of the toggle.

Events​

NameDescription
tk-changeEvent emitted when the toggle value changes.

Methods​

NameTypeDescription
getInputElementgetInputElement() => Promise<HTMLInputElement>Returns the native <input> element used under the hood.

Slots​

NameDescription
The default slot