feat(datepicker): Improve extensibility for datepicker use custom calendar implementation #25709
Labels
area: material/datepicker
feature
This issue represents a new feature or feature request rather than a bug or bug fix
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Feature Description
The content of the datepicker overlay is hard-coded in:
components/src/material/datepicker/datepicker-base.ts
Lines 685 to 688 in 36af2a3
It would be beneficial to allow custom content implementations (either derived from MatDatepickerContent or matching an interface) to be used, maybe as a factory method that could be added as a provider.
Use Case
We have an application where weeks are grouped into biweekly periods and the users find it useful when selecting dates which biweekly period a week is in and whether the week is the first or second week.
We are able to subtype the MatCalendarBody with a custom template that include another column (with a rowspan) to identify the biweekly period.
We are able to subtype the MatMonthView to use our custom body and to ensure the cells are built with days in the months before or after to make sure that each biweekly period is complete (it would be nice if
_createWeekCells
,_getCellCompareValue
and_shouldEnableDate
were not private so that they could be overridden/accessed).We are able to subtype MatCalendar to use our custom month view.
We are able to subtype MatDatepickerContent to use our custom calendar.
Unfortunately this is where it ends. We cannot use a custom content component with the datepicker without copying a large amount of code.
At a minimum we would like to be able to specify a custom content for the datepicker (and dateRangePicker) through something like a provider.
Or even nicer would be an option to dynamically identify the calendar views (possibly with a provider) to avoid all the extra subtyping.
This extensibility could also help other achieve similar requests like #20530.
The text was updated successfully, but these errors were encountered: