javascript - Material UI:TextField 闹钟更改为另一个图标
问题描述
我有TextField
。因为 Material UI 有Alarm Clock
图标。
材料 UI 文档是这样的:
<form className={classes.container} noValidate>
<TextField
id="time"
label="Alarm clock"
type="time"
defaultValue="07:30"
className={classes.textField}
InputLabelProps={{
shrink: true,
}}
inputProps={{
step: 300, // 5 min
}}
/>
</form>
我设计的是这样的:
<TextField
id="time"
type="time"
style={{
width: "148px",
marginLeft: 4,
marginRight: 6,
padding: "2px 0px 3px 6px",
}}
defaultValue="03:30"
value={timeChange}
onChange={handleTimeChange}
className={classes.textField}
color="secondary"
InputProps={{
disableUnderline: true,
endAdornment: <ExpandMoreIcon style={{ color: "gray" }} />,
classes: {
input: classes.floatingLabelFocusStyle,
},
// className: classes.input,
}}
/>;
并添加了一些CSS:
input[type="time"]::-webkit-calendar-picker-indicator {
background: none;
}
我得到的是:
有没有一种方法可以让我ExpandMoreIcon
在点击时表现得像闹钟一样并打开弹出窗口以显示时间选择器?
我不想显示闹钟图标。ExpandMoreIcon
我只想要图标中的闹钟功能?
有什么解决办法吗。。
谢谢你。
解决方案
const [displayPicker, setDisplayPicker] = React.useState(false);
<TextField
id="time"
type="time"
style={{
width: '148px',
marginLeft: 4,
marginRight: 6,
padding: '2px 0px 3px 6px',
}}
defaultValue="03:30"
value={timeChange}
onChange={handleTimeChange}
focused={displayPicker}
className={classes.textField}
color="secondary"
InputProps={{
endAdornment: <ExpandMoreIcon style={{ color: 'gray' }} />,
onFocus: () => setDisplayPicker(true),
onBlur: () => setDisplayPicker(false),
classes: {
input: classes.floatingLabelFocusStyle,
},
}}
/>
推荐阅读
- android - 如何使用不同类型的卡片创建布局?
- java - Java 应用程序在 Fedora 30 上的 JDK1.8 上启动非常缓慢
- sql - 无法将值插入创建的表中
- reactjs - 了解更多关于 Reactjs 中的 Hoc
- css - 单击卡片背面的左箭头图标时,转换 CSS 样式将不起作用
- angularjs - AngularJS - ui路由器 - 无法将url参数键与感叹号匹配
- swift - 如何在不同的视图控制器之间快速更改某些单元格的视图
- spring-boot - 捕获我的任何休息控制器发生的任何 CRUD 操作的所有审核日志
- javascript - Unexpected value 'ButtonModule 请添加@NgModule 注解
- hl7-fhir - FHIR:多服务器身份验证