palantir / blueprint

A React-based UI toolkit for the web
https://blueprintjs.com/
Apache License 2.0
20.63k stars 2.17k forks source link

Extend default shortcuts of date range picker with MTD and YTD #5268

Open severinlandolt opened 2 years ago

severinlandolt commented 2 years ago

Environment

Package version(s): Latest Blueprint version Browser and OS versions: Latest Chrome version

Feature request

It would be great to extend the default shortcuts of the date range picker with the following options:

Examples

MTD: Today is April 24th, 2022. The month-to-date option would include the range from 01-04-2022 to 24-04-2022. YTD: Today is April 24th, 2022. The year-to-date option would include the range from 01-01-2022 to 24-04-2022.

adidahiya commented 2 years ago

This is very similar to a previous request: https://github.com/palantir/blueprint/issues/4398

Adding MTD and YTD is currently possible, all you have to do is set the shortcuts prop on DateRangeInput or DateRangePicker.

However, it's not very easy to extend the set of default shortcuts, because we don't expose those in the public API:

https://github.com/palantir/blueprint/blob/85dab97343d3780d5180afe86739d0aee0236e62/packages/datetime/src/shortcuts.tsx#L130

I'd be open to an API improvement which makes it easy to extend the default set instead of overriding the default shortcuts.