Skip to content
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

Merged
merged 5 commits into from
Nov 13, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Nov 10, 2023

Part of #10776

  • Add calendarHeader slot support on DateRangeCalendar
  • Allow to override the format in the header using slotProps.calendarHeader.format
  • Remove some useless 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.

@flaviendelangle flaviendelangle self-assigned this Nov 10, 2023
@flaviendelangle flaviendelangle added the component: pickers This is the name of the generic UI component, not the React module! label Nov 10, 2023
@@ -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;
Copy link
Member Author

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}`,
Copy link
Member Author

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

@@ -103,28 +102,12 @@ describe('<DateCalendar />', () => {
expect(disabledDays.length).to.equal(31);
});

it('should render header label text according to monthAndYear format', () => {
Copy link
Member Author

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

@mui-bot
Copy link

mui-bot commented Nov 10, 2023

@flaviendelangle flaviendelangle marked this pull request as ready for review November 10, 2023 11:11
@flaviendelangle
Copy link
Member Author

@k725 since you will need this feature, I'd be interested to have your feedback about the DX and the doc clarity 🙏

Copy link
Member

@michelengelen michelengelen left a 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! 🙇🏼

@k725
Copy link
Contributor

k725 commented Nov 12, 2023

@flaviendelangle Thank you very much. It seems easy to use for me. LGTM

@flaviendelangle flaviendelangle merged commit b5306db into mui:next Nov 13, 2023
18 checks passed
@flaviendelangle flaviendelangle deleted the calendarHeader-format branch November 13, 2023 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants