React Tabs Component

15.7.0 · active · verified Tue Apr 21

rc-tabs is a foundational React UI component designed to provide a highly flexible and accessible tab interface. It is part of the `react-component` ecosystem, focusing on delivering core functionality without imposing specific styling, allowing developers to integrate it seamlessly into various design systems. The current stable version is 15.7.0, with regular updates that typically occur weekly or bi-weekly, addressing bug fixes, accessibility enhancements, and minor feature additions. Its key differentiators include built-in keyboard navigation for improved accessibility, extensive customization options via `prefixCls`, `className`, `style`, and `renderTabBar` props, and a commitment to being a lightweight, unstyled component. This makes `rc-tabs` an ideal choice for projects requiring a robust tab solution that prioritizes control over visual presentation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic `rc-tabs` setup with static content, keyboard navigation, custom styling, and an `onChange` callback, rendered using React 18's createRoot.

import Tabs from 'rc-tabs';
import React from 'react';
import ReactDOM from 'react-dom/client';

const callback = (key: string) => {
  console.log(`Active tab: ${key}`);
};

const items = [
  {
    key: '1',
    label: 'Google',
    children: (
      <div className="text-xl">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
      </div>
    ),
  },
  {
    key: '2',
    label: <p>Amazon</p>,
    children:
      'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...', 
    disabled: true,
  },
  {
    key: '3',
    label: <p>Twitter</p>,
    children: (
      <div>
        "There is no one who loves pain itself, who seeks after it and wants to have it, simply
        because it is pain..."
      </div>
    ),
  },
];

// Ensure a root element with id="root" exists in your public/index.html
const rootElement = document.getElementById('root');

if (rootElement) {
  const root = ReactDOM.createRoot(rootElement);
  root.render(
    <React.StrictMode>
      <Tabs
        tabPosition="bottom"
        items={items}
        defaultActiveKey="1"
        className="md:w-[70%] w-full mx-auto p-2 border-0"
        onChange={callback}
        style={{ color: 'yellow', border: '1px solid #eee', padding: 10 }}
      />
    </React.StrictMode>
  );
} else {
  console.error('Root element with id "root" not found in the document.');
}

view raw JSON →