Add Month Range Picker Feature#2380
Conversation
- Add isMonthRange option to enable month-only selection - Implement renderMonthCalendar method for month grid display - Update updateMonthsInView to handle month range mode - Add month navigation and selection logic - Enhance styling for month picker interface
There was a problem hiding this comment.
Pull Request Overview
This PR adds a month-range selection mode to the existing date range picker, enabling users to pick entire months instead of specific dates while maintaining all current day-picker functionality.
- Introduces an
isMonthRangeoption and demo checkbox to toggle month-only mode. - Extends calendar rendering and navigation methods to support month grids and year-based navigation.
- Adds CSS styling for the month-picker table and range highlighting.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| demo.html | Added isMonthRange checkbox and demo configuration handling. |
| daterangepicker.js | Introduced isMonthRange flag, month-range rendering, navigation, and selection logic. |
| daterangepicker.css | Defined styles for the month-picker table, hover, disabled, and range states. |
Comments suppressed due to low confidence (2)
daterangepicker.js:57
- New
isMonthRangeoption and its calendar logic lack accompanying unit tests. Consider adding tests for month-range rendering, navigation, and selection behaviors to ensure coverage.
this.isMonthRange = false;
demo.html:146
- [nitpick] The label
isMonthRangemay not be user-friendly in the demo. Consider changing it to a more descriptive phrase like “Enable month-range selection.”
<input type="checkbox" id="isMonthRange"> isMonthRange
| if (this.endDate || startOfMonth.isBefore(this.startDate, 'month')) { //picking start | ||
| this.endDate = null; | ||
| this.setStartDate(startOfMonth.clone()); | ||
| } else if (!this.endDate && startOfMonth.isBefore(this.startDate, 'month')) { |
There was a problem hiding this comment.
The special-case branch for selecting the same month is unreachable because the previous if already handles startOfMonth.isBefore(this.startDate). Consider checking for equality (isSame) or reordering conditions to correctly detect clicking the same start/end month.
| } else if (!this.endDate && startOfMonth.isBefore(this.startDate, 'month')) { | |
| } else if (!this.endDate && startOfMonth.isSame(this.startDate, 'month')) { |
| renderMonthCalendar: function(side) { | ||
|
|
||
| var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar; | ||
| var year = calendar.month.year(); | ||
|
|
||
| var minDate = side == 'left' ? this.minDate : this.startDate; | ||
| var maxDate = this.maxDate; | ||
|
|
||
| var html = '<table class="table-condensed month-picker">'; | ||
| html += '<thead>'; |
There was a problem hiding this comment.
[nitpick] The renderMonthCalendar method is large and duplicates parts of renderCalendar. Refactor shared header and grid-generation logic into helper functions to reduce duplication and improve readability.
| renderMonthCalendar: function(side) { | |
| var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar; | |
| var year = calendar.month.year(); | |
| var minDate = side == 'left' ? this.minDate : this.startDate; | |
| var maxDate = this.maxDate; | |
| var html = '<table class="table-condensed month-picker">'; | |
| html += '<thead>'; | |
| generateCalendarHeader: function(year, minDate, maxDate, side) { | |
| var html = '<thead>'; |
|
The problem that in month-only mode the plugin uses a different calendar structure and never sets |
This PR adds a month range picker feature to the daterangepicker library.
Changes:
Usage:
This feature allows users to select month ranges instead of specific dates, which is useful for reporting, analytics, and other use cases where month-level granularity is preferred.