Usage
Use the Tabs component to display a list of items in a tabs.
<script setup lang="ts">
import { reactive } from 'vue'
const items = [
{
label: 'Account',
icon: 'i-lucide:user',
slot: 'account'
},
{
label: 'Password',
icon: 'i-lucide:lock',
slot: 'password'
}
]
const state = reactive({
name: 'praburangki',
username: 'praburangki',
currentPassword: '',
newPassword: '',
confirmPassword: ''
})
</script>
<template>
<PTabs :items="items">
<template #account>
<PForm :state="state" class="flex flex-col gap-4">
<PFormField label="Name" name="name">
<PInput v-model="state.name" class="w-full" />
</PFormField>
<PFormField label="Username" name="username">
<PInput v-model="state.username" class="w-full" />
</PFormField>
</PForm>
</template>
<template #password>
<PForm :state="state" class="flex flex-col gap-4">
<PFormField label="Current Password" name="current" required>
<PInput v-model="state.currentPassword" type="password" required class="w-full" />
</PFormField>
<PFormField label="New Password" name="new" required>
<PInput v-model="state.newPassword" type="password" required class="w-full" />
</PFormField>
<PFormField label="Confirm Password" name="confirm" required>
<PInput v-model="state.confirmPassword" type="password" required class="w-full" />
</PFormField>
</PForm>
</template>
</PTabs>
</template>
Items
Use the items prop as an array of objects with the following properties:
label?: stringicon?: stringavatar?: AvatarPropsbadge?: string | number | BadgePropscontent?: stringvalue?: string | numberdisabled?: booleanslot?: stringclass?: anypohon?: { trigger?: ClassNameValue, leadingIcon?: ClassNameValue, leadingAvatar?: ClassNameValue, leadingAvatarSize?: ClassNameValue, label?: ClassNameValue, trailingBadge?: ClassNameValue, trailingBadgeSize?: ClassNameValue, content?: ClassNameValue }
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account',
icon: 'i-lucide:user',
content: 'This is the account content.'
},
{
label: 'Password',
icon: 'i-lucide:lock',
content: 'This is the password content.'
}
])
</script>
<template>
<PTabs :items="items" class="w-full" />
</template>
Content
Set the content prop to false to turn the Tabs into a toggle-only control without displaying any content. Defaults to true.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account',
icon: 'i-lucide:user',
content: 'This is the account content.'
},
{
label: 'Password',
icon: 'i-lucide:lock',
content: 'This is the password content.'
}
])
</script>
<template>
<PTabs :content="false" :items="items" class="w-full" />
</template>
Unmount
Use the unmount-on-hide prop to prevent the content from being unmounted when the Tabs is collapsed. Defaults to true.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account',
icon: 'i-lucide:user',
content: 'This is the account content.'
},
{
label: 'Password',
icon: 'i-lucide:lock',
content: 'This is the password content.'
}
])
</script>
<template>
<PTabs :unmount-on-hide="false" :items="items" class="w-full" />
</template>
Color
Use the color prop to change the color of the Tabs.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account'
},
{
label: 'Password'
}
])
</script>
<template>
<PTabs color="neutral" :content="false" :items="items" class="w-full" />
</template>
Variant
Use the variant prop to change the variant of the Tabs.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account'
},
{
label: 'Password'
}
])
</script>
<template>
<PTabs color="neutral" variant="link" :content="false" :items="items" class="w-full" />
</template>
Size
Use the size prop to change the size of the Tabs.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account'
},
{
label: 'Password'
}
])
</script>
<template>
<PTabs size="md" variant="pill" :content="false" :items="items" class="w-full" />
</template>
Orientation
Use the orientation prop to change the orientation of the Tabs. Defaults to horizontal.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui'
const items = ref<PTabsItem[]>([
{
label: 'Account'
},
{
label: 'Password'
}
])
</script>
<template>
<PTabs orientation="vertical" variant="pill" :content="false" :items="items" class="w-full" />
</template>
Examples
Control active item
You can control the active item by using the default-value prop or the v-model directive with the index of the item.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui';
import { useRoute, useRouter } from '#app';
import { computed } from 'vue';
const route = useRoute();
const router = useRouter();
const items: Array<PTabsItem> = [
{
label: 'Account',
value: 'account',
},
{
label: 'Password',
value: 'password',
},
];
const active = computed({
get() {
return (route.query.tab as string) || 'account';
},
set(tab) {
// Hash is specified here to prevent the page from scrolling to the top
router.push({
path: '/docs/pohon/components/tabs',
query: { tab },
hash: '#control-active-item',
});
},
});
</script>
<template>
<PTabs
v-model="active"
:content="false"
:items="items"
class="w-full"
/>
</template>
With content slot
Use the #content slot to customize the content of each item.
This is the Account tab.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui';
const items: Array<PTabsItem> = [
{
label: 'Account',
icon: 'i-lucide:user',
},
{
label: 'Password',
icon: 'i-lucide:lock',
},
];
</script>
<template>
<PTabs
:items="items"
class="w-full"
>
<template #content="{ item }">
<p>This is the {{ item.label }} tab.</p>
</template>
</PTabs>
</template>
With custom slot
Use the slot property to customize a specific item.
You will have access to the following slots:
#{{ item.slot }}
Make changes to your account here. Click save when you're done.
<script setup lang="ts">
import type { PTabsItem } from 'pohon-ui';
import { reactive } from 'vue';
const items = [
{
label: 'Account',
description: 'Make changes to your account here. Click save when you\'re done.',
icon: 'i-lucide:user',
slot: 'account' as const,
},
{
label: 'Password',
description: 'Change your password here. After saving, you\'ll be logged out.',
icon: 'i-lucide:lock',
slot: 'password' as const,
},
] satisfies Array<PTabsItem>;
const state = reactive({
name: 'praburangki',
username: 'praburangki',
currentPassword: '',
newPassword: '',
confirmPassword: '',
});
</script>
<template>
<PTabs
:items="items"
variant="link"
:pohon="{ trigger: 'grow' }"
class="gap-4 w-full"
>
<template #account="{ item }">
<p class="color-text-muted mb-4">
{{ item.description }}
</p>
<PForm
:state="state"
class="flex flex-col gap-4"
>
<PFormField
label="Name"
name="name"
>
<PInput
v-model="state.name"
class="w-full"
/>
</PFormField>
<PFormField
label="Username"
name="username"
>
<PInput
v-model="state.username"
class="w-full"
/>
</PFormField>
<PButton
label="Save changes"
type="submit"
variant="soft"
class="self-end"
/>
</PForm>
</template>
<template #password="{ item }">
<p class="color-text-muted mb-4">
{{ item.description }}
</p>
<PForm
:state="state"
class="flex flex-col gap-4"
>
<PFormField
label="Current Password"
name="current"
required
>
<PInput
v-model="state.currentPassword"
type="password"
required
class="w-full"
/>
</PFormField>
<PFormField
label="New Password"
name="new"
required
>
<PInput
v-model="state.newPassword"
type="password"
required
class="w-full"
/>
</PFormField>
<PFormField
label="Confirm Password"
name="confirm"
required
>
<PInput
v-model="state.confirmPassword"
type="password"
required
class="w-full"
/>
</PFormField>
<PButton
label="Change password"
type="submit"
variant="soft"
class="self-end"
/>
</PForm>
</template>
</PTabs>
</template>
API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
items | T[] | |
color | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
variant | 'pill' | "pill" | "link" |
size | 'md' | "md" | "xs" | "sm" | "lg" | "xl" |
orientation | 'horizontal' | "horizontal" | "vertical"The orientation of the tabs. |
labelKey | 'label' | keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>>The key used to get the label from the item.
|
defaultValue | '0' | string | numberThe value of the tab that should be active when initially rendered. Use when you do not need to control the state of the tabs |
modelValue | string | numberThe controlled value of the tab to activate. Can be bind as | |
activationMode | automatic | "automatic" | "manual"Whether a tab is activated automatically (on focus) or manually (on click). |
content | true | booleanThe content of the tabs, can be disabled to prevent rendering the content. |
unmountOnHide | true | booleanWhen |
pohon | { root?: ClassValue; list?: ClassValue; indicator?: ClassValue; trigger?: ClassValue; leadingIcon?: ClassValue; leadingAvatar?: ClassValue; leadingAvatarSize?: ClassValue; label?: ClassValue; trailingBadge?: ClassValue; trailingBadgeSize?: ClassValue; content?: ClassValue; } |
Slots
| Slot | Type |
|---|---|
leading | { item: T; index: number; pohon: object; } |
default | { item: T; index: number; } |
trailing | { item: T; index: number; pohon: object; } |
content | { item: T; index: number; pohon: object; } |
list-leading | object |
list-trailing | object |
Emits
| Event | Type |
|---|---|
update:modelValue | [payload: string | number] |
Expose
When accessing the component via a template ref, you can use the following:
| Name | Type |
|---|---|
triggersRef | Ref<ComponentPublicInstance[]> |
Theme
Below is the theme configuration skeleton for the PTabs. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.
export default defineAppConfig({
pohon: {
tabs: {
slots: {
root: '',
list: '',
indicator: '',
trigger: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
label: '',
trailingBadge: '',
trailingBadgeSize: '',
content: ''
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
pill: {
list: '',
trigger: '',
indicator: ''
},
link: {
list: '',
indicator: '',
trigger: ''
}
},
orientation: {
horizontal: {
root: '',
list: '',
indicator: '',
trigger: ''
},
vertical: {
list: '',
indicator: ''
}
},
size: {
xs: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
sm: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
md: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
lg: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
xl: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
}
}
},
compoundVariants: [],
defaultVariants: {
color: 'primary',
variant: 'pill',
size: 'md'
}
}
}
};
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'
export default defineAppConfig({
pohon: {
tabs: {
slots: {
root: '',
list: '',
indicator: '',
trigger: '',
leadingIcon: '',
leadingAvatar: '',
leadingAvatarSize: '',
label: '',
trailingBadge: '',
trailingBadgeSize: '',
content: ''
},
variants: {
color: {
primary: '',
secondary: '',
success: '',
info: '',
warning: '',
error: '',
neutral: ''
},
variant: {
pill: {
list: '',
trigger: '',
indicator: ''
},
link: {
list: '',
indicator: '',
trigger: ''
}
},
orientation: {
horizontal: {
root: '',
list: '',
indicator: '',
trigger: ''
},
vertical: {
list: '',
indicator: ''
}
},
size: {
xs: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
sm: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
md: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
lg: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
},
xl: {
trigger: '',
leadingIcon: '',
leadingAvatarSize: ''
}
}
},
compoundVariants: [],
defaultVariants: {
color: 'primary',
variant: 'pill',
size: 'md'
}
}
}
};
Akar
With Pohon UI, you can achieve similar component functionality with less code and effort, as it comes with built-in styles mechanism and behaviors that are optimized for common use cases. Since it's using unocss-variants it adds a runtime cost, but it can be worth it if you prioritize development speed and ease of use over fine-grained control.
If this is a deal breaker for you, you can always stick to using Akar and build your own custom components on top of it.