Toggle Group
A set of two-state buttons that can be toggled on or off.
A set of two-state buttons that can be toggled on or off.
To set up the toggle group correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-part
attribute to help identify them in the DOM.
Learn how to use the ToggleGroup
component in your project. Let’s take a look
at the most basic example:
import { ToggleGroup } from '@ark-ui/react'
const Basic = () => {
return (
<ToggleGroup.Root>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
import { ToggleGroup } from '@ark-ui/solid'
const Basic = () => {
return (
<ToggleGroup.Root>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroup } from '@ark-ui/vue'
const value = ref(['b'])
</script>
<template>
<ToggleGroup.Root>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
</template>
Demonstrates how to enable multiple
selection within the group.
import { ToggleGroup } from '@ark-ui/react'
const Multiple = () => {
return (
<ToggleGroup.Root multiple>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
import { ToggleGroup } from '@ark-ui/solid'
const Multiple = () => {
return (
<ToggleGroup.Root>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroup } from '@ark-ui/vue'
const value = ref(['b'])
</script>
<template>
<ToggleGroup.Root multiple>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
</template>
Shows how to set an initial value in the toggle group.
import { ToggleGroup } from '@ark-ui/react'
const InitialValue = () => {
return (
<ToggleGroup.Root defaultValue={['b']}>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
import { ToggleGroup } from '@ark-ui/solid'
const InitialValue = () => {
return (
<ToggleGroup.Root value={['b']}>
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { ToggleGroup } from '@ark-ui/vue'
const value = ref(['b'])
</script>
<template>
<ToggleGroup.Root v-model="value">
<ToggleGroup.Item value="a">A</ToggleGroup.Item>
<ToggleGroup.Item value="b">B</ToggleGroup.Item>
<ToggleGroup.Item value="c">C</ToggleGroup.Item>
</ToggleGroup.Root>
</template>
value | string | |
asChild Render as a different element type. | boolean | |
disabled | boolean |
asChild Render as a different element type. | boolean | |
defaultValue The initial value of the toggle group. | string[] | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
disabled Whether the toggle is disabled. | boolean | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The unique identifier of the machine. | string | |
ids The ids of the elements in the toggle. Useful for composition. | Partial<{ root: string; toggle(value: string): string }> | |
loop Whether to loop focus inside the toggle group. | boolean | |
multiple Whether to allow multiple toggles to be selected. | boolean | |
onValueChange Function to call when the toggle is clicked. | (details: ValueChangeDetails) => void | |
orientation The orientation of the toggle group. | Orientation | |
rovingFocus Whether to use roving tab index to manage focus. | boolean | |
value The values of the toggles in the group. | string[] |