Socket
Socket
Sign inDemoInstall

@radix-ui/react-tabs

Package Overview
Dependencies
Maintainers
6
Versions
192
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-tabs


Version published
Weekly downloads
1.4M
increased by0.28%
Maintainers
6
Weekly downloads
 
Created

What is @radix-ui/react-tabs?

@radix-ui/react-tabs is a React component library for creating accessible and customizable tab interfaces. It provides a set of components and hooks to build tabbed navigation systems with ease, ensuring accessibility and flexibility.

What are @radix-ui/react-tabs's main functionalities?

Basic Tabs

This code demonstrates a basic tab interface with two tabs. The `Tabs`, `TabsList`, `TabsTrigger`, and `TabsContent` components are used to create a simple tabbed navigation system.

import { Tabs, TabsList, TabsTrigger, TabsContent } from '@radix-ui/react-tabs';

function BasicTabs() {
  return (
    <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>
  );
}

Controlled Tabs

This code demonstrates a controlled tab interface where the active tab is managed by the component's state. The `value` and `onValueChange` props are used to control the active tab.

import { useState } from 'react';
import { Tabs, TabsList, TabsTrigger, TabsContent } from '@radix-ui/react-tabs';

function ControlledTabs() {
  const [value, setValue] = useState('tab1');

  return (
    <Tabs value={value} onValueChange={setValue}>
      <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>
  );
}

Custom Styling

This code demonstrates how to apply custom styling to the tab components. By adding class names to the `TabsList`, `TabsTrigger`, and `TabsContent` components, you can style them using CSS.

import { Tabs, TabsList, TabsTrigger, TabsContent } from '@radix-ui/react-tabs';
import './CustomTabs.css';

function CustomTabs() {
  return (
    <Tabs defaultValue="tab1">
      <TabsList className="custom-tabs-list">
        <TabsTrigger className="custom-tabs-trigger" value="tab1">Tab 1</TabsTrigger>
        <TabsTrigger className="custom-tabs-trigger" value="tab2">Tab 2</TabsTrigger>
      </TabsList>
      <TabsContent className="custom-tabs-content" value="tab1">Content for Tab 1</TabsContent>
      <TabsContent className="custom-tabs-content" value="tab2">Content for Tab 2</TabsContent>
    </Tabs>
  );
}

Other packages similar to @radix-ui/react-tabs

FAQs

Package last updated on 10 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc