Try 'magnetic button'
View code

Specification

Catalogue
No. 18 of 110
Section
Tabs
Interaction
Press
Element
Tabs, Media
Preview
Live component
Imports
react 19.3.1, @number-flow/react 0.6.2
Added

Notes

Pick a finish or a treatment and the photo changes to show exactly that one.

When options are visual, a name alone is a guess. Every photo has the same framing, so only the option changes, and the note under it says what it is in words.

Photos cross-fade 250ms ease-out. Tabs with arrow keys, Home and End; two rows of tabs under 460px. Same framing in every photo, so the change is the option alone.

The names, figures and pictures in the demo are sample content; a real build uses the client's own.

Code

React and plain CSS
"use client";

import { useId, useState } from "react";
import { tabKey } from "@/components/pieces/shared";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "./image-tabs.css";

const S = "/samples";

const FINISHES = [
  { id: "oak", label: "Oak", note: "Oak veneer, matt lacquer, black bar handles." },
  { id: "walnut", label: "Walnut", note: "Walnut veneer with brushed brass handles." },
  { id: "sage", label: "Sage", note: "Painted in-frame doors, brass handles." },
  { id: "ink", label: "Ink blue", note: "Painted in-frame doors, brass handles." },
];

function ImageTabsDemo() {
  const [i, setI] = useState(0);
  const uid = useId();
  const pick = (k: number) => {
    setI(k);
    document.getElementById(`${uid}-t${k}`)?.focus();
  };
  return (
    <div className="dm">
      <div className="itabs">
        <div className="itabs-frame" role="tabpanel" id={`${uid}-panel`} aria-labelledby={`${uid}-t${i}`}>
          {FINISHES.map((f, k) => (
            <img key={f.id} src={`${S}/kitchen-${f.id}.svg`} alt={k === i ? `Kitchen in the ${f.label.toLowerCase()} finish` : ""} aria-hidden={k !== i} data-on={k === i || undefined} draggable={false} />
          ))}
        </div>
        <div className="itabs-list" role="tablist" aria-label="Cabinet finish">
          {FINISHES.map((f, k) => (
            <button
              key={f.id}
              id={`${uid}-t${k}`}
              type="button"
              role="tab"
              aria-selected={i === k}
              aria-controls={`${uid}-panel`}
              tabIndex={i === k ? 0 : -1}
              className="itabs-tab"
              onClick={() => setI(k)}
              onKeyDown={(e) => {
                const n = tabKey(e.key, k, FINISHES.length);
                if (n !== null) {
                  e.preventDefault();
                  pick(n);
                }
              }}
            >
              <span className="itabs-swatch" data-finish={f.id} aria-hidden="true" />
              {f.label}
            </button>
          ))}
        </div>
        <p className="itabs-note" aria-live="polite">
          {FINISHES[i]?.note}
        </p>
      </div>
    </div>
  );
}

// What a hovered card shows: the piece used the way a visitor would.
const TOUR: Tour = [
  { click: ".itabs-tab", nth: 1 },
  { click: ".itabs-tab", nth: 2 },
  { click: ".itabs-tab", nth: 3 },
  { click: ".itabs-tab", nth: 0 },
];

export default function ImageTabsEntry(props: LivePreviewProps) {
  return (
    <PieceStage {...props} label="A photo for each option" sample tour={TOUR}>
      <ImageTabsDemo />
    </PieceStage>
  );
}

More like this

Before and after slider

DragMedia and galleries

Bookshelf

Press, Layout AnimationMedia and galleries

Image panels that widen

Hover, Layout AnimationMedia and galleries

Photo grid that opens into the photo

Layout AnimationMedia and galleries

Video poster that opens the player

Press, Layout AnimationMedia and galleries

Menu that opens into link cards

Press, Layout AnimationNavigation