Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

createGroup

Multi-selection with tri-state (mixed/indeterminate) support for checkbox trees, grouped toggles, and any pattern where items can be partially selected.

Usage

The createGroup composable manages a group of selectable items, letting you work with both their IDs and their position indexes. It supports selecting, unselecting, toggling, and reading the indexes of selected items.

ts
import { createGroup } from '@vuetify/v0'

// Instantiate group
const group = createGroup()

// Register items
group.register({ id: 'apple', value: 'Apple' })
group.register({ id: 'banana', value: 'Banana' })
group.register({ id: 'cherry', value: 'Cherry' })
group.register({ id: 'date', value: 'Date' })

// Select some items
group.select(['apple', 'banana'])
console.log(group.selectedIndexes.value) // Set { 0, 1 }

// Toggle an item (banana will become unselected)
group.toggle('banana')
console.log(group.selectedIndexes.value) // Set { 0 }

// Unselect apple
group.unselect('apple')
console.log(group.selectedIndexes.value) // Set {}

Context / DI

Use createGroupContext to share a group-selection instance across a component tree:

ts
import { createGroupContext } from '@vuetify/v0'

export const [useCheckboxGroup, provideCheckboxGroup, checkboxGroup] =
  createGroupContext({ namespace: 'my:checkboxes' })

// In parent component
provideCheckboxGroup()

// In child component
const group = useCheckboxGroup()
group.selectAll()

Architecture

createGroup extends createSelection with multi-select and tri-state capabilities:

Reactivity

Group selection state is always reactive, including the tri-state mixedIds set.

Property/MethodReactiveNotes
selectedIdsshallowReactive(Set) — always reactive
mixedIdsshallowReactive(Set) — tracks indeterminate state
mixedItemsComputedRef<Set> — ticket instances in mixed state
selectedIndexesComputed from selectedIds
selectedItemsComputed from selectedIds
selectedValuesComputed from selectedItems
isAllSelectedtrue when all non-disabled items are selected
isNoneSelectedtrue when no items are selected
isMixedtrue when some but not all items are selected — use for header checkbox
selectAll()-Select all non-disabled items
unselectAll()-Unselect all items
toggleAll()-Toggle all non-disabled items
mix(ids)-Set one or more tickets to indeterminate state
unmix(ids)-Clear indeterminate state from one or more tickets
mixed(id)-Returns true if the ticket is in mixed state
ticket isSelectedComputed from selectedIds
ticket isMixedReadonly<Ref<boolean>> — whether this ticket is indeterminate
ticket mix()-Set this ticket to indeterminate state
ticket unmix()-Clear indeterminate state from this ticket

Examples

Chip Filter

Chip filters are a common pattern for narrowing content by tags. This example shows how createGroup handles per-item toggling, bulk selection via a tri-state header, and reactive state queries (isAllSelected, isMixed, isNoneSelected) — all out of the box.

API Reference

The following API details are for the createGroup composable.
Was this page helpful?

Ctrl+/