Veil UI
Components

Toggle

A two-state button that can be pressed or unpressed.

Installation

$ npx veil-ui@latest add toggle

Usage

import { Toggle } from "@/components/ui/toggle";
import { Bookmark } from "lucide-react";

<Toggle aria-label="Bookmark this page">
  <Bookmark />
</Toggle>;

Examples

Basic

Outline

Sizes

With text

API reference

PropTypeDefaultDescription
variant"default" | "outline""default"Visual style of the toggle.
size"sm" | "default" | "lg""default"Control height and padding.
pressedboolean—Controlled pressed state.
defaultPressedbooleanfalseInitial pressed state when uncontrolled.
onPressedChange(pressed: boolean) => void—Called when the pressed state changes.
...propsTogglePrimitive.Root props—All Radix Toggle props, including disabled and aria-label.

Accessibility

  • Exposes aria-pressed and toggles it on click, Space and Enter.
  • Icon-only toggles need an aria-label; toggles with text use the text as the accessible name.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add toggle --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Toggle } from "reka-ui";

import { cn } from "@/lib/utils";

import { toggleVariants, type ToggleVariants } from "./variants";

const props = withDefaults(
  defineProps<{
    class?: string;
    variant?: ToggleVariants["variant"];
    size?: ToggleVariants["size"];
    disabled?: boolean;
    defaultValue?: boolean;
  }>(),
  { disabled: false },
);

const model = defineModel<boolean>();
</script>

<template>
  <Toggle
    v-model="model"
    data-slot="toggle"
    :default-value="defaultValue"
    :disabled="disabled"
    :class="cn(toggleVariants({ variant, size }), props.class)"
  >
    <slot />
  </Toggle>
</template>

On this page