Har*_*lla 7 css reactjs material-ui
<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>
Run Code Online (Sandbox Code Playgroud)
.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;
}
Run Code Online (Sandbox Code Playgroud)
是否可以按照我预期的外观样式设置 Material UI 日期选择器的样式,如所附图像?
gdh*_*gdh 11
代码
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>
);
}
Run Code Online (Sandbox Code Playgroud)
编辑:根据评论回答后续问题。
dob值label={dob && "Date of Birth"}
Run Code Online (Sandbox Code Playgroud)
makeStyles和InputPropsconst 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>
);
}
Run Code Online (Sandbox Code Playgroud)
代码沙盒演示已更新以反映上述所有要点。
| 归档时间: |
|
| 查看次数: |
3907 次 |
| 最近记录: |