Open In App

React MUI Speed Dial 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 this article, we’ll be discussing React MUI Speed Dial Navigation. A speed dial navigation is in the form of a floating action button which is used to display three to six related actions.



Speed Dial Navigation Variants:

 



Syntax:

<SpeedDial>
    ...
</SpeedDial>

Creating React Project:

Step 1: To create a react app, 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 basic speed dial navigation.




import { SpeedDial, SpeedDialAction, 
    SpeedDialIcon } from "@mui/material";
import * as React from "react";
  
import NoteAddIcon from "@mui/icons-material/NoteAdd";
import SendIcon from "@mui/icons-material/Send";
import MyLocationIcon from "@mui/icons-material/MyLocation";
import EditIcon from "@mui/icons-material/Edit";
  
const spdActions = [
    { icon: <NoteAddIcon />, name: "New" },
    { icon: <EditIcon />, name: "Edit" },
    { icon: <MyLocationIcon />, name: "Location" },
    { icon: <SendIcon />, name: "Send" },
];
  
function App() {
    return (
        <center>
            <div>
                <h1 style={{ color: "green" }}>
                    GeeksforGeeks
                </h1>
                <h2>React MUI Speed dial navigation</h2>
            </div>
            <div style={{ width: "50%" }}>
                <SpeedDial
                    ariaLabel="basic"
                    sx={{ 
                        position: "absolute"
                        bottom: 30, 
                        right: 20 
                    }}
                    icon={<SpeedDialIcon />}
                >
                    {spdActions.map((action) => (
                        <SpeedDialAction
                            key={action.name}
                            icon={action.icon}
                            tooltipTitle={action.name}
                        />
                    ))}
                </SpeedDial>
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Example 2: Below example demonstrates the React MUI persistent action tooltips speed dial navigation.




import { SpeedDial, SpeedDialAction, 
    SpeedDialIcon } from "@mui/material";
import * as React from "react";
  
import NoteAddIcon from "@mui/icons-material/NoteAdd";
import SendIcon from "@mui/icons-material/Send";
import MyLocationIcon from "@mui/icons-material/MyLocation";
import EditIcon from "@mui/icons-material/Edit";
  
const spdActions = [
    { icon: <NoteAddIcon />, name: "New" },
    { icon: <EditIcon />, name: "Edit" },
    { icon: <MyLocationIcon />, name: "Location" },
    { icon: <SendIcon />, name: "Send" },
];
  
function App() {
    const [buttonOpen, setButtonOpen] = React.useState(false);
    const handleButtonOpen = () => setButtonOpen(true);
    const handleButtonClose = () => setButtonOpen(false);
  
    return (
        <center>
            <div>
                <h1 style={{ color: "green" }}>
                    GeeksforGeeks
                </h1>
                <h2>React MUI Speed dial navigation</h2>
            </div>
            <div style={{ width: "50%" }}>
                <SpeedDial
                    ariaLabel="basic"
                    sx={{ 
                        position: "absolute"
                        bottom: 30, 
                        right: 20 
                    }}
                    icon={<SpeedDialIcon />}
                    onClose={handleButtonClose}
                    onOpen={handleButtonOpen}
                    open={buttonOpen}
                >
                    {spdActions.map((action) => (
                        <SpeedDialAction
                            key={action.name}
                            icon={action.icon}
                            tooltipTitle={action.name}
                            tooltipOpen
                        />
                    ))}
                </SpeedDial>
            </div>
        </center>
    );
}
  
export default App;

Output:

 

Reference: https://mui.com/material-ui/react-speed-dial/


Article Tags :