tabs-underlined.tsx
Overview
The tabs-underlined.tsx file defines a set of React components that provide a styled tab interface using the Radix UI Tabs primitive (@radix-ui/react-tabs). It wraps the Radix Tabs components to apply consistent styling, theming, and convenient props forwarding. This file is focused on creating a visually underlined tabs UI pattern with enhanced accessibility and interaction state styling.
The components exported are:
Tabs— The root container managing tab state.TabsList— The container for the tab triggers (tab buttons).TabsTrigger— The individual tab button.TabsContent— The content panel corresponding to each tab.
These components are designed to be composable and customizable via class names and props, while encapsulating complex styling and accessibility concerns.
Components and API
1. Tabs
Purpose:
Acts as the root container for the tab interface. It manages the current active tab and provides context for child tab components.
Props:
Accepts all props from TabsPrimitive.Root (Radix UI Tabs root component), plus an optional className for styling.
className?: string— Additional CSS classes to customize the tabs root container....props— Other Radix Tabs root props such asdefaultValue,value,onValueChange, etc.
Returns:
A TabsPrimitive.Root React element with default flex column layout and gap styling, merged with any additional classes.
Usage Example:
<Tabs defaultValue="tab1">
<TabsList>
<TabsTrigger value="tab1">Tab 1</TabsTrigger>
<TabsTrigger value="tab2">Tab 2</TabsTrigger>
</TabsList>
<TabsContent value="tab1">Content for Tab 1</TabsContent>
<TabsContent value="tab2">Content for Tab 2</TabsContent>
</Tabs>
2. TabsList
Purpose:
Serves as the container for all tab triggers/buttons. It visually groups tab buttons and applies styling for the tab list.
Props:
Accepts all props from TabsPrimitive.List plus an optional className.
className?: string— Additional CSS classes for styling the tab list container....props— Other Radix Tabs list props.
Returns:
A styled TabsPrimitive.List element with background, padding, rounded corners, and inline-flex layout.
3. TabsTrigger
Purpose:
Represents an individual tab button that users can click or navigate to select a tab.
Props:
Accepts all props from TabsPrimitive.Trigger plus an optional className.
className?: string— Additional CSS classes to customize the tab trigger appearance....props— Other Radix Tabs trigger props such asvalue(required),disabled, etc.
Returns:
A styled TabsPrimitive.Trigger element with dynamic styles reflecting interaction states:
Active tab: changes background, border, and text color.
Focus-visible: shows ring/focus outlines.
Disabled: reduces opacity and disables pointer events.
Transitions on color and box-shadow.
Supports embedded SVG icons with size and pointer events adjustments.
4. TabsContent
Purpose:
Displays the content associated with a specific tab. Only the active tab’s content is shown.
Props:
Accepts all props from TabsPrimitive.Content plus an optional className.
className?: string— Additional CSS classes for the content panel....props— Other Radix Tabs content props, includingvalueto match the tab.
Returns:
A TabsPrimitive.Content element with flex-grow and no outline by default.
Implementation Details
Styling: Uses utility-first CSS classes (likely Tailwind CSS) combined with a
cnfunction (a classnames utility) to merge static and dynamic class names.Accessibility: Built on Radix UI Tabs, which provides keyboard navigation, ARIA attributes, and proper tab semantics by default.
Data attributes: Adds
data-slotattributes for each component (tabs,tabs-list,tabs-trigger,tabs-content), which can be useful for targeting in testing or styling.Reusability: Components accept all native Radix props and
className, enabling flexibility and customization.Dark mode support: Uses CSS classes that switch styles based on dark mode.
Interaction with Other Parts of the Application
Relies on the
@radix-ui/react-tabslibrary for core tab logic and accessibility infrastructure.Uses a utility function
cnfrom@/lib/utilsto combine class names.Intended to be imported and used wherever tabbed navigation or content organization is required.
Likely interacts visually and functionally with other UI components styled similarly for a consistent design system.
Visual Diagram
componentDiagram
component Tabs {
+className?: string
+...props (TabsPrimitive.Root props)
}
component TabsList {
+className?: string
+...props (TabsPrimitive.List props)
}
component TabsTrigger {
+className?: string
+...props (TabsPrimitive.Trigger props)
}
component TabsContent {
+className?: string
+...props (TabsPrimitive.Content props)
}
Tabs <|-- TabsList : contains
TabsList <|-- TabsTrigger : contains (multiple)
Tabs <|-- TabsContent : contains (multiple)
Summary
The tabs-underlined.tsx file provides a clean, accessible, and customizable tabs UI using Radix UI primitives wrapped with utility-first styling. It abstracts away the complexity of managing tab state and accessibility while allowing easy integration and theming within larger React applications. This file is a key part of the UI toolkit for tabbed navigation or content sections.