-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DateCalendar] Allow to override the format of the header with a prop #10990
[DateCalendar] Allow to override the format of the header with a prop #10990
Conversation
@@ -329,6 +332,32 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar<TDate>( | |||
timezone, | |||
}); | |||
|
|||
// When disabled, limit the view to the selected date | |||
const minDateWithDisabled = (disabled && value[0]) || minDate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DateRangePicker
calendar was not using the calendarHeader
slot
{utils.format(visibleMonths[month], 'monthAndYear')} | ||
{utils.formatByString( | ||
visibleMonths[month], | ||
calendarHeaderProps.format ?? `${utils.formats.month} ${utils.formats.year}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we have 2+ months visible, we don't use the header and instead we directly set the format.
Is it good for you to also use the slot prop here? That way people can always override the format the same way
.../x-date-pickers/src/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.tsx
Show resolved
Hide resolved
@@ -103,28 +102,12 @@ describe('<DateCalendar />', () => { | |||
expect(disabledDays.length).to.equal(31); | |||
}); | |||
|
|||
it('should render header label text according to monthAndYear format', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the test for the old API, we now have a new one
Deploy preview: https://deploy-preview-10990--material-ui-x.netlify.app/ Updated pages: |
@k725 since you will need this feature, I'd be interested to have your feedback about the DX and the doc clarity 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM so far ... just a few comments. Please correct me if I am wrong on the formatting part! 🙇🏼
.../x-date-pickers/src/internals/components/PickersArrowSwitcher/PickersArrowSwitcher.types.tsx
Show resolved
Hide resolved
@flaviendelangle Thank you very much. It seems easy to use for me. LGTM |
Part of #10776
calendarHeader
slot support onDateRangeCalendar
slotProps.calendarHeader.format
LocalizationProvider
on tests (not related to this PR, I just saw them while working on it)I can mark this as breaking and add it to the migration guide if you want.