Open In App

React MUI Tabs Navigation

React MUI is a UI library that provides fully-loaded components, bringing our own design system to our production-ready components. MUI is a user interface library that provides predefined and customizable React components for faster and easy web development, these Material-UI components are based on top of Material Design by Google.

In React MUI Tabs Navigation, we use tabs to navigate between different screens or pages, etc. Not only this, but it also organizes and allows navigation between a group of content that has the same hierarchy or is related.



Tabs Navigation Variants:

 



Syntax:

<Tabs>
    <Tab label="one" />
    <Tab label="two" />
</Tabs>
<TabPanel value={value}>...</TabPanel>
<TabPanel value={value}>...</TabPanel>

Creating React Project:

Step 1: To create a react app, you need to install react modules through the npm command.

npm create-react-app project name

Step 2: After creating your react project, move into the folder to perform different operations.

cd project name

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

npm install @mui/material @emotion/react @emotion/styled

Project Structure:

 

Step to Run Application: Open the terminal and type the following command.

npm start

Example 1: Below example demonstrates the React MUI colored tab with some disabled tabs.




import { Box, Tab, Tabs } from "@mui/material";
import React, { useState } from "react";
  
function App() {
  
    const [val, setVal] = useState('two');
  
    const handleTab = (e, newVal) => {
        setVal(newVal);
    };
  
    return (
        <center>
            <div>
                <h1 style={{ color: 'green' }}>
                    GeeksforGeeks</h1>
                <h2>React MUI Tabs Navigation</h2>
            </div>
            <div>
                <Box>
                    <Tabs
                        value={val}
                        onChange={handleTab}
                        textColor="primary"
                        indicatorColor="secondary"
                    >
                        <Tab value="one" label="Learn" />
                        <Tab value="two" label="Tutorials" />
                        <Tab value="three" label="Practice" 
                             disabled />
                        <Tab value="four" label="GBlog" />
                    </Tabs>
                </Box>
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Example 2: Below example demonstrates the React MUI scrollable tab with icons.




import { Box, Tab, Tabs } from "@mui/material";
import React, { useState } from "react";
import { Home, Code, Notes, Call, LocalLibrary, RssFeed }
    from "@mui/icons-material";
  
function App() {
  
    const [val, setVal] = useState('two');
  
    const handleTab = (e, newVal) => {
        setVal(newVal);
    };
  
    return (
        <center>
            <div>
                <h1 style={{ color: 'green' }}>
                    GeeksforGeeks</h1>
                <h2>React MUI Tabs Navigation</h2>
            </div>
            <div>
                <Box sx={{ maxWidth: 500 }}>
                    <Tabs
                        value={val}
                        onChange={handleTab}
                        textColor="primary"
                        indicatorColor="secondary"
                        variant="scrollable"
                    >
                        <Tab icon={<Home />}
                            value="one" label="Home" />
                        <Tab icon={<LocalLibrary />}
                            value="two" label="Learn" />
                        <Tab icon={<Notes />}
                            value="three" label="Tutorials" />
                        <Tab icon={<Code />}
                            value="four" label="Practice" />
                        <Tab icon={<RssFeed />}
                            value="five" label="GBlog" 
                                disabled />
                        <Tab icon={<Call />}
                            value="six" label="Contact" />
                    </Tabs>
                </Box>
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Reference: https://mui.com/material-ui/react-tabs/


Article Tags :