Tabs
Switches between views of the same thing, one at a time. Each tab can show its own panel, or only the bar to drive something else, like a filter or a route.
Showcase
<LnxTabs v-model=... <-- Pass a reactive variable here to bind its value :tabs="[{'value':'overview','label':'Overview','icon':'lucide:house'},{'value':'documents','label':'Documents','badge':12},{'value':'tenants','label':'Tenants'},{'value':'archive','label':'Archive','disabled':true}]" aria-label="Property" @update:modelValue="..." <-- Two way binding of the component />
When to use
- For views of the same object that the user moves between, like the sections of a property. Each view should make sense on its own.
- As the bar of a list, to filter it by status. Then leave out the slots and use
v-model. - To pick an option inside a form, use a Radio group with
mode="segmented".
Examples
With panels
Each tab shows the slot named as its value. The arrows move between tabs, and Home and End go to the first and the last.
The flat is rented until June.
vue
<LnxTabs v-model="tab" :tabs="TABS" aria-label="Property">
<template #overview>
The flat is rented until June.
</template>
<template #documents>
12 documents, the last one uploaded yesterday.
</template>
<template #tenants>
Two tenants.
</template>
</LnxTabs>1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Only the bar
Without slots only the bar is shown, and v-model tells which tab is selected.
Showing: all
vue
<LnxTabs v-model="filter" :tabs="FILTERS" aria-label="Status" />
<p>Showing: {{ filter }}</p>1
2
2
With routes
With to, a tab is a link: it navigates with vue-router and is active while its route, or one inside it, is the current one. Without vue-router, it's a plain link.
vue
<LnxTabs
aria-label="Property"
:tabs="[
{ value: 'overview', label: 'Overview', to: '/properties/7' },
{ value: 'documents', label: 'Documents', to: '/properties/7/documents' },
]"
/>
<RouterView />1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
API
Props
| Prop | Type | Description |
|---|---|---|
v-model | T | The value of the selected tab. With to, the tab of the current route |
tabs | Tab<T>[] | The tabs. Each one shows the slot named as its value, if there is one |
aria-label | string | What the tabs are about, for screen readers. It goes to the tab list |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | T | Two way binding of the component |
Slots
| Slot | Scope | Description |
|---|---|---|
[value] | — | The panel of the tab with that value. Without slots only the bar is shown |
Types
Tab
ts
export interface Tab<T = string> {
value: T; /* Identifies the tab, and names the slot of its panel */
label: string; /* Text of the tab */
icon?: string; /* Iconify icon before the label */
badge?: string | number; /* A count or a short text after the label */
to?: string | object; /* A route: the tab is a link, and it's active while the route matches */
disabled?: boolean; /* Can't be selected */
}1
2
3
4
5
6
7
8
2
3
4
5
6
7
8