How to disable option mui select in react js?
February 18, 2023Hi Friends 👋,
Welcome To aGuideHub!
To disable option mui select in React js, you can use disabled={option.disabled}
. It will disable option mui select in React js.
Today, I am going to show you, how to disable option mui select in react js.
Installation
Install the following packages to use disable option mui select in react js.
npm
npm install @mui/material @emotion/react @emotion/styled
yarn
yarn add @mui/material @emotion/react @emotion/styled
MUI material disable option mui select example.
The below code is an example of disable option mui select using disabled={option.disabled}
in menuitem with select mui.
App.js
import { Select, MenuItem } from '@mui/material';
const options = [
{ value: 'option1', label: 'Option 1', disabled: false },
{ value: 'option2', label: 'Option 2', disabled: true },
{ value: 'option3', label: 'Option 3', disabled: false },
];
export default function MySelect() {
return (
<Select defaultValue="option1">
{options.map((option) => (
<MenuItem key={option.value} value={option.value} disabled={option.disabled}>
{option.label}
</MenuItem>
))}
</Select>
);
}
In the above code example, I have used the @mui/material
component and disable option mui select.
Check the output of the above code example.
Here, we are provided code sandbox links for the above program disable option mui select. Then you can use whenever you want and do the changes as per your requirements.
All the best 👍