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][DateRangePicker] Separately disable start and end date picking #13558

Open
kbrueckner opened this issue Jun 20, 2024 · 4 comments
Open
Labels
component: DateRangePicker The React component. component: pickers This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@kbrueckner
Copy link

kbrueckner commented Jun 20, 2024

Summary

I am looking for a feature where it is possible to freeze selected values for start and end date. Means a start or end date cannot be changed. This shall be possible independently, thus disable on DAteRangePicker itself wouldn ot work, since it disabled edition completely for start and end date at the same time.

Examples

No response

Motivation

In some projects I have the following use case:
Definition of settings which apply to a selected date range. Once the start date of the range is reached or in the past it shall not be possible to update the start date anymore while the end date shall still be editable until that one is in the past as well.

Search keywords: daterangepicker disable

@kbrueckner kbrueckner added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 20, 2024
@LukasTy
Copy link
Member

LukasTy commented Jun 20, 2024

Hello @kbrueckner, have you tried using the shouldDisableDate callback prop?

It receives the position argument that can be used to disable dates based on the selected range position, i.e.:

(day, position) => {
  if (value[0] && position === 'start' && day.isBefore(value[0])) {
    return true;
  }
  return false;
}

@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! component: DateRangePicker The React component. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 20, 2024
@kbrueckner
Copy link
Author

Yes, I considered that and tried a lot of things with different provided attributes of DateRangePicker.
The problem is that it doesn't give a full blown solution with nice UX.

The one you suggested - if I am not mistaking - would simply disable a specific date in the calendar but it does not prevent from setting the from date to another date which is not disabled.

@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 Jun 20, 2024
@LukasTy
Copy link
Member

LukasTy commented Jun 20, 2024

The one you suggested - if I am not mistaking - would simply disable a specific date in the calendar but it does not prevent from setting the from date to another date which is not disabled.

Do you mean setting the date in the input?
Are validation errors and form submission blocking not an option in your use case? 🤔

If not, it seems like you are talking about the following requirement: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date (year is disabled in input given present validation rules).
Such enhancement could be possible, but only in the new accessible DOM behavior.
Could you confirm if this is the behavior you need? 🤔

@LukasTy LukasTy added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 20, 2024
@kbrueckner
Copy link
Author

kbrueckner commented Jun 20, 2024

Uploading a screenshot to explain the expected behaviour:
Screenshot 2024-06-20 at 12 53 07

If start date is configured to be fixed/not editable the input field shall be disabled. Whenever you open the calendar widget i.e. by editing the the end date the start date (in the screenshot June 19) shall be fixed. It shall not be possible to move the start date to earlier or later while the end date can still be updated/moved. the selected range nevertheless shall still be in the light highlight color.

In addition it shall also be possible to set the end date fixed while keeping the start date updateable.

With the current control attributes I can achieve to set the start date input field disabled but it can still be updated via the calendar widget unfortunately.

@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 Jun 20, 2024
@michelengelen michelengelen changed the title [DateRangePicker] Separately disable start and end date picking [pickers][DateRangePicker] Separately disable start and end date picking Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: DateRangePicker The React component. component: pickers This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants