<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DatePicker
fullWidth
value={dob}
label="Date of Birth"
format="dd / MM / yyyy"
margin="normal"
maxDate={new Date()}
InputProps={{ className: css.datepicker }}
></DatePicker>
</MuiPickersUtilsProvider>
.datepicker {
margin: 2px 0px 2px 0px;
height: 60px;
width: fit-content;
padding: 20px 15px 10px;
border-bottom: 2px solid $lightGrey;
background-color: #fff;
color: #2c2c2c;
width: 300px;
font-weight: 600;
}
Is it possible to style the Material UI date picker in my expected way of look as the image attached?
code
function App() {
const [dob, setDob] = useState(null); //<--- pass initial value as null
const handleDateChange = date => {
setDob(date);
};
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DatePicker
fullWidth
onChange={handleDateChange}
value={dob}
label="Date of Birth"
format="dd / MM / yyyy"
margin="normal"
maxDate={new Date()}
emptyLabel="custom label" //<--- custom placeholder when date is null
// InputProps={{ className: css.datepicker }}
/>
</MuiPickersUtilsProvider>
);
}
Edit: answering follow-up qns based on comment.
dob
has a valuelabel={dob && "Date of Birth"}
makeStyles
and InputProps
const useStyles = makeStyles(theme => ({
datepicker: {
margin: "2px 0px 2px 0px",
height: "60px",
// width: 'fit-content',
padding: "20px 15px 10px",
borderBottom: "2px solid blue",
backgroundColor: "#fff",
color: "#2c2c2c",
width: 300,
fontWeight: 600
}
}));
function App() {
const [dob, setDob] = useState(null); //<--- pass initial value as null
const classes = useStyles();
const handleDateChange = date => {
setDob(date);
};
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DatePicker
fullWidth
onChange={handleDateChange}
value={dob}
label={dob && "Date of Birth"}
format="dd / MM / yyyy"
margin="normal"
maxDate={new Date()}
emptyLabel="custom label" //<--- custom placeholder when date is null
InputProps={{ className: !dob ? classes.datepicker : null }} //<----apply style when no date selected
/>
</MuiPickersUtilsProvider>
);
}
The codesandbox demo has been updated to reflect all the points above.