Skip to content
Related Articles

Related Articles

Improve Article

ReactJS UI Ant Design Tabs Component

  • Last Updated : 01 Jun, 2021

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Tabs Component to used as Tabs make it easy to switch between different views. We can use the following approach in ReactJS to use the Ant Design Tabs Component.

Tabs Props:

  • activeKey: It is used to denote the current TabPane’s key.
  • addIcon: It is used for the customize add icon.
  • animated: It is used to indicate whether to change tabs with animation.
  • centered: It is used to centers the tabs.
  • defaultActiveKey: It is used to denote the initial active TabPane’s key.
  • hideAdd: It is used to indicate whether to hide plus icon or not.
  • moreIcon: It is used for the custom icon of ellipsis.
  • renderTabBar: It is used to replace the TabBar.
  • size: It is used to denote the tab bar size.
  • tabBarExtraContent: It is used to denote the extra content in the tab bar.
  • tabBarGutter: It is used to denote the gap between tabs.
  • tabBarStyle: It is used for the Tab bar-style object.
  • tabPosition: It is used to position the tabs.
  • type: It is used to denote the basic style of tabs.
  • onChange: It is a callback function that is triggered when the active tab is changed.
  • onEdit: It is a callback function that is triggered when the tab is added or removed.
  • onTabClick: It is a callback function that is triggered when the tab is clicked.
  • onTabScroll: It is a callback function that is triggered when the tab scrolls.

Tabs.TabPane Props:

  • closeIcon: It is used for customize close icon in TabPane’s head.
  • forceRender: It is used for the forced render of content in tabs.
  • key: It is used to denote the TabPane’s key.
  • tab: It is used to show text in TabPane’s head.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:



    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React from 'react'
import "antd/dist/antd.css";
import { Tabs } from 'antd';
  
const { TabPane } = Tabs;
  
export default function App() {
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design ConfigProvider Component</h4>
      <Tabs>
        <TabPane tab="Tab 1" key="1">
          1st TAB PANE Content
        </TabPane>
        <TabPane tab="Tab 2" key="2">
          2nd TAB PANE Content
        </TabPane>
        <TabPane tab="Tab 3" key="3">
          3rd TAB PANE Content
        </TabPane>
      </Tabs>
    </div>
  );
}

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/tabs/




My Personal Notes arrow_drop_up
Recommended Articles
Page :