Skip to content

Conversation

chuganzy
Copy link

@chuganzy chuganzy commented Aug 3, 2025

Pull Request Template

Thanks for your PR! Make sure you have read the CONTRIBUTING guide.

What's Changed

Currently dropdown order is hardcoded, however the ideal order changes based on locale.
This PR makes use of Intl.DateTimeFormat.prototype.formatToParts() API to get the best matching order.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Tips for a good PR

  • If you are changing code, please add tests to cover the changes.
  • Some screenshots or screen recording could help to understand the changes.
  • If it is a bug, please provide the code to reproduce it.

Thanks

Additional Notes

Add any extra comments or questions here.

@chuganzy chuganzy marked this pull request as ready for review August 3, 2025 06:05
Copy link
Collaborator

@rodgobbi rodgobbi left a comment

Choose a reason for hiding this comment

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

@chuganzy thanks for the PR!
The idea is great 🚀
I left some change requests.

Could you also improve the PR description?
Adding more context and if possible, screenshots of how the day picker would look for you.

{formatYearDropdown(calendarMonth.date, dateLib)}
</span>
)}
{dropdownTypes.map((type) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This new feature will also adapt the month and year labels, not just the dropdowns.
Could you rename dropdownTypes to a more generic name that refers to the date-time format of the locale?

</span>
)}
{dropdownTypes.map((type) => {
const uiKey =
Copy link
Collaborator

Choose a reason for hiding this comment

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

For me, it's better to be explicit, as in the previous version.
Could you refactor this to have if statements that return the component with the explicit props applied to it, like:

if (type === month) {
  return // return the same code block as before for month
}
if (type === year) {
  return // return the same code block as before for year
}

: formatYearDropdown;

return (
<Fragment key={type}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fragment is not needed, key can be passed to the Dropdown component, and span.

expect(comparePosition()).toBe(Node.DOCUMENT_POSITION_FOLLOWING);

rerender(<Dropdown locale={ja} />);
expect(comparePosition()).toBe(Node.DOCUMENT_POSITION_PRECEDING);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This new feature will also change the way date text is displayed, so we can assert that the text is rendered in the right order using toHaveAccessibleName, like the other tests.
But to do so, we also need to update the accessible name of the calendar, could you update the labelGrid to have the same dynamic logic based on locale?
Please extract the logic to compute the month/year order based on locale to a separate function.

@gpbl
Copy link
Owner

gpbl commented Aug 4, 2025

This is an interesting take. I have some questions:

  • Which locales require displaying the year before the month? Does the test cover these locales?
  • This sounds like a breaking change. Should we add a prop to toggle this feature instead?
  • Why apply this only to the dropdown and not also to the caption?

@chuganzy
Copy link
Author

chuganzy commented Sep 16, 2025

Apologies for leaving this open for a while..

Which locales require displaying the year before the month? Does the test cover these locales?

Many Asian countries such as Japan, China, Korea and more, and yes I added a test to cover this.

This sounds like a breaking change. Should we add a prop to toggle this feature instead?

Let me come up with the way.

Why apply this only to the dropdown and not also to the caption?

Because for captions and labels we already have a way to override, and it is necessary for these locales to override them to properly localize (although probably most developers would just ignore), so I initially thought it can be decoupled from this PR. However, indeed I can come up with the way to take care of it along with the previous question.

@gpbl
Copy link
Owner

gpbl commented Sep 19, 2025

@chuganzy Thanks so much for your insights here!

I see that the issue isn’t just about the drop-downs, but also affects the formatting of the caption in formatCaption and the grid label in labelGrid.

I think it makes sense to take a broader approach and add a function to DateLib that tells us whether the calendar should display year-first or month-first.

Since this requires some familiarity with the codebase, I’m happy to take this on.

@chuganzy
Copy link
Author

Great, then I will close mine! Thanks!

@chuganzy chuganzy closed this Sep 20, 2025
@chuganzy chuganzy deleted the dropdown-order branch September 20, 2025 16:55
@gpbl
Copy link
Owner

gpbl commented Sep 21, 2025

@chuganzy the change is available in v9.11 - see for example

https://daypicker.dev/playground?locale=zh-CN

does it work for you?

@chuganzy
Copy link
Author

chuganzy commented Sep 21, 2025

Thanks, and it looks good! Technically, the year format is not yet 100% accurate and can see the difference between Intl format vs date-fns when using label caption vs dropdown caption, but indeed that can be decoupled!

So, looks like no flag is added and was just released as a minor update?

@gpbl
Copy link
Owner

gpbl commented Sep 22, 2025

@chuganzy yes, we released this to gather more feedback. I'm not an expert in these Asian languages, so I can’t judge how accurate it is :)

Do you mean the label caption is still not quite correct? I'd like to iterate on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants