Skip to content
Component installs need the registry setup
VegaStack Design

View Toggle

The Grid | List | Board icon switch for a list page, with its labels hidden on a phone.

Status
stable
Since
0.23.10
Accessibility pattern
tablist, one selected tab

Last updated

Install

Add View Toggle from the VegaStack registry. The CLI verifies the item's integrity hash before writing it.

pnpm dlx shadcn@latest add @vegastack/view-toggle

The same command installs the registry items it composes: @vegastack/tabs.

Usage

import { ViewToggle } from "@/components/ui/view-toggle";

<ViewToggle value={view} onValueChange={setView} />;

ViewToggle switches a list page between its views — the default (pill) Tabs at the toolbar's h-8 tier, one view always selected; every toolbar switch uses this style. The labels show beside the icons from a small screen up and hide on a phone (they stay in the accessible name). DataList mounts it for you in the FilterBar view slot when you pass onViewChange, and remembers the choice for the session.

Examples

Views

views sets which views are offered, in order: Grid (LayoutGrid), List (List) and Board (Columns3). An app passes only the views it allows — views={["list", "board"]} for a task list.

API Reference

PropTypeDefaultDescription
onValueChange*(view: V) => void—Called with the view the user picks.
value*V—The current view.
aria-labelstring"View"The group's accessible name.
classNamestring—Extra classes for the group.
labelsPartial<Record<ListView, string>>—Relabel a view ("Cards" for "Grid").
viewsreadonly V[]["grid", "list"]The views offered, in order.

Data attributes and CSS variables on ViewToggle

AttributeValues
data-slot"view-toggle"
data-viewmirrors a prop or state value

Accessibility

  • A tablist named "View" (aria-label to rename); the current view is the selected tab.
  • On a phone the labels are visually hidden but still name each tab.
KeyAction
TabMove into and out of the list
← / →Move between views
Enter / SpaceSwitch to the focused view
ContractStates tested
Behaviourgrid, list, board
Accessibilitylabeled, browser-accessibility-test
Visualdefault, hover

Do / Don't

Do
Offer only the views the page supports, in the same order everywhere.
Don't
Use ViewToggle for a scope switch such as Mine | Team — that is a default Tabs in the scope slot.

On this page