Open In App

React Suite Dropdown Disabled State

Improve
Improve
Like Article
Like
Save
Share
Report

React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The dropdown component allows the user to provide navigation that uses a select picker if you want to select a value. 

React Suite Dropdown Disabled help to disable any item present in the dropdown menu. You can disable the entire component or disable individual options by configuring the disabled property.

Syntax:

<Dropdown title="GFG" >
      <Dropdown.Item disabled>Disabled</Dropdown.Item>
      <Dropdown.Item>Item B</Dropdown.Item>
      <Dropdown.Item>Item C</Dropdown.Item>
 </Dropdown>

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 rsuite

Project Structure: It will look like the following.

 

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. In this example,  we will learn how to disable only few items in the dropdown menu.

Javascript




import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import ButtonToolbar from 'rsuite/ButtonToolbar';
import 'rsuite/dist/rsuite.min.css';
  
import Link from '@mui/material/Link';
function App() {
    return (
        <div>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>React Suite Dropdown Disabled State</h3>
            <h6 style={{ color: 'red' }}>
                Only few Dropdown items are disabled
            </h6>
              
            <ButtonToolbar>
                <Dropdown title="GeeksforGeeks" >
                    <Dropdown.Item disabled>Disabled</Dropdown.Item>
                    <Dropdown.Item >Item B</Dropdown.Item>
                    <Dropdown.Item >Item C</Dropdown.Item>
                    <Dropdown.Item disabled>Item D</Dropdown.Item>
                </Dropdown>
            </ButtonToolbar>
        </div>
    )
}
  
export default App;


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:

 

Example 2: In this example, we will learn how can we disable entire dropdown component.

Javascript




import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import ButtonToolbar from 'rsuite/ButtonToolbar';
import 'rsuite/dist/rsuite.min.css';
  
import Link from '@mui/material/Link';
function App() {
    return (
        <div>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>React Suite Dropdown Disabled State</h3>
            <h6 style={{ color: 'red' }}>
                Complete Dropdown component is disabled
            </h6>
              
            <ButtonToolbar>
                <Dropdown title="GeeksforGeeks" disabled>
                    <Dropdown.Item  >Item A</Dropdown.Item>
                    <Dropdown.Item >Item B</Dropdown.Item>
                    <Dropdown.Item >Item C</Dropdown.Item>
                    <Dropdown.Item >Item D</Dropdown.Item>
                </Dropdown>
            </ButtonToolbar>
        </div>
    )
}
  
export default App;


Output:

 

Reference: https://rsuitejs.com/components/dropdown/#disabled-state



Last Updated : 18 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads