I have implemented an input field that accepts user input and made it appear as if the first letter is automatically capitalized using CSS with textTransform: capitalize
. However, when I assign a useState variable to the input field, the value does not retain proper capitalization. How can I ensure that the useState variable's value reflects the correct capitalization displayed in the input field?
Below is the code snippet:
import {useState} from "react"
import "./styles.css";
import {Input} from "antd";
export default function App() {
const [text, setText] = useState("")
return (
<div className="App">
<Input placeHolder="Type Something" style={{textTransform:"capitalize"}} onChange={(e)=>{setText(e.target.value)}}/>
<br/>
value = {text}
</div>
);
}
For a better visualization and understanding, please refer to this codesandbox link.