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

[DateRangePicker] Implement range shortcuts #4563

Closed
oliviertassinari opened this issue Apr 14, 2020 · 27 comments · Fixed by #7154
Closed

[DateRangePicker] Implement range shortcuts #4563

oliviertassinari opened this issue Apr 14, 2020 · 27 comments · Fixed by #7154
Assignees
Labels
component: DateRangePicker The React component. component: pickers This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer linked in docs The issue is linked in the docs, so completely skew the upvotes new feature New feature or request plan: Pro Impact at least one Pro user

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 14, 2020

Referring to mui/material-ui-pickers#1293 (comment), I think that it would very valuable to implement a range shortcut feature. I was proposing this API:

  /**
   * Whether shortcuts to quickly select a range of dates are displayed or not.
   * If true, preset shortcuts will be displayed.
   * If false, no shortcuts will be displayed.
   * If an array is provided, the custom shortcuts will be displayed.
   */
  rangeShortcuts: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),

but I have no doubt other, potentially better, alternative APIs are possible.

Requests

Benchmarks

For the benchmark, we can consider:

Capture d’écran 2020-04-14 à 23 33 41

Screenshot 2022-09-29 at 01 30 38

Screenshot 2022-09-29 at 01 32 46

Screenshot 2022-09-29 at 01 26 01

Screenshot 2022-09-29 at 01 46 03

Screenshot 2022-09-29 at 01 29 48

Screenshot 2022-09-29 at 01 34 06

  • WooCommerce Analytics

Screenshot 2022-10-03 at 17 21 33

  • Stripe

Screenshot 2022-10-03 at 17 24 49

Screenshot 2022-10-03 at 17 25 01

@oliviertassinari oliviertassinari changed the title Implement range shortcuts [DateRangePicker] Implement range shortcuts Dec 27, 2020
@oliviertassinari oliviertassinari transferred this issue from mui/material-ui-pickers Dec 27, 2020
@oliviertassinari oliviertassinari added component: DateRangePicker The React component. new feature New feature or request labels Dec 27, 2020
@cherniavskii cherniavskii transferred this issue from mui/material-ui Apr 18, 2022
@cherniavskii cherniavskii added status: waiting for maintainer These issues haven't been looked at yet by a maintainer 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 Apr 18, 2022
@flaviendelangle flaviendelangle added the plan: Pro Impact at least one Pro user label Apr 20, 2022
@flaviendelangle
Copy link
Member

flaviendelangle commented Apr 21, 2022

I fully agree with the idea of shortcuts

I am just not sure about the boolean version

Here a three apis I can think of to define the default and custom shortcuts
The prop naming is of course subject to changes.

// Option A: `true` for default and object for custom
// Very concise but very magic
import { DateRangePicker } from '@mui/x-date-pickers-pro'

<DateRangePicker {...other} rangeShortcuts /> // default
<DateRangePicker {...other} rangeShortcuts={[{ /** **/ }]} /> // custom

// Option B: always use objects
import { DateRangePicker, DEFAULT_RANGE_SHORTCUTS } from '@mui/x-date-pickers-pro'

<DateRangePicker {...other} rangeShortcuts={DEFAULT_RANGE_SHORTCUTS} /> // default
<DateRangePicker {...other} rangeShortcuts={[{ /** **/ }]} /> // custom

// Option C: decouple the feature activation and the feature config 
// Similar to what we do for the `filterable` and `filterOperators` on the grid
import { DateRangePicker } from '@mui/x-date-pickers-pro'

<DateRangePicker {...other} enableShortcuts /> // default
<DateRangePicker {...other} enableShortcuts rangeShortcuts=[{ /** **/ }]} /> // custom

I guess the 1st one is great if we think most users will stick with the default one and custom shortcuts is an edge case.
But if we think a large portion of our user will remove some shortcut / add others / change the behavior of others, then I prefer to be explicit and avoid props with two signatures.

@flaviendelangle flaviendelangle added the waiting for 👍 Waiting for upvotes label Apr 21, 2022
@oliviertassinari oliviertassinari added the linked in docs The issue is linked in the docs, so completely skew the upvotes label Apr 26, 2022
@RayaneSlimani
Copy link

Hi,
actually it is possible to do it with the existing components with lot of work but it would be very interesting to add it by default 💯

