admin管理员组文章数量:1389762
I am trying to style one of the options for date time pickers found in material ui. I made a styled Input I liked, and was trying to use that as a base. Adding the type="datetime-local"
prop to the ponent adds the functionality I need, but I can't find a way to style the icon button and the dialog.
Here is my experiment in code sandbox:
The code for the ponent looks like this:
<Paper ponent="form" className={classes.paper} elevation={0}>
<InputBase
className={classes.input}
type="datetime-local"
defaultValue="2017-05-24T10:30"
/>
</Paper>
The classNames provide the styling I like for the ponent:
But I need to change the color for the calendar icon on the right and if possible the style of the date picker for a dark theme.
How can I do that? Thanks in advance.
I am trying to style one of the options for date time pickers found in material ui. I made a styled Input I liked, and was trying to use that as a base. Adding the type="datetime-local"
prop to the ponent adds the functionality I need, but I can't find a way to style the icon button and the dialog.
Here is my experiment in code sandbox:
The code for the ponent looks like this:
<Paper ponent="form" className={classes.paper} elevation={0}>
<InputBase
className={classes.input}
type="datetime-local"
defaultValue="2017-05-24T10:30"
/>
</Paper>
The classNames provide the styling I like for the ponent:
But I need to change the color for the calendar icon on the right and if possible the style of the date picker for a dark theme.
How can I do that? Thanks in advance.
Share Improve this question edited Mar 28 at 10:37 Olivier Tassinari 8,6916 gold badges25 silver badges28 bronze badges asked Aug 20, 2020 at 17:17 DanfDanf 1,5693 gold badges24 silver badges43 bronze badges2 Answers
Reset to default 4Fortunately, you CAN change the icon.
It's a platform native element, so you need to reference the underlying tag.
input[type="date"]::-webkit-calendar-picker-indicator {
filter: invert(1);
}
Ciao, unfortunately you cannot change icon color (to white if I understood correctly). I tried to override &.MuiInputBase-input
css class also but the only thing I achieved was change text color.
But you can do something more (if you want). You can use DatePicker
from @material-ui/pickers
. This is of course more customizable (and I think more cool).
What do you need?
- @date-io/moment (1.x version pay attention on this);
- @material-ui/pickers;
- @date-io/moment;
- moment;
Installed this libraries you can do something like that:
Define a Theme:
const Theme = { palette: { primary: { // primary color contrastText: "#FFFFFF", dark: "#000000", main: "#000000", // black light: "#000000" } } };
Create a Mui theme:
const theme = createMuiTheme(Theme);
Use a
DatePicker
:<DatePicker format={"DD-MM-YYYY"} // your date format label="my date" inputVariant="outlined" // if you want an outlined date input helperText="" size="small" value={myDate} onChange={setmyDate} />
Wrap
DatePicker
into aThemeProvider
(to passTheme
toDatePicker
) and into aMuiPickersUtilsProvider
(to manage date withmoment
):<ThemeProvider theme={theme}> <MuiPickersUtilsProvider utils={MomentUtils}> <div className="App"> <DatePicker format={"DD-MM-YYYY"} label="my date" inputVariant="outlined" helperText="" size="small" value={myDate} onChange={setmyDate} /> </div> </MuiPickersUtilsProvider> </ThemeProvider>
And now if you click on date input you got this:
A DatePicker with a dark style. This is a date picker dialog but you can also have a date picker inline (using KeyboardDatePicker
).
Here you can find all the date picker versions provided by MaterialUI.
I know, it's a little bit tricky the first time (how many stuff I have to do for a simple date picker!!!) but the result is graphically more beautiful.
Here a codesandbox example of DatePicker
.
本文标签: javascriptStyle Material UI InputBase with Date amp Time pickersStack Overflow
版权声明:本文标题:javascript - Style Material UI InputBase with Date & Time pickers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744680260a2619361.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论