InstallComponentsExample

Tabs Web Component

A segmented control that switches between panels, using the same look as the finance app.

How it helpsButtons in a <nav> plus one <section> per tab. The element wires up ARIA roles, arrow keys and hidden panels.

Segmented

Overview panel: your month at a glance.

Analytics panel: trends and categories.

Reports panel: export statements.

export default function Example() {
  return (
    <>
      <sd-tabs className="w-full">
        <nav><button>Overview</button><button>Analytics</button><button>Reports</button></nav>
        <section><p>Overview panel: your month at a glance.</p></section>
        <section><p>Analytics panel: trends and categories.</p></section>
        <section><p>Reports panel: export statements.</p></section>
      </sd-tabs>
    </>
  );
}
<sd-tabs class="w-full">
  <nav><button>Overview</button><button>Analytics</button><button>Reports</button></nav>
  <section><p>Overview panel: your month at a glance.</p></section>
  <section><p>Analytics panel: trends and categories.</p></section>
  <section><p>Reports panel: export statements.</p></section>
</sd-tabs>

In Next.js

// Works as-is in a Server Component. To react to changes:
"use client";
import { useRef } from "react";
import { useSidedishEvent } from "sidedish";

export function ReportTabs() {
  const ref = useRef<HTMLElement & { select(i: number): void }>(null);
  useSidedishEvent<{ index: number }>(ref, "change", (e) => console.log(e.detail.index));
  return (
    <sd-tabs ref={ref} selected={1}>
      <nav><button>Overview</button><button>Analytics</button></nav>
      <section>…</section>
      <section>…</section>
    </sd-tabs>
  );
}
// ref.current?.select(0) switches tab from code.

API

NameTypeDescription
<sd-tabs>element<nav> of buttons followed by <section> panels.
selectedattrInitial index (0-based).
select(i)methodChange tab from code.
changeeventdetail.index.