Talisman LogoTalisman Logo Design System
Browse documentation
Components

Switch

A binary on and off setting that takes effect as soon as the user changes it, with an optional label and description.

Stableimport { Switch } from "@repo/ui/switch";Source

Avisa o revisor assim que a tarefa for atribuída.

size
variant
<Switch description="Avisa o revisor assim que a tarefa for atribuída." label="Notificar por e-mail" size="md" variant="default" />

When to use

  • For a setting that applies immediately, with no save button: notifications, a filter such as “Mostrar apenas com falha”, a feature flag.
  • For one binary choice where “on” and “off” are both clear.

When not to use

  • A choice that is sent with a form. Use Checkbox, so the user reviews it before submitting.
  • Picking several items from a list. Use Checkbox.
  • Choosing one option among several. Use Radio group.
  • Running an action. Use Button.

Variants

Brand
Contrast
Default
Variant Use for
default Most settings. Gray track when off, green when on.
contrast A track placed on a colored surface. Solid inverse track when off.
brand Enabled settings in platform orange. Extends the hit area upward and downward.

Sizes

compact · 34×20
md · 44×24
sm · 28×16

md is the default. compact and sm fit dense rows, such as a group switch and the smaller switches of its children.

States

Off, on, and disabled with a description.

Disponível apenas para administradores.

Definido pela política do cliente.

Examples

Label and description

The description says what happens when the switch is on.

Cada nova contestação entra na fila do revisor sem aprovação manual.

Content

  • Write the label as the setting, not as an action: “Notificar por e-mail”, not “Ative para notificar”.
  • The label must make sense for both states.
  • Use the description for consequences: “Cada nova contestação entra na fila do revisor sem aprovação manual.”

Do and don’t

DoName the setting. The switch state says on or off.
Don'tDon't write the label as an instruction. It reads the opposite when the switch is on.

Accessibility

  • Built on Radix Switch: a button with role="switch" and aria-checked.
  • Space toggles the switch when it has focus.
  • With label, the label is linked by htmlFor and id, so clicking the text toggles the switch. The id is generated when you do not pass one.
  • Without label, pass aria-label. The switch has no other visible name.
  • The focus ring appears only for keyboard focus (focus-visible).
  • brand respects reduced motion. The other variants animate the thumb with transition-transform.

Code

import { Switch } from "@repo/ui/switch";

<Switch
  checked={enabled}
  description="Avisa o revisor assim que a tarefa for atribuída."
  label="Notificar por e-mail"
  onCheckedChange={setEnabled}
/>;

Props

Switch
PropTypeDefaultDescription
descriptionstring—Secondary text under the label
disabledbooleanfalseDisables interaction and applies the disabled colors
labelstring—Visible label linked to the switch. Without it, pass `aria-label`
onCheckedChange(checked: boolean) => void—Called with the new state when the user toggles
size"compact" | "md" | "sm"mdTrack size
variant"brand" | "contrast" | "default"defaultTrack colors

Every other prop of the Radix Switch root, such as name, required and value, is forwarded.

Known issues

Issue Effect
The sm track is 16px high and compact is 20px. Only brand extends the hit area. Below the 24px minimum without a label. Harder to hit in dense rows.
The disabled thumb is bg-[rgba(0,0,0,0.05)], a hardcoded translucent color. Does not follow the tokens or the no-transparency rule. Looks different on each theme.
The on state uses bg-[hsl(var(--green-400))] and the thumb bg-[hsl(var(--neutral-white))], palette tokens. Does not change with the semantic tokens, so a theme cannot restyle it.
The focus ring uses ring-offset-background. The Tailwind config only defines old-background. The class generates nothing. The offset falls back to Tailwind’s default, white.
No style for aria-invalid. A switch cannot show a validation error.
Edit this page on GitHub