Components
Toggle
A two-state button that can be pressed or unpressed.
Installation
$ npx veil-ui@latest add toggleUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "outline" | "default" | Visual style of the toggle. |
| size | "sm" | "default" | "lg" | "default" | Control height and padding. |
| pressed | boolean | — | Controlled pressed state. |
| defaultPressed | boolean | false | Initial pressed state when uncontrolled. |
| onPressedChange | (pressed: boolean) => void | — | Called when the pressed state changes. |
| ...props | TogglePrimitive.Root props | — | All Radix Toggle props, including disabled and aria-label. |
Accessibility
- Exposes
aria-pressedand 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>