reactjs - 如何在 MUI v5 中将图标添加到 MobileDatePicker
问题描述
这是代码的一部分:
<MobileDatePicker
showTodayButton
showToolbar={false}
disableCloseOnSelect={false}
inputFormat="YYYY-MM-DD"
views={['day']}
value={row.value}
onChange={(newValue) => row.onChange(newValue)}
renderInput={(params) => (
<InputBase {...params} className={classes.datePicker} />
)}
/>
在移动端,他没有显示触发图标。
如何显示给用户一个清晰的指示。
解决方案
MobileDatePicker
没有后缀图标,因为您可以通过聚焦来打开它,这与TextField
您DesktopDatePicker
必须单击图标才能打开选择器不同。但是,如果您仍然想包含该图标,只需在 中添加endAdornment
一个TextField
:
import InputAdornment from '@mui/material/InputAdornment';
import EventIcon from '@mui/icons-material/Event';
const [value, setValue] = React.useState<Date | null>(new Date());
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
return (
<MobileDatePicker
label="For mobile"
value={value}
open={open}
onOpen={handleOpen}
onClose={handleClose}
onChange={setValue}
renderInput={(params) => (
<TextField
{...params}
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton edge="end" onClick={handleOpen}>
<EventIcon />
</IconButton>
</InputAdornment>
),
}}
/>
)}
/>
);
相关答案
推荐阅读
- reactjs - React - List?Dictionary?State? Or am i missing something
- sql - Force COALESE(NULL,NULL) to return NULL
- serialization - 如何使用它的父接口序列化对象?
- xpath - 如何使用 XPath 获取默认选择值
- javascript - SendGrid: How to put embed form to a HTML template mail when using SendGrid
- javascript - 对于 Protractor e2e 测试... 执行方法不稳定:单击按钮 3 次
- c# - Refactoring to make code open for extensions but closed for modifications
- python - nginx and django setting for docker-compose
- laravel - Laravel 5.8控制器索引函数返回空白页
- regex - 如何用bash中变量的值替换第i行的第j列