screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <div id="app"></div> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> <script type="text/babel"> const { useState } = React; function App() { const [disabledOptions, setDisabledOptions] = useState(['option2']); // Initially disable Option 2 return ( <div className='container'> <h3 className='heading'>React Js Disable Select Option Conditionally</h3> <select className='select-box'> <option className={`option ${disabledOptions.includes('option1') ? 'disabled' : ''}`} value="option1" disabled={disabledOptions.includes('option1')} > Option 1 </option> <option className={`option ${disabledOptions.includes('option2') ? 'disabled' : ''}`} value="option2" disabled={disabledOptions.includes('option2')} > Option 2 </option> <option className={`option ${disabledOptions.includes('option3') ? 'disabled' : ''}`} value="option3" disabled={disabledOptions.includes('option3')} > Option 3 </option> </select> {/* Your application logic can set or update the disabledOptions array */} <button className='disable-button' onClick={() => setDisabledOptions(['option1', 'option3'])} > Disable Options 1 and 3 </button> <button className='enable-button' onClick={() => setDisabledOptions([])} > Enable All Options </button> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 500px; text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; } /* Style for the heading */ .heading { font-size: 24px; margin-bottom: 20px; color: #333; } /* Style for the select box */ .select-box { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; font-size: 16px; color: #333; outline: none; } /* Style for the options */ .option { padding: 5px; } /* Style for disabled options */ .option.disabled { background-color: #ccc; color: #999; } /* Style for the disable button */ .disable-button { background-color: #ff3333; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; margin-right: 10px; cursor: pointer; margin-top: 10px; } .disable-button:hover { background-color: #cc0000; } /* Style for the enable button */ .enable-button { background-color: #33cc33; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; } .enable-button:hover { background-color: #00aa00; } </style> </body> </html>