Tabs
Discord-inspired tabs that switch between panels, with a line variant that underlines the active tab and a pill variant that fills it.
A tab group built on Radix Tabs in React and Reka UI Tabs in Vue. The primitive owns the behaviour; newt/ui owns the look. The panel is only rendered for the active tab, so a tab whose content is expensive does not cost anything until it is opened.
The default line variant draws a 2px --newt-text-brand bar under the active tab, over a 2px rail as wide as the list. The bar grows in when its tab opens. Hover brightens the label, and keyboard focus draws a 2px ring in --newt-focus-ring.
newt-tabsimport { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
export default function TabsDemo() {
return (
<Tabs defaultValue="one">
<TabsList>
<TabsTrigger value="one">Tab one</TabsTrigger>
<TabsTrigger value="two">Tab two</TabsTrigger>
<TabsTrigger value="three">Tab three</TabsTrigger>
</TabsList>
</Tabs>
)
}<script setup lang="ts">
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
</script>
<template>
<Tabs default-value="one">
<TabsList>
<TabsTrigger value="one">Tab one</TabsTrigger>
<TabsTrigger value="two">Tab two</TabsTrigger>
<TabsTrigger value="three">Tab three</TabsTrigger>
</TabsList>
</Tabs>
</template>Installation
npx newtui@latest add tabsnpx shadcn@latest add @newtui/tabsnpx shadcn-vue@latest add @newtui/tabspnpm dlx newtui@latest add tabspnpm dlx shadcn@latest add @newtui/tabspnpm dlx shadcn-vue@latest add @newtui/tabsyarn dlx newtui@latest add tabsyarn dlx shadcn@latest add @newtui/tabsyarn dlx shadcn-vue@latest add @newtui/tabsbunx newtui@latest add tabsbunx shadcn@latest add @newtui/tabsbunx shadcn-vue@latest add @newtui/tabsdeno run -A npm:newtui@latest add tabsdeno run -A npm:shadcn@latest add @newtui/tabsdeno run -A npm:shadcn-vue@latest add @newtui/tabsvlx newtui@latest add tabsvlx shadcn@latest add @newtui/tabsvlx shadcn-vue@latest add @newtui/tabsvp dlx newtui@latest add tabsvp dlx shadcn@latest add @newtui/tabsvp dlx shadcn-vue@latest add @newtui/tabsnubx newtui@latest add tabsnubx shadcn@latest add @newtui/tabsnubx shadcn-vue@latest add @newtui/tabsnlx newtui@latest add tabsnlx shadcn@latest add @newtui/tabsnlx shadcn-vue@latest add @newtui/tabsupx newtui@latest add tabsupx shadcn@latest add @newtui/tabsupx shadcn-vue@latest add @newtui/tabs- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install radix-ui class-variance-authoritypnpm add radix-ui class-variance-authorityyarn add radix-ui class-variance-authoritybun add radix-ui class-variance-authoritydeno add npm:radix-ui npm:class-variance-authorityvlt install radix-ui class-variance-authorityvp add radix-ui class-variance-authoritynub add radix-ui class-variance-authorityni radix-ui class-variance-authorityupm add radix-ui class-variance-authority- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
npm install reka-ui class-variance-authoritypnpm add reka-ui class-variance-authorityyarn add reka-ui class-variance-authoritybun add reka-ui class-variance-authoritydeno add npm:reka-ui npm:class-variance-authorityvlt install reka-ui class-variance-authorityvp add reka-ui class-variance-authoritynub add reka-ui class-variance-authorityni reka-ui class-variance-authorityupm add reka-ui class-variance-authority- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
"use client"
import { cva, type VariantProps } from "class-variance-authority"
import { Tabs as TabsPrimitive } from "radix-ui"
import * as React from "react"
import { cn } from "@/lib/utils"
/*
* Radix owns the behaviour: roving focus, arrow keys, Home and End, and the
* tab/panel ids that link each pair. Only the look is newt/ui's.
*/
const Tabs = TabsPrimitive.Root
/*
* A list whose triggers do not fit scrolls sideways, with its scrollbar
* hidden; a trigger that takes focus scrolls into view. A scroll box clips at
* its padding edge, so the list carries 4px of padding, and the same negative
* margin so the triggers still line up with the content around them: a focus
* ring stays whole. The `line` rail is a background, so it stays in place
* while the triggers scroll over it.
*/
const tabsListVariants = cva(
"box-border flex -m-[var(--newt-space-1)] overflow-x-auto p-[var(--newt-space-1)] [scroll-padding-inline:var(--newt-space-2)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
{
variants: {
variant: {
line: "w-[calc(100%+2*var(--newt-space-1))] gap-[var(--newt-space-8)] bg-[linear-gradient(var(--newt-border-subtle),var(--newt-border-subtle))] bg-[length:calc(100%-2*var(--newt-space-1))_2px] bg-[position:center_bottom_var(--newt-space-1)] bg-no-repeat",
pill: "w-fit max-w-[calc(100%+2*var(--newt-space-1))] gap-[var(--newt-space-2)]",
},
},
defaultVariants: { variant: "line" },
}
)
/*
* Leaving a hover is quick (`duration-instant`, ease-in); arriving is a little
* slower (`duration-base`, ease-out). In `line` each trigger draws its own
* 2px indicator in the brand text colour and grows it when it opens. The
* active pill is filled and edged with an inset shadow. The text size comes
* before the line height: `cn` drops a `leading-*` that comes before a text
* size class.
*/
const tabsTriggerVariants = cva(
"relative box-border inline-flex shrink-0 cursor-pointer select-none items-center justify-center gap-[var(--newt-space-2)] whitespace-nowrap border-0 bg-transparent font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] font-[number:var(--newt-font-weight-medium)] leading-[var(--newt-line-height-tight)] text-newt-text-muted transition-[color,background-color] duration-instant ease-newt-in hover:duration-base hover:ease-newt-out enabled:data-[state=inactive]:hover:text-newt-text-secondary data-[state=active]:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-focus-ring disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none",
{
variants: {
variant: {
line: "rounded-[var(--newt-radius-sm)] px-0 pb-[var(--newt-space-4)] pt-0 after:absolute after:bottom-0 after:end-0 after:start-0 after:h-[2px] after:scale-x-0 after:rounded-[var(--newt-radius-full)] after:bg-newt-text-brand after:opacity-0 after:transition-[transform,scale,opacity] after:duration-instant after:ease-newt-in data-[state=active]:after:scale-x-100 data-[state=active]:after:opacity-100 data-[state=active]:after:duration-base data-[state=active]:after:ease-newt-out motion-reduce:after:transition-none",
pill: "min-h-newt-control-sm rounded-[var(--newt-radius-full)] px-[var(--newt-space-3)] py-[var(--newt-space-1)] enabled:data-[state=inactive]:hover:bg-newt-bg-hover data-[state=active]:bg-newt-bg-active data-[state=active]:shadow-[inset_0_0_0_1px_var(--newt-border-strong)]",
},
},
defaultVariants: { variant: "line" },
}
)
type TabsVariant = NonNullable<VariantProps<typeof tabsListVariants>["variant"]>
/* The list tells its triggers which variant to draw. */
const TabsVariantContext = React.createContext<TabsVariant>("line")
type TabsListProps = React.ComponentPropsWithoutRef<
typeof TabsPrimitive.List
> & {
/** `line` draws a bar under the active tab; `pill` fills it. */
variant?: TabsVariant
}
const TabsList = React.forwardRef<
React.ComponentRef<typeof TabsPrimitive.List>,
TabsListProps
>(({ className, variant = "line", ...props }, ref) => (
<TabsVariantContext.Provider value={variant}>
<TabsPrimitive.List
ref={ref}
data-variant={variant}
className={cn(tabsListVariants({ variant }), className)}
{...props}
/>
</TabsVariantContext.Provider>
))
TabsList.displayName = "TabsList"
const TabsTrigger = React.forwardRef<
React.ComponentRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, onFocus, onBlur, onMouseDown, onMouseUp, ...props }, ref) => {
const variant = React.useContext(TabsVariantContext)
/*
* Radix focuses a trigger from script in its own `onMouseDown`, and Chrome
* then counts that focus as `:focus-visible`. The press marks itself here,
* just before Radix runs (a touch tap reaches it as the mousedown that
* follows the tap), so its focus does not scroll the page. The mark only
* stands for the primary button without Ctrl, which is when Radix focuses,
* and the mouseup or a blur clears it when no focus follows.
*/
const pressed = React.useRef(false)
return (
<TabsPrimitive.Trigger
ref={ref}
className={cn(tabsTriggerVariants({ variant }), className)}
onMouseDown={(event) => {
onMouseDown?.(event)
pressed.current =
!event.defaultPrevented && event.button === 0 && !event.ctrlKey
}}
onMouseUp={(event) => {
pressed.current = false
onMouseUp?.(event)
}}
onBlur={(event) => {
pressed.current = false
onBlur?.(event)
}}
onFocus={(event) => {
const fromPress = pressed.current
pressed.current = false
onFocus?.(event)
/*
* The browser leaves a half-hidden trigger where it is when it takes
* focus; scroll the list just far enough to show all of it. Only for
* keyboard focus, so a press with the mouse does not move the page,
* and not when your own `onFocus` prevented the default.
*/
if (
!event.defaultPrevented &&
!fromPress &&
event.currentTarget.matches(":focus-visible")
)
event.currentTarget.scrollIntoView({
block: "nearest",
inline: "nearest",
})
}}
{...props}
/>
)
})
TabsTrigger.displayName = "TabsTrigger"
const TabsContent = React.forwardRef<
React.ComponentRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn(
"mt-[var(--newt-space-4)] rounded-[var(--newt-radius-sm)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-focus-ring",
className
)}
{...props}
/>
))
TabsContent.displayName = "TabsContent"
export {
Tabs,
TabsList,
TabsTrigger,
TabsContent,
tabsListVariants,
tabsTriggerVariants,
type TabsListProps,
type TabsVariant,
}<script setup lang="ts">
import {
TabsRoot,
useForwardPropsEmits,
type TabsRootEmits,
type TabsRootProps,
} from "reka-ui"
/*
* Reka owns the behaviour: roving focus, arrow keys, Home and End, and the
* tab/panel ids that link each pair. Only the look is newt/ui's.
*/
const props = defineProps<TabsRootProps>()
const emits = defineEmits<TabsRootEmits>()
const forwarded = useForwardPropsEmits(props, emits)
</script>
<template>
<TabsRoot v-bind="forwarded">
<slot />
</TabsRoot>
</template><script setup lang="ts">
import { TabsList, useForwardProps, type TabsListProps } from "reka-ui"
import { provide, toRef, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
import { type TabsVariant, tabsListVariants, tabsVariantKey } from "."
const {
class: className,
variant = "line",
...delegated
} = defineProps<
TabsListProps & {
class?: HTMLAttributes["class"]
/** `line` draws a bar under the active tab; `pill` fills it. */
variant?: TabsVariant
}
>()
/*
* Forward only the props the caller set: Vue turns an absent boolean prop
* into `false`, which would switch off Reka's `loop` default.
*/
const forwarded = useForwardProps(delegated)
provide(
tabsVariantKey,
toRef(() => variant)
)
</script>
<template>
<TabsList
v-bind="forwarded"
:data-variant="variant"
:class="cn(tabsListVariants({ variant }), className)"
>
<slot />
</TabsList>
</template><script setup lang="ts">
import { TabsTrigger, useForwardProps, type TabsTriggerProps } from "reka-ui"
import { inject, ref, type HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
import { tabsTriggerVariants, tabsVariantKey } from "."
const { class: className, ...delegated } = defineProps<
TabsTriggerProps & { class?: HTMLAttributes["class"] }
>()
const emit = defineEmits<{ focus: [event: FocusEvent] }>()
const forwarded = useForwardProps(delegated)
const variant = inject(tabsVariantKey, ref("line"))
/*
* The browser leaves a half-hidden trigger where it is when it takes focus;
* scroll the list just far enough to show all of it. Only for keyboard
* focus, so a press with the mouse does not move the page, and not when your
* own `@focus` handler, which runs first, prevented the default.
*/
const reveal = (event: FocusEvent) => {
/*
* A focus event is not cancelable, so `preventDefault()` leaves
* `defaultPrevented` false. The call is recorded here instead, as React's
* synthetic event does.
*/
let prevented = false
const preventDefault = event.preventDefault.bind(event)
Object.defineProperty(event, "preventDefault", {
configurable: true,
value: () => {
prevented = true
preventDefault()
},
})
emit("focus", event)
const trigger = event.currentTarget
if (
!prevented &&
trigger instanceof HTMLElement &&
trigger.matches(":focus-visible")
)
trigger.scrollIntoView({ block: "nearest", inline: "nearest" })
}
</script>
<template>
<TabsTrigger
v-bind="forwarded"
:class="cn(tabsTriggerVariants({ variant }), className)"
@focus="reveal"
>
<slot />
</TabsTrigger>
</template><script setup lang="ts">
import { TabsContent, type TabsContentProps } from "reka-ui"
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
const { class: className, ...delegated } = defineProps<
TabsContentProps & { class?: HTMLAttributes["class"] }
>()
</script>
<template>
<TabsContent
v-bind="delegated"
:class="
cn(
'mt-[var(--newt-space-4)] rounded-[var(--newt-radius-sm)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-focus-ring',
className
)
"
>
<slot />
</TabsContent>
</template>import { cva, type VariantProps } from "class-variance-authority"
import type { InjectionKey, Ref } from "vue"
export { default as Tabs } from "./Tabs.vue"
export { default as TabsList } from "./TabsList.vue"
export { default as TabsTrigger } from "./TabsTrigger.vue"
export { default as TabsContent } from "./TabsContent.vue"
/*
* A list whose triggers do not fit scrolls sideways, with its scrollbar
* hidden; a trigger that takes focus scrolls into view. A scroll box clips at
* its padding edge, so the list carries 4px of padding, and the same negative
* margin so the triggers still line up with the content around them: a focus
* ring stays whole. The `line` rail is a background, so it stays in place
* while the triggers scroll over it.
*/
export const tabsListVariants = cva(
"box-border flex -m-[var(--newt-space-1)] overflow-x-auto p-[var(--newt-space-1)] [scroll-padding-inline:var(--newt-space-2)] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
{
variants: {
variant: {
line: "w-[calc(100%+2*var(--newt-space-1))] gap-[var(--newt-space-8)] bg-[linear-gradient(var(--newt-border-subtle),var(--newt-border-subtle))] bg-[length:calc(100%-2*var(--newt-space-1))_2px] bg-[position:center_bottom_var(--newt-space-1)] bg-no-repeat",
pill: "w-fit max-w-[calc(100%+2*var(--newt-space-1))] gap-[var(--newt-space-2)]",
},
},
defaultVariants: { variant: "line" },
}
)
/*
* Leaving a hover is quick (`duration-instant`, ease-in); arriving is a little
* slower (`duration-base`, ease-out). In `line` each trigger draws its own
* 2px indicator in the brand text colour and grows it when it opens. The
* active pill is filled and edged with an inset shadow. The text size comes
* before the line height: `cn` drops a `leading-*` that comes before a text
* size class.
*/
export const tabsTriggerVariants = cva(
"relative box-border inline-flex shrink-0 cursor-pointer select-none items-center justify-center gap-[var(--newt-space-2)] whitespace-nowrap border-0 bg-transparent font-[family-name:var(--newt-font-sans)] text-[length:var(--newt-font-size-sm)] font-[number:var(--newt-font-weight-medium)] leading-[var(--newt-line-height-tight)] text-newt-text-muted transition-[color,background-color] duration-instant ease-newt-in hover:duration-base hover:ease-newt-out enabled:data-[state=inactive]:hover:text-newt-text-secondary data-[state=active]:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-focus-ring disabled:cursor-not-allowed disabled:opacity-50 motion-reduce:transition-none",
{
variants: {
variant: {
line: "rounded-[var(--newt-radius-sm)] px-0 pb-[var(--newt-space-4)] pt-0 after:absolute after:bottom-0 after:end-0 after:start-0 after:h-[2px] after:scale-x-0 after:rounded-[var(--newt-radius-full)] after:bg-newt-text-brand after:opacity-0 after:transition-[transform,scale,opacity] after:duration-instant after:ease-newt-in data-[state=active]:after:scale-x-100 data-[state=active]:after:opacity-100 data-[state=active]:after:duration-base data-[state=active]:after:ease-newt-out motion-reduce:after:transition-none",
pill: "min-h-newt-control-sm rounded-[var(--newt-radius-full)] px-[var(--newt-space-3)] py-[var(--newt-space-1)] enabled:data-[state=inactive]:hover:bg-newt-bg-hover data-[state=active]:bg-newt-bg-active data-[state=active]:shadow-[inset_0_0_0_1px_var(--newt-border-strong)]",
},
},
defaultVariants: { variant: "line" },
}
)
/** `line` draws a bar under the active tab; `pill` fills it. */
export type TabsVariant = NonNullable<
VariantProps<typeof tabsListVariants>["variant"]
>
/** The list tells its triggers which variant to draw. */
export const tabsVariantKey: InjectionKey<Readonly<Ref<TabsVariant>>> =
Symbol("newt-tabs-variant")Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Tabs to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Tabs to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Tabs } from "@/components/ui/tabs"
export function Example() {
return <Tabs />
}<script setup lang="ts">
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"
</script>
<template>
<Tabs />
</template>Examples
Pill
Set variant="pill" on TabsList to fill the active tab with a pill, edged with a 1px --newt-border-strong line, instead of underlining it. The list then is only as wide as its tabs. The same prop has the same name in React and Vue.
newt-tabsimport { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
/*
* `variant="pill"` on the list fills the active tab instead of underlining
* it, as in a friends list header.
*/
export default function TabsPillDemo() {
return (
<Tabs defaultValue="online">
<TabsList variant="pill" aria-label="Friends">
<TabsTrigger value="online">Online</TabsTrigger>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="pending">Pending</TabsTrigger>
<TabsTrigger value="blocked" disabled>
Blocked
</TabsTrigger>
</TabsList>
</Tabs>
)
}<script setup lang="ts">
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
/*
* `variant="pill"` on the list fills the active tab instead of underlining
* it, as in a friends list header.
*/
</script>
<template>
<Tabs default-value="online">
<TabsList variant="pill" aria-label="Friends">
<TabsTrigger value="online">Online</TabsTrigger>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="pending">Pending</TabsTrigger>
<TabsTrigger value="blocked" disabled>Blocked</TabsTrigger>
</TabsList>
</Tabs>
</template>Controlled
Hold the active tab yourself with value and onValueChange in React, or v-model in Vue, when something outside the list has to read it or change it. Here the link below the tabs switches to Pending.
newt-tabs"use client"
import * as React from "react"
import { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
const TABS = [
{ value: "online", label: "Online", summary: "4 friends online" },
{ value: "all", label: "All", summary: "27 friends" },
{ value: "pending", label: "Pending", summary: "2 pending requests" },
]
/*
* The active tab lives in the parent, so anything else on the page can read it
* — or change it, as the button under the list does.
*/
export default function TabsControlledDemo() {
const [tab, setTab] = React.useState("online")
return (
<div className="flex flex-col items-start gap-3">
<Tabs value={tab} onValueChange={setTab}>
<TabsList>
{TABS.map((item) => (
<TabsTrigger key={item.value} value={item.value}>
{item.label}
</TabsTrigger>
))}
</TabsList>
</Tabs>
<p className="text-sm text-newt-text-secondary">
{TABS.find((item) => item.value === tab)?.summary}
</p>
<button
type="button"
className="cursor-pointer border-0 bg-transparent p-0 text-[13px] font-medium text-newt-text-link hover:underline"
onClick={() => setTab("pending")}
>
Review pending requests
</button>
</div>
)
}<script setup lang="ts">
import { computed, ref } from "vue"
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
/*
* The active tab lives in the parent, so anything else on the page can read it
* — or change it, as the button under the list does.
*/
const tab = ref("online")
const tabs = [
{ value: "online", label: "Online", summary: "4 friends online" },
{ value: "all", label: "All", summary: "27 friends" },
{ value: "pending", label: "Pending", summary: "2 pending requests" },
]
const summary = computed(
() => tabs.find((item) => item.value === tab.value)?.summary
)
</script>
<template>
<div class="flex flex-col items-start gap-3">
<Tabs v-model="tab">
<TabsList>
<TabsTrigger v-for="item in tabs" :key="item.value" :value="item.value">
{{ item.label }}
</TabsTrigger>
</TabsList>
</Tabs>
<p class="text-sm text-newt-text-secondary">{{ summary }}</p>
<button
type="button"
class="cursor-pointer border-0 bg-transparent p-0 text-[13px] font-medium text-newt-text-link hover:underline"
@click="tab = 'pending'"
>
Review pending requests
</button>
</div>
</template>With panels
Tabs shares the state, TabsList holds the triggers, and each TabsContent sits beside the list, not inside it. Each TabsContent renders only while its trigger is active.
newt-tabsimport {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "@/registry/bases/newt/ui/tabs"
/*
* `Tabs` shares the state, `TabsList` holds the triggers, and each
* `TabsContent` is a sibling of the list. Radix links every trigger to its
* panel with `aria-controls` and `aria-labelledby`.
*/
export default function TabsPanelsDemo() {
return (
<Tabs defaultValue="overview" className="w-full max-w-sm">
<TabsList>
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="roles">Roles</TabsTrigger>
<TabsTrigger value="invites">Invites</TabsTrigger>
</TabsList>
<TabsContent
value="overview"
className="text-sm leading-5 text-newt-text-secondary"
>
Rename the server, change its icon and pick the channel new members land
in.
</TabsContent>
<TabsContent
value="roles"
className="text-sm leading-5 text-newt-text-secondary"
>
Three roles. Drag one above another to give it precedence.
</TabsContent>
<TabsContent
value="invites"
className="text-sm leading-5 text-newt-text-secondary"
>
One active invite link, used 12 times, expiring in 6 days.
</TabsContent>
</Tabs>
)
}<script setup lang="ts">
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from "~~/registry/bases/newt/ui/tabs"
/*
* `Tabs` shares the state, `TabsList` holds the triggers, and each
* `TabsContent` is a sibling of the list. Reka links every trigger to its
* panel with `aria-controls` and `aria-labelledby`.
*/
</script>
<template>
<Tabs default-value="overview" class="w-full max-w-sm">
<TabsList>
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="roles">Roles</TabsTrigger>
<TabsTrigger value="invites">Invites</TabsTrigger>
</TabsList>
<TabsContent
value="overview"
class="text-sm leading-5 text-newt-text-secondary"
>
Rename the server, change its icon and pick the channel new members land
in.
</TabsContent>
<TabsContent
value="roles"
class="text-sm leading-5 text-newt-text-secondary"
>
Three roles. Drag one above another to give it precedence.
</TabsContent>
<TabsContent
value="invites"
class="text-sm leading-5 text-newt-text-secondary"
>
One active invite link, used 12 times, expiring in 6 days.
</TabsContent>
</Tabs>
</template>Disabled tab
A trigger is a native button and takes disabled. The trigger dims itself and leaves the arrow-key order.
newt-tabsimport { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
/*
* `disabled` on a trigger takes it out of the arrow-key order and the tab
* order; the trigger already dims itself.
*/
export default function TabsDisabledDemo() {
return (
<Tabs defaultValue="messages">
<TabsList>
<TabsTrigger value="messages">Messages</TabsTrigger>
<TabsTrigger value="threads">Threads</TabsTrigger>
<TabsTrigger value="insights" disabled>
Insights
</TabsTrigger>
</TabsList>
</Tabs>
)
}<script setup lang="ts">
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
/*
* `disabled` on a trigger takes it out of the arrow-key order and the tab
* order; the trigger already dims itself.
*/
</script>
<template>
<Tabs default-value="messages">
<TabsList>
<TabsTrigger value="messages">Messages</TabsTrigger>
<TabsTrigger value="threads">Threads</TabsTrigger>
<TabsTrigger value="insights" disabled>Insights</TabsTrigger>
</TabsList>
</Tabs>
</template>Many tabs
The list is never wider than its container. If the triggers do not fit, the list scrolls sideways and the triggers keep their width. The scrollbar is hidden, so the list keeps its height. An arrow key moves focus to the next trigger, and the browser scrolls that trigger into view with its focus ring.
newt-tabsimport { Tabs, TabsList, TabsTrigger } from "@/registry/bases/newt/ui/tabs"
const TABS = ["Members", "Media", "Files", "Links", "Threads", "Pins"]
/*
* Six tabs in a narrow panel. The list scrolls sideways instead of clipping,
* and an arrow key scrolls the focused tab into view.
*/
export default function TabsOverflowDemo() {
return (
<div className="w-full max-w-[280px]">
<Tabs defaultValue="members">
<TabsList aria-label="Channel details">
{TABS.map((tab) => (
<TabsTrigger key={tab} value={tab.toLowerCase()}>
{tab}
</TabsTrigger>
))}
</TabsList>
</Tabs>
</div>
)
}<script setup lang="ts">
import { Tabs, TabsList, TabsTrigger } from "~~/registry/bases/newt/ui/tabs"
/*
* Six tabs in a narrow panel. The list scrolls sideways instead of clipping,
* and an arrow key scrolls the focused tab into view.
*/
const tabs = ["Members", "Media", "Files", "Links", "Threads", "Pins"]
</script>
<template>
<div class="w-full max-w-[280px]">
<Tabs default-value="members">
<TabsList aria-label="Channel details">
<TabsTrigger v-for="tab in tabs" :key="tab" :value="tab.toLowerCase()">
{{ tab }}
</TabsTrigger>
</TabsList>
</Tabs>
</div>
</template>API reference
Tabs
value?string
The active tab, when you control it.
stringdefaultValue?string
The tab active on first render, when you do not.
stringonValueChange?(value: string) => void
Called with the tab that was activated.
(value: string) => voidTabs
orientation?"horizontal" | "vertical"
Which arrow keys move between triggers.
"horizontal" | "vertical""horizontal"activationMode?"automatic" | "manual"
`automatic` opens a tab when it takes focus; `manual` waits for Enter or Space.
"automatic" | "manual""automatic"TabsList
variant?"line" | "pill"
`line` draws a bar under the active tab; `pill` fills the active tab. The triggers in the list follow it.
"line" | "pill""line"TabsTrigger
value?string
Which panel this trigger opens.
stringdisabled?boolean
Skipped by arrow-key navigation.
booleanfalseTabsContent
value?string
Which trigger opens this panel.
stringEvery part also accepts the native attributes of the element it renders, and a className that is merged rather than replaced.
Accessibility
It implements the tabs pattern: TabsList is the role="tablist", aria-selected on the triggers, aria-controls and aria-labelledby linking each pair. Only the active trigger is in the tab order; Left and Right move between triggers, Home and End jump to the ends. Pass dir="rtl" to Tabs in a right-to-left layout, and Left and Right swap.
- A focused trigger draws a 2px
--newt-focus-ringoutline 2px outside its edge. The list keeps 4px of padding, so the ring is not cut off when the list scrolls. - Screen readers get the active tab from
aria-selected, not from how it looks. - In
line, the active tab has a 2px bar in--newt-text-brand. In the default palette the bar measures at least 4.5:1 against--newt-bg-surfacein both themes, and 4.63:1 (dark) and 3.88:1 (light) against the rail under it. The active label also turns--newt-text-primary. - In
pill, the active tab is filled with--newt-bg-activeand edged with a 1px inset--newt-border-strongline. Both are faint: in the default palette the edge measures 1.98:1 (dark) and 1.63:1 (light) against--newt-bg-surface. The active label also turns--newt-text-primary. Where the active tab must stand out on its own, useline. - A disabled trigger is dimmed to half opacity and does not react to hover.
- Under
prefers-reduced-motion: reduce, the indicator and the colours change without a transition. - In the HTML version,
tabs.jsgives the same keyboard behaviour: it moves the tab order with the active tab and shows the panel a tab names inaria-controls.
Tokens
Tabs reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-tabs.
--newt-space-8--newt-space-1--newt-space-2--newt-border-subtle--newt-space-4--newt-radius-sm--newt-text-muted--newt-font-sans--newt-font-size-sm--newt-font-weight-medium--newt-line-height-tight--newt-duration-instant--newt-ease-in--newt-radius-full--newt-text-brand--newt-text-secondary--newt-duration-base--newt-ease-out--newt-text-primary--newt-focus-ring--newt-text-link--newt-control-sm--newt-space-3--newt-bg-hover--newt-bg-active--newt-border-strong