Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Inputs

ToggleGroup

Segmented control. Single choice by default (a view switcher); multiple for independent toggles. ref points at the button that takes focus (the first pressed one, else the first enabled one).

import { ToggleGroup } from "@stylhero/ui";

Example

Code
import { useState } from "react";
import { ToggleGroup } from "@stylhero/ui";

function ToggleGroupExample() {
  const [view, setView] = useState("grid");
  return (
    <ToggleGroup label="View" value={view} onValueChange={setView}
      options={[{ value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "map", label: "Map" }]} />
  );
}

Props

PropTypeDefaultDescription
options required ToggleOption[] -
className string -
defaultValue string | string[] -
label string -
multiple boolean -
onBlur FocusEventHandler<HTMLDivElement> - Runs when focus leaves the group (react-hook-form's field.onBlur).
onValueChange ((value: string) => void) | ((value: string[]) => void) -
size "sm" | "md" "md"
value string | string[] -

Takes a ref.

Types

type ToggleOption = { value: string; label: ReactNode; disabled?: boolean };

Keyboard

KeyDoes
TabMoves between the buttons
Enter / SpaceToggles the focused button

Accessibility

  • A role="group" of buttons with aria-pressed. Give it a label.

Generated from src/components/ToggleGroup.tsx. Something wrong or missing? Open an issue.