<script setup lang="ts">
import { AToggle } from 'akar';
import { ref } from 'vue';
const toggleState = ref(false);
</script>
<template>
<AToggle
v-model="toggleState"
aria-label="Toggle italic"
class="color-text rounded-lg bg-background bg-white flex size-9 ring ring-ring-accented ring-inset shadow-sm transition-colors-280 items-center justify-center data-[state=on]:bg-background-accented hover:bg-background-elevated focus-within:(ring-2 ring-ring-inverted)"
>
<i
class="i-lucide:italic size-6"
/>
</AToggle>
</template>
Import the component.
<script setup>
import { AToggle } from 'akar';
</script>
<template>
<AToggle />
</template>
The toggle.
| Prop | Default | Type |
|---|---|---|
as | 'button' | APrimitiveAsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
defaultValue | booleanThe pressed state of the toggle when it is initially rendered. Use when you do not need to control its open state. | |
disabled | false | boolean |
modelValue | boolean | null | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
required | booleanWhen |
| Event | Type |
|---|---|
update:modelValue | [value: boolean]Event handler called when the value of the toggle changes. |
| Slot | Type |
|---|---|
modelValue | booleanThe controlled pressed state of the toggle. Can be bind as |
state | 'on' | 'off'Current state |
pressed | booleanCurrent pressed state |
disabled | booleanWhen |
| Key | Description |
|---|---|
Space | Activates/deactivates the toggle. |
Enter | Activates/deactivates the toggle. |