# Tabs

Source: https://ecosphere.dev/docs/navigation/tabs (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A row of views of one thing, the active one underlined in accent: page tabs across a screen, or section tabs inside a card.

`import { EcoTabs } from "vue-ecosphere"`

## Page tabs

The screen's main views. Arrow keys, Home and End move between tabs; only the tab where acting is possible takes the filled notification count. A row wider than its container scrolls sideways instead of wrapping or widening the page.

Vue (vue-ecosphere):

```vue
<script setup lang="ts">
const view = ref("open");
const views = [
  { key: "open", label: "Open", count: 12, notify: true },
  { key: "scheduled", label: "Scheduled", count: 4 },
  { key: "closed", label: "Closed", count: 248 },
  { key: "archived", label: "Archived" },
];
</script>

<EcoTabs v-model="view" :items="views" size="page" label="Views">
  <template #panel>…the {{ view }} list…</template>
</EcoTabs>
```

React (react-ecosphere):

```tsx
const [view, setView] = useState("open");
const views = [
  { key: "open", label: "Open", count: 12, notify: true },
  { key: "scheduled", label: "Scheduled", count: 4 },
  { key: "closed", label: "Closed", count: 248 },
  { key: "archived", label: "Archived" },
];

<EcoTabs
  value={view}
  onChange={setView}
  items={views}
  size="page"
  label="Views"
  renderPanel={() => <>…the {view} list…</>}
/>
```

## Section tabs

Two to four short sections inside a card or a drawer.

Vue (vue-ecosphere):

```vue
<EcoTabs v-model="section" :items="[
  { key: 'activity', label: 'Activity', count: 3, notify: true },
  { key: 'details', label: 'Details' },
  { key: 'history', label: 'History', count: 26 },
]" label="Sections">
  <template #panel-activity>…</template>
  <template #panel-details>…</template>
  <template #panel-history>…</template>
</EcoTabs>
```

React (react-ecosphere):

```tsx
<EcoTabs
  value={section}
  onChange={setSection}
  label="Sections"
  items={[
    { key: "activity", label: "Activity", count: 3, notify: true },
    { key: "details", label: "Details" },
    { key: "history", label: "History", count: 26 },
  ]}
  renderPanel={{
    activity: () => <>…</>,
    details: () => <>…</>,
    history: () => <>…</>,
  }}
/>
```

## No counts

Vue (vue-ecosphere):

```vue
<EcoTabs v-model="tab" size="page" label="Views" :items="[
  { key: 'overview', label: 'Overview' },
  { key: 'usage', label: 'Usage' },
  { key: 'billing', label: 'Billing' },
]" />
```

React (react-ecosphere):

```tsx
<EcoTabs value={tab} onChange={setTab} size="page" label="Views" items={[
  { key: "overview", label: "Overview" },
  { key: "usage", label: "Usage" },
  { key: "billing", label: "Billing" },
]} />
```

## Links to views, with icons and a panel

When each view is worth a URL, give every tab an href: the row becomes nav.tabs with aria-current, and the browser history does the rest.

Vue (vue-ecosphere):

```vue
<!-- Every item has an href: renders nav.tabs with a.tab and aria-current="page" -->
<EcoTabs v-model="tab" size="page" label="Record" :items="[
  { key: 'summary', label: 'Summary', icon: 'file-list-3-line', href: '/accounts/42' },
  { key: 'vehicles', label: 'Vehicles', icon: 'car-line', href: '/accounts/42/vehicles', count: '1,204' },
  { key: 'drivers', label: 'Drivers', icon: 'steering-2-line', href: '/accounts/42/drivers', count: 986 },
  { key: 'billing', label: 'Billing', icon: 'bill-line', href: '/accounts/42/billing' },
]">
  <template #panel-summary><dl class="kv">…</dl></template>
</EcoTabs>
```

React (react-ecosphere):

```tsx
{/* Every item has an href: renders nav.tabs with a.tab and aria-current="page" */}
<EcoTabs
  value={tab}
  onChange={setTab}
  size="page"
  label="Record"
  items={[
    { key: "summary", label: "Summary", icon: "file-list-3-line", href: "/accounts/42" },
    { key: "vehicles", label: "Vehicles", icon: "car-line", href: "/accounts/42/vehicles", count: "1,204" },
    { key: "drivers", label: "Drivers", icon: "steering-2-line", href: "/accounts/42/drivers", count: 986 },
    { key: "billing", label: "Billing", icon: "bill-line", href: "/accounts/42/billing" },
  ]}
  renderPanel={{ summary: () => <dl className="kv">…</dl> }}
/>
```

## Through the router

With vue-router installed, give every tab a `to`: each renders an anchor with the resolved href and navigates without a page load, and the tab of the current route is current, through back and forward too. Modifier-clicks still open a new tab. Render the view with RouterView under the row.

Vue (vue-ecosphere):

```vue
<!-- Each tab is a RouterLink: no page load, and the tab of the current route is current -->
<EcoTabs size="page" label="Account" :items="[
  { key: 'summary', label: 'Summary', to: { name: 'account-summary', params: { id } } },
  { key: 'vehicles', label: 'Vehicles', to: { name: 'account-vehicles', params: { id } } },
  { key: 'billing', label: 'Billing', to: { name: 'account-billing', params: { id } } },
]" />
<div class="tabpanel"><RouterView /></div>
```

React (react-ecosphere):

```tsx
{/* Each tab renders your router's Link; pass the current route's key as value */}
<EcoTabs size="page" label="Account" as={Link} value={currentKey} items={[
  { key: "summary", label: "Summary", to: `/accounts/${id}` },
  { key: "vehicles", label: "Vehicles", to: `/accounts/${id}/vehicles` },
  { key: "billing", label: "Billing", to: `/accounts/${id}/billing` },
]} />
<div className="tabpanel"><Outlet /></div>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `EcoTabItem[]` | — | { key, label, count?, notify?, icon?, href?, to?, disabled? }. notify renders the count as badge--notification (one tab per row at most). to is a vue-router destination: the tab renders through RouterLink and is current while its route is active (a nested view below it included); a string falls back to a plain link without the router. |
| `v-model` | `string` | first tab | Key of the active tab. |
| `size` | `"page" \| "section"` | "section" | page → tabs--page for the screen's main views; section tabs share the width equally. |
| `label` | `string` | — | Accessible name of the row. |
| `#panel-<key> / #panel` | `slot` | — | Content in tabpanel under the row, 16px clear of the rule. |
| `@change` | `(key: string) => void` | — | Fires when the active tab changes. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `EcoTabItem[]` | — | { key, label, count?, notify?, icon?, href?, to?, disabled? }. notify renders the count as badge--notification (one tab per row at most). With as (your router's Link) on EcoTabs, each tab renders it with the item's to; without as, a string to becomes the href. Pass the current route's key as value. |
| `value / defaultValue / onChange` | `string` | first tab | Key of the active tab; onChange(key) fires when it changes. |
| `size` | `"page" \| "section"` | "section" | page → tabs--page for the screen's main views; section tabs share the width equally. |
| `label` | `string` | — | Accessible name of the row. |
| `renderPanel` | `((scope: { item }) => ReactNode) \| Record<string, (scope: { item }) => ReactNode>` | — | Content in tabpanel under the row, 16px clear of the rule: one function for every tab, or a record of functions by tab key. |