image

@yaminagile
Copy link

@RayaneSlimani can you share snippets or reference code how you achieve this shortcuts in range picker?

@RayaneSlimani
Copy link

@yaminagile just some logic and https://date-fns.org/ 😄
The shorcuts buttons are functions that return the date according to the selected shorcut.

@Wyctus
Copy link

Wyctus commented Jul 30, 2022

What is the current state of this?

@flaviendelangle
Copy link
Member

We did not start working on it

@tarmooo
Copy link

tarmooo commented Aug 15, 2022

Hi, actually it is possible to do it with the existing components with lot of work but it would be very interesting to add it by default 💯

Did the same thing so i don't see a point in that. perhaps just a demo in documentation for it to get started faster?

@Magwaer
Copy link

Magwaer commented Aug 15, 2022

Here a demo of a good example
https://codesandbox.io/s/textfieldhiddenlabel-material-demo-forked-bpm46e?file=/RangePicker.tsx
Screenshot from 2022-08-15 12-12-30

@Joseph-Mutua
Copy link

Joseph-Mutua commented Aug 24, 2022

There seems to be an error in the demo. When I click the Apply I just get the error: onChange is not a function. Do you know any solution to this please?

@LukasTy
Copy link
Member

LukasTy commented Aug 26, 2022

This feature is now somewhat more easier to implement using the newly introduced PaperContent slot.
The examples include working demos with range shortcuts, with a caveat that onChange is not triggered, because we are changing the range values externally.

@alexfauquette alexfauquette self-assigned this Aug 31, 2022
@gerdadesign
Copy link
Member

What about using chips for shortcuts? Perhaps this might be easier to stack vertically in mobile as well.
Version 1-desktop (1)

@alexfauquette
Copy link
Member

As a replacement of the ActionBar (the clear button) it would be nice

image

Just made a codesandbox to explore the different options developers can already set
https://codesandbox.io/s/late-dew-zixos5?file=/demo.tsx

@gerdadesign
Copy link
Member

gerdadesign commented Sep 26, 2022

As discussed, below are a few variations with the action bar.
When it comes to multiple chips, it seems that Material Design 2 and Material Design 3 both favor a horizontal scroll with a fade.

A few chips inline with action bar

few with actions

Many chips inline with action bar, with horizontal scroll

interactive prototype

Screenshot 2022-09-29 at 00 56 33

Many chips vertically stacked, container inline with action bar

vertical stack chips with actions

Many chips and action bar vertically stacked (also showing outline style)

vertical stack all + outline style

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Sep 28, 2022

I have updated the benchmark of the issue (first comment) to polish it. Thoughts on #4563 (comment):

  1. How does it look like with this preset?

Screenshot 2022-09-29 at 01 41 15

It's what the account we have in https://sell.buysellads.com/ use. I feel that the value we use in the above test are shorter compared to how they might be used in real life by Product Manager/Product Designer. So, I think that it could be great to test longer labels too.

  1. How would it look like for Joy UI?
  2. I think that we need to have a not-too-hard option for the shortcuts to be on the left side. Why, because we are building a component that developers will customize. I would expect a lot to branch out from what Material Design recommends by default. And based on what's done in the wild, it seems that the left side is a common pattern. In practice, I think that we can consider all the options, maybe starting with a demo in the docs, before considering anything built-in.

@gerdadesign
Copy link
Member

gerdadesign commented Oct 3, 2022

Thanks for the feedback! These options are definitely with a slightly different use case in mind than where I started. I added more options to figma that show how the chips can be used with this text and how it can be placed in different positions.

with a screenshot preview:
Overview of shortcuts in date/time pickers

One note that if it gets to be an overwhelming amount of options, then perhaps they no longer qualify as "shortcuts" and would be better served as an input field with selections (like in the Google search console example).

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Oct 3, 2022

like in the Google search console example

@gerdadesign This touch on something interesting! I think that we need to consider the notion of what happens when an end-user selects a preset. Does she/he select a start and end date or select the preset itself? (e.g., if you come 15 days later, what do you see?)

In practice, I think that we should optimize here for what's simpler for internal tools/the simple use cases. Based on the above benchmark, I would expect advanced external user-facing applications to implement the range feature themselves.

@gerdadesign
Copy link
Member

Here is my proposal for a default + the available customizations.

  • I'm suggesting bottom inline as the default for saving space + encouraging keeping a small number of shortcuts. Open to changing my mind here if we think most people would use it differently! Just operating on assumptions right now.
  • Shortcuts moveable to bottom (full-width), top, left, and right
  • The final slide is a way to show that the chips themselves are also customizable, and based on the existing Material UI docs it seems they should use the clickable chip action.
Default (inline) bottom (full-width) top left right
inline full-width top-full-width left right

And here is a basic prototype of the suggested interaction. All shortcuts would be relative to today's date.

  • "Last week"
  • "This month"
  • What if I want to change the end date after clicking a shortcut?
    • press end date, hovering extends range, click to new date
  • Current range picker automatically closes when the end date is accepted; with presets, it might be better to add a submit since you need to verify if the shortcut is correct.

@abury
Copy link

abury commented Dec 6, 2022

What's the ETA on this one? I love MUI, but it's a bit disappointing that something like this isn't provided in a paid solution when it's available for free in other libraries.

@alexfauquette
Copy link
Member

@abury This feature is currently blocked by #6900. From the different design approaches, we concluded that there is not a single obvious place for shortcuts. So we decided to implement first a solution to simplify the modification of the layout, and then add the shortcut block in the new layout. It should start in few weeks

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Dec 7, 2022

@gerdadesign Great, thanks for the update. I think that it can make sense for Material Design.

If we move forward with this default look. I think that it will be important to have a customization demo the looks like how Google solves the problem on Google Ads and Google Analytics. I think that we could expect many designers or PMs to also ask their engineers to implement this approach.

@danilo-leal did you had initial thoughts on how the date picker should look like with Joy UI?

@danilo-leal
Copy link
Contributor

@oliviertassinari I don't have any specific designs for Joy UI as of now but, at least from an interaction standpoint, I do not expect it to be different from the one @gerdadesign is iterating on for Material UI. Of course, visually it will be something else but it would work similarly?!

@abury
Copy link

abury commented Dec 9, 2022

@alexfauquette Thanks for the update, really looking forward to seeing it in action.

@oliviertassinari
Copy link
Member Author

I think that we need to consider the notion of what happens when an end-user selects a preset. Does she/he select a start and end date or select the preset itself? (e.g., if you come 15 days later, what do you see?)

I have found a component that takes the latter approach: "selecting the preset" rather than the date range: https://vercel.com/design/calendar#presets

Screenshot 2023-02-15 at 11 43 44

@gerdadesign
Copy link
Member

Should we address the way we handle the Reset button?
Right now it's being treated the same as a chip, but it's functioning a little bit differently. MD3 adds a left-aligned Clear button in the bottom action row. This could be used to clear both the range shortcuts as well as the selection even if they did not use the shortcuts.
Ranges_Clear

@oliviertassinari oliviertassinari added design This is about UI or UX design, please involve a designer and removed design: ux labels Aug 18, 2023
@charlesjIV
Copy link

I think that we need to consider the notion of what happens when an end-user selects a preset. Does she/he select a start and end date or select the preset itself? (e.g., if you come 15 days later, what do you see?)

I have found a component that takes the latter approach: "selecting the preset" rather than the date range: https://vercel.com/design/calendar#presets

Screenshot 2023-02-15 at 11 43 44

Is there any intention of implementing this feature or is there a way to modify the date range picker locally to support this? The API I am working with works with keywords rather than dates and using Custom Actions isn't my favorite way of implementing this.

@LukasTy
Copy link
Member

LukasTy commented Dec 5, 2023

Is there any intention of implementing this feature or is there a way to modify the date range picker locally to support this?

We are not dismissing such idea, but we are currently spread a bit too thin to tackle such feature additions. 😉

@flaviendelangle
Copy link
Member

@LukasTy now that we are passing the shortcut object to onChange, people can do nice things in user-land
I did a quick POC here, but we could probably add a doc example based on this approach.

If people wants to entirely disable the view part in favor of a preset list, then I'd suggest using this doc section as the main inspiration.

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! design This is about UI or UX design, please involve a designer linked in docs The issue is linked in the docs, so completely skew the upvotes new feature New feature or request plan: Pro Impact at least one Pro user
Projects
None yet
Development

Successfully merging a pull request may close this issue.