<html>
<head>
<meta charset="UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/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 } = React;
function App() {
const [isElementFocused, setIsElementFocused] = useState(false);
const handleFocusChange = (event) => {
setIsElementFocused(event.type === 'focus');
};
return (
<div className='container'>
<h3>React Js Check Input Element is focused</h3>
<input
onFocus={handleFocusChange}
onBlur={handleFocusChange}
/>
{isElementFocused ? (
<p>The element is focused.</p>
) : (
<p>The element is not focused.</p>
)}
</div>
);
}
ReactDOM.render(<App />, document.getElementById('app'));
</script>
<style>
.container {
width: 400px;
margin: 0 auto;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
h3 {
font-size: 24px;
margin-bottom: 20px;
color: #333;
}
input {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 10px;
font-size: 16px;
width: 100%;
box-sizing: border-box;
}
</style>
</body>
</html>