Open In App

React Suite Modal Props

React Suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application.

In this article, we’ll learn about React Suite Modal Props. The modal can be different sizes which include extra-small, small, medium, large, and full page. The different modal props are discussed below.



Modal Props:

Syntax:



<Modal size="xs" open={open} 
       onClose={handleClose} 
       onEntered={handleEntered}>
  ...
</Modal>

Creating React Application And Installing Module:

Step 1: Create a React application using the given command:

npm create-react-app projectname

Step 2: After creating your project, move to it using the given command:

cd projectname

Step 3: Now Install the rsuite node package using the given command:

npm install rsuite

Project Structure: Now your project structure should look like the following:

 

Example 1: Below example demonstrates the open, onClose, size, and autofocus props of modal.




import "rsuite/dist/rsuite.min.css";
import { Button, Modal } from "rsuite";
import { useState } from "react";
  
export default function App() {
    const [open, setOpen] = useState(false);
    const handleOpen = () => setOpen(true);
    const handleClose = () => setOpen(false);
  
    return (
        <center>
            <div>
                <h2>GeeksforGeeks</h2>
                <h4 style={{ color: "green" }}>
                    React Suite Modal Props
                </h4>
  
                <div style={{ marginTop: 20, width: 340 }}>
                    <Button onClick={handleOpen}>
                        Open
                    </Button>
                    <Modal open={open} 
                           onClose={handleClose} 
                           size="md" autoFocus>
                        <Modal.Header>
                            GeeksforGeeks
                        </Modal.Header>
                        <Modal.Body>
                            <p>
                              Welcome to GeeksforGeeks. Find all 
                              computer science content at one place.
                            </p>
                        </Modal.Body>
                        <Modal.Footer>
                            <Button onClick={handleClose} 
                                    appearance="primary">
                                Ok
                            </Button>
                            <Button onClick={handleClose} 
                                    appearance="subtle">
                                Close
                            </Button>
                        </Modal.Footer>
                    </Modal>
                </div>
            </div>
        </center>
    );
}

Output:

 

Example 2: Below example demonstrates the backdrop and role props of the modal.




import "rsuite/dist/rsuite.min.css";
import { Button, Modal } from "rsuite";
import { useState } from "react";
  
export default function App() {
    const [open, setOpen] = useState(false);
    const handleOpen = () => setOpen(true);
    const handleClose = () => setOpen(false);
  
    return (
        <center>
            <div>
                <h2>GeeksforGeeks</h2>
                <h4 style={{ color: "green" }}>
                    React Suite Modal Props
                </h4>
  
                <div style={{ marginTop: 20, width: 340 }}>
                    <Button onClick={handleOpen}>
                        Open
                    </Button>
                    <Modal open={open} onClose={handleClose} 
                           size="md" backdrop={false
                           role="alertdialog">
                        <Modal.Header>
                            GeeksforGeeks
                        </Modal.Header>
                        <Modal.Body>
                            <p>
                              Hi! Welcome to Computer 
                              Science portal.
                            </p>
                        </Modal.Body>
                        <Modal.Footer>
                            <Button onClick={handleClose} 
                                    appearance="primary">
                                Ok
                            </Button>
                            <Button onClick={handleClose} 
                                    appearance="subtle">
                                Cancel
                            </Button>
                        </Modal.Footer>
                    </Modal>
                </div>
            </div>
        </center>
    );
}

Output:

 

Reference: https://rsuitejs.com/components/modal/#props


Article Tags :