Back to elements
ElementForm & InputFree

Content Switch React component

A switch that swaps the content below it: a pill or underline thumb slides to the chosen option, the new panel slides in from that side (or fades or blurs in), and the box eases to the new height instead of jumping.

When to use the Content Switch component

Use Content Switch when a section shows one of a few alternative views of the same thing: preview / code, personal / business plans, map / list, before / after.

For full-page navigation between unrelated sections, use Tabs or real links instead.

Installation

Add the Content Switch component to your project with the shadcn CLI. It lands in components/content-switch.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/content-switch.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<ContentSwitch /> accepts 10 props, all optional.

  • options
    { value: string; label: string; icon?: React.ReactNode; content: React.ReactNode }[]
  • value
    string
  • defaultValue
    string
  • onValueChange
    (value: string) => void
  • variant

    pill: a filled thumb slides behind the labels. underline: a line slides under them.

    "pill" | "underline"
    Default: "pill"
  • transition

    How panels change: slide in from the side of the new option, fade, or blur.

    "slide" | "fade" | "blur"
    Default: "slide"
  • align
    "start" | "center"
    Default: "start"
  • label
    string
    Default: "View"
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

How is it different from Tabs?
It's built for a few closely related views inside one card or section: a compact switch, panels that slide in from the chosen side, and a box that eases to the new content height.
Does the layout jump when panels have different heights?
No. The container measures each panel and springs to its height.
Is it keyboard accessible?
It's a tablist: arrow keys move between options and select them, and each panel is labelled by its tab.

Related components

Floating Label Input
Free
Variant Swatches
Free
Input Group
Free
Masked Input
Free
Blockquote
Free
Basic Table
Free