Enhance Label Styling: Utilize custom CSS to adjust the label's position above the border, along with modifying font size, padding, and margin to suit your requirements.
import { styled } from '@mui/system';
const StyledTextField = styled(TextField)({
'& .MuiInputLabel-root': {
transform: 'translate(0, -1.5rem) scale(1)', // Move label above border
fontSize: '1rem', // Adjust font size as needed
paddingLeft: '0.5rem', // Optional: Modify padding for improved alignment
paddingRight: '0.5rem', // Optional: Modify padding for improved alignment
},
'& .MuiInputLabel-shrink': {
transform: 'translate(0, -1.5rem) scale(1)', // Ensure consistent positioning when focused
},
});
const MyComponent = () => (
<StyledTextField
label="First Name"
variant="outlined"
InputLabelProps={{
shrink: true,
}}
/>
);
export default MyComponent;