Thursday, December 26, 2024
Google search engine
HomeLanguagesReact Suite Dropdown Disabled State

React Suite Dropdown Disabled State

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' }}>
                neveropen
            </h1>
            <h3>React Suite Dropdown Disabled State</h3>
            <h6 style={{ color: 'red' }}>
                Only few Dropdown items are disabled
            </h6>
              
            <ButtonToolbar>
                <Dropdown title="neveropen" >
                    <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' }}>
                neveropen
            </h1>
            <h3>React Suite Dropdown Disabled State</h3>
            <h6 style={{ color: 'red' }}>
                Complete Dropdown component is disabled
            </h6>
              
            <ButtonToolbar>
                <Dropdown title="neveropen" 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments