NK

Search

Search pages, posts, and components

All components

Button Group

Buttons

A joined, segmented button group.

Installation

Add it with the shadcn CLI:

$pnpm dlx shadcn@latest add https://nawalkattel.com.np/r/button-group.json
Or install manually
  1. 1. Install dependencies

    pnpm add clsx tailwind-merge
  2. 2. Copy the component source into components/library/button-group.tsx

Props

PropTypeDefaultDescription
optionsstring[] - Option labels, in order.
activenumber0Initially selected index.
onChange(index: number) => void - Called with the new index.

Accessibility

  • aria-pressed marks the selected option for assistive tech.
  • Selection changes background and text colour together.
  • Real buttons, so keyboard activation works without extra wiring.

Dependencies

clsxtailwind-merge