Pattern
Tabs
Sections of a record or a page, as buttons that switch in place or links that navigate, with count pills.
- Copy the bindings from
- app/
features/ forms/ routes/ dashboard/ submitted-forms.kind/ components/ review-drawer.tsx - Route
- /
dashboard/ accounts/ :acctId/ sites/ :siteId/ submitted-forms/ :kind?review=:id
Button tabs with counts and an indicator
Switch a section in place. The row is a tablist: each tab has role tab and the current one aria-selected, with no aria-current since nothing navigates, and Left, Right, Home, and End move between tabs. Give it an `id` from `useId` and spread `tabPanelProps(id, tab)` on the element that shows the selected section, which the selected tab’s aria-controls names. A count shows in a pill, zero included, and the flag marks flagged answers.
- Route
- /
dashboard/ accounts/ :acctId/ sites/ :siteId/ submitted-forms/ :kind?review=:id
<Tabs
id={tabsId}
items={[
{
key: 'overview',
label: 'Overview',
},
{
key: 'answers',
label: 'Answers',
count: 117,
indicator: 'flag',
},
{
key: 'contracts',
label: 'Contracts',
count: 0,
},
{
key: 'notes',
label: 'Notes',
count: 5,
},
{
key: 'history',
label: 'History',
count: 23,
},
]}
selected={tab}
onSelect={setTab2}
/>
<div
{...tabPanelProps(tabsId, tab)}
>
{/* the selected section */}
</div>Link tabs
Navigate. The tab whose path matches the page exactly is current, whatever the search string, so Daily Dosages stays current while the page keeps its date in the URL. Here they switch between the gallery’s own pages; the snippet shows the paths the Medication layout builds.
- Route
- /
dashboard/ accounts/ :acctId/ sites/ :siteId/ dosages
<Tabs
items={[
{
key: 'daily',
label: 'Daily Dosages',
to: `${siteBaseUrl}/daily`,
},
{
key: 'missed',
label: 'Missed Dosages',
to: `${siteBaseUrl}/missed`,
},
]}
/>An overflowing row
The row never wraps or becomes a dropdown. It scrolls sideways, keeps the current tab in view clear of the fade, and fades at a clipped edge. When this page opens, Sponsors is current; each other tab opens its own gallery page, where that tab is current.
- Route
- /
dashboard/ accounts/ :acctId/ sites/ :siteId/ animals/ :id/ edit
<Tabs
items={[
{
key: 'edit',
label: 'Edit Animal',
to: `${siteBaseUrl}/edit`,
},
{
key: 'medical',
label: 'Medical',
to: `${siteBaseUrl}/medical`,
},
{
key: 'notes',
label: 'Notes',
to: `${siteBaseUrl}/notes`,
},
{
key: 'submissions',
label: 'Applications',
count: 4,
to: `${siteBaseUrl}/submissions`,
},
{
key: 'contracts',
label: 'Contracts',
count: 2,
to: `${siteBaseUrl}/contracts`,
},
{
key: 'history',
label: 'History',
to: `${siteBaseUrl}/history`,
},
{
key: 'sponsors',
label: 'Sponsors',
count: 3,
to: `${siteBaseUrl}/sponsors`,
},
]}
/>