Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI - Add "Today" button to <DatePicker />

Tags:

material-ui

I need to have a "Today" button as in the image bellow, positioned somewhere in the red marked area (or somewhere else). I'm using material-ui v5 and I also tried to add prop showTodayButton but seems to do nothing...

enter image description here

like image 455
stackoverflow Avatar asked Nov 01 '25 18:11

stackoverflow


2 Answers

2023 Update

As mentioned by @Chaitanya, the componentsProps prop is deprecated (for v5), you should use slotProps instead.

Original answer

The bug mentioned by bhugo313 has been fixed by now but the documentation isn't very clear on how to add the "Today" button.

You need to provide an actionBar object via the componentsProps:

import { DateTimePicker } from "@mui/x-date-pickers/DateTimePicker";

<DateTimePicker
    /* ... other props */
    componentsProps={{
       actionBar: { actions: ["clear", "today", "cancel", "accept"] },
    }}
/>
like image 187
Liiva Avatar answered Nov 04 '25 20:11

Liiva


This is the bug of Material UI v5. There's pending PR for this bug and it's not merged yet. Since v5 is still in RC stage, I think we should wait this PR to be merged.

showTodayButton prop works well on mobile date picker, but not on desktop date picker.

like image 23
bhugo313 Avatar answered Nov 04 '25 19:11

bhugo313



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!