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] Allow controlling the currently displayed year and month in the calendar components #16108

Open
KilianB opened this issue Jan 9, 2025 · 5 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@KilianB
Copy link

KilianB commented Jan 9, 2025

Summary

Currently the referenceDate can be used to define which month of the DateCalendar is initially displayed, but changes to it do not reflect in the current month displayed in the date calendar. I am trying to replace the next and previous Buttons with my own implementation.

 <DateCalendar
    minDate={dayjs()}
    views={["day"]}
    referenceDate={referenceDateRight}
    slots={{
      nextIconButton: () => <></>,
      previousIconButton: () => <></>,
    }}
  />

I explicitly do not want to set the value or the default value of the component, but just control which month and date is displayed to the user

Examples

image

Motivation

As shown in the example the goal is to have multiple date pickers next to each other. In order to synch those I need to control the displayed month.
This can somehow we achieved by making the key dependent on the reference value, but this means that we are remounting the entire component every time we are changing the month.

The same motivation could previously be found here: https://stackoverflow.com/questions/76998078/how-can-i-have-two-calendars-in-the-datepicker-component-of-mui

Search keywords: reference date controlled date calendar

@KilianB KilianB added new feature New feature or request status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 9, 2025
@noraleonte
Copy link
Contributor

Hey there 👋 I am not sure the reference date will be of much help once the value is changed. referenceDate is used to determine what month to render initially. And as for rendering two calendars in a DatePicker I'm not sure how to correctly handle that off the top of my head 🤔 I will look into a solution - but seems cumbersome to achieve on the user's side
As far as I know, there's no current plan to support multiple calendars in a simple picker, but I will bring it up in the next team discussion.

@LukasTy
Copy link
Member

LukasTy commented Jan 9, 2025

This sounds close to #7379 and #4549.
Could we treat it as a duplicate? 🤔

@noraleonte
Copy link
Contributor

@LukasTy Feels like the main problem here is displaying multiple calendars 🤔

@LukasTy
Copy link
Member

LukasTy commented Jan 9, 2025

If that's the case - ok.
I don't think there are many problems creating multiple DateCalendar components.
I felt like the main issue is programmatically controlling updates of their current month. 🤔

@LukasTy LukasTy added status: waiting for author Issue with insufficient information component: pickers This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 9, 2025
@KilianB
Copy link
Author

KilianB commented Jan 10, 2025

As @noraleonte has said there are no current plans to support multiple calendars, so the main point of the issue is controlling the reference date as this would allow for the user to build it themselves. Getting the calendars to sync and show dates properly selected is just a matter of a few lines of code.

Multiple calendars are just an example. Having an external year picker or list of the website where the selection can be externally adjusted with different inputs or gestures could also be a scenario where controlling which month or year to display would be helpful.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 10, 2025
@LukasTy LukasTy removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 10, 2025
@LukasTy LukasTy changed the title Allow controlling the currently displayed year and month in the calendar components [pickers] Allow controlling the currently displayed year and month in the calendar components Jan 10, 2025
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! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants