screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <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> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const [text, setText] = useState(''); const handleChange = (event) => { const inputValue = event.target.value; // Check if the input value exceeds the character limit if (inputValue.length <= 10) { setText(inputValue); } }; return ( <div className='container'> <h3>React Js Character Limit Example</h3> <input type="text" value={text} onChange={handleChange} maxLength={10} // Set the maximum character limit /> <p>Remaining characters: {10 - text.length}</p> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); text-align: center; } input[type="text"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; margin-bottom: 10px; box-sizing: border-box; } input[type="text"]:focus { border-color: #3498db; box-shadow: 0 0 6px rgba(52, 152, 219, 0.5); } p { font-size: 16px; color: #777; } </style> </body> </html>