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

[pickers] Keep the calendar header and content in sync when switching locale #14125

Merged
merged 7 commits into from
Sep 2, 2024

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Aug 6, 2024

Fixes #12963

In AdapterDateFns we have the following:

  public startOfWeek = (value: Date): Date => {
    return startOfWeek(value, { locale: this.locale });
  };

But on the adapters where the locale is stored on the date object, we didn't set the locale of the adapter to the value passed.
So if the locale of the value and the value of the adapter were different, it was the locale of the value that was being used.

@@ -1,4 +1,5 @@
import * as React from 'react';
import moment, { Moment } from 'moment';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, I just noticed that we had 2 spec files for this component

@@ -574,7 +574,7 @@ export function DayCalendar<TDate extends PickerValidDate>(inProps: DayCalendarP
key={i.toString()}
variant="caption"
role="columnheader"
aria-label={utils.format(utils.addDays(startOfCurrentWeek, i), 'weekday')}
aria-label={utils.format(weekday, 'weekday')}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why we were re-doing the day shift here, but I spent some time finding out why my aria-label were not updated in the test whereas the UI was good in the doc 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization. 👍

@mui-bot
Copy link

mui-bot commented Aug 6, 2024

Deploy preview: https://deploy-preview-14125--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against b01df58

@flaviendelangle flaviendelangle self-assigned this Aug 6, 2024
@flaviendelangle flaviendelangle changed the title [pickers] Keep the calendar header and the calendar content in sync when switching locale [pickers] Keep the calendar header and content in sync when switching locale Aug 6, 2024
@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label Aug 7, 2024
@flaviendelangle flaviendelangle added the bug 🐛 Something doesn't work label Aug 13, 2024
Copy link
Member

@arthurbalduini arthurbalduini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@flaviendelangle flaviendelangle merged commit 033f897 into mui:master Sep 2, 2024
18 checks passed
@flaviendelangle flaviendelangle deleted the day-header-locale branch September 2, 2024 14:18
Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! 👏
Sorry for a late review. 🙈

@@ -574,7 +574,7 @@ export function DayCalendar<TDate extends PickerValidDate>(inProps: DayCalendarP
key={i.toString()}
variant="caption"
role="columnheader"
aria-label={utils.format(utils.addDays(startOfCurrentWeek, i), 'weekday')}
aria-label={utils.format(weekday, 'weekday')}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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.

[pickers] Changing locale between a monday-first or sunday-first language breaks indicated order of weekdays
5 participants