Command palette

@yasinsensoy/web

Web · Components

Tabs

Tabs switching between several views in the same area.

5 exports

Live example

Preview

General settings go here.

Code

import { Tabs, Genel, Badge, Bildirimler, G } from "@yasinsensoy/web";

<Tabs defaultValue="Genel"
  items={[
    { value: "Genel", label: "Genel", icon: "settings", tooltip: "Open General settings", content: <Genel /> },
    { value: "Bildirimler", label: "Bildirimler", icon: "mail", badge: <Badge size="sm">3</Badge>, tooltip: "Open Notifications settings", content: <Bildirimler /> },
    { value: "Güvenlik", label: "Güvenlik", icon: "user", disabled: true, tooltip: "You don't have permission for this tab", content: <Güvenlik /> },
  ]}
/>

Events

  1. Events appear here when you interact with the preview.

Import

import { Tabs } from "@yasinsensoy/web";

Tabs

componentClient component

Tabs switching between several views in the same area. Tabs are given with the items array; buttons and panels are rendered automatically.

  • Keyboard: arrow keys move between tabs and select them, Home/End go to the first and last tab. The tab list is a single Tab stop.
  • Mobile: If the tabs don't fit, the list scrolls horizontally (hidden scrollbar, snapping) and the selected tab is brought into view automatically.
  • Unselected panels aren't removed from the DOM but hidden with hidden; so form state inside them is kept and find in page works.
  • If you only need the tab buttons (e.g. the content is elsewhere), omit content and use onValueChange.
Tabs({ items, value, defaultValue, onValueChange, orientation, variant: variantProp, effect, fullWidth, label, classNames, className, ...props }: TabsProps): JSX.Element

Examples

<Tabs items={[
  { value: "account", label: "Account", icon: "user", content: <Account /> },
  { value: "password", label: "Password", content: <Password /> },
  { value: "billing", label: "Billing", badge: <Badge>2</Badge>, content: <Billing /> },
]} />

<Tabs variant="line" value={tab} onValueChange={setTab} items={…} />

TabItem

interface

A tab inside Tabs.

NameTypeDescription
valuestringUnique value of the tab.
labelReactNodeText shown on the tab button.
icon?IconPropIcon before the label: name or element.
badge?ReactNodeSmall content after the label (e.g. a count badge).
content?ReactNodeContent shown while the tab is selected.
disabled?booleanCan't be selected.
tooltip?TooltipPropTooltip shown when hovering the tab or focusing it with the keyboard (e.g. for icon-only tabs or the reason a tab is disabled). See TooltipProp.

Look of the tabs.

  • pill: the selected tab looks like a white card on a gray background.
  • line: a line under the selected tab.
type TabsVariant = "pill" | "line"

Classes that can be passed to the inner parts of Tabs.

NameTypeDescription
list?stringList of tab buttons.
tab?stringEach tab button.
panel?stringEach content panel.

TabsProps

interface

Props of the Tabs component.

Extends: Omit<ComponentProps<"div">, "defaultValue" | "onChange" | "children">

NameTypeDefaultDescription
itemsreadonly TabItem[]Tabs.
value?stringValue of the selected tab in controlled use.
defaultValue?stringInitially selected tab in uncontrolled use. If omitted, the first selectable tab is selected.
onValueChange?(value: string) => voidCalled when the selected tab changes.
orientation?"horizontal" | "vertical""horizontal"Layout of the tabs and direction of the arrow keys.
variant?TabsVariant | CustomVariant<"tabs">"pill"Look: built-in (TabsVariant) or a custom look added with defineAppearance (its classes are added to the tab list; use [&_[role=tab]]:… for tabs). If omitted, UIProvider appearance.defaults.tabs.variant.
effect?EffectPropEffect of each tab button (e.g. "ripple", "shine"). If omitted, UIProvider appearance.defaults.tabs.effect. See BuiltinEffect.
fullWidth?booleanTabs share the full width of the list equally.
label?stringScreen reader name of the tab list.
classNames?TabsClassNamesClasses added to the inner parts.