-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add Month Range Picker Feature #2380
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
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
isMonthRange
option 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
isMonthRange
option 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
isMonthRange
may 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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')) { |
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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>'; |
Copilot uses AI. Check for mistakes.
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.