Skip to content

Commit

Permalink
fixed white spaces selection in calendar component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ana Belciug committed Nov 24, 2021
1 parent 3688c9d commit 863d756
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**Fixed:**

- bpk-component-calendar:
- bpk-component-scrollable-calendar:
- Fixed white spaces selection in calendar component.
50 changes: 49 additions & 1 deletion packages/bpk-component-calendar/src/Week.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
isSameMonth,
isToday,
isWithinRange,
isAfter,
isBefore,
} from './date-utils';
import CustomPropTypes, { CALENDAR_SELECTION_TYPE } from './custom-proptypes';
// TODO: Move this to `Week.scss`
Expand Down Expand Up @@ -83,9 +85,19 @@ function getSelectedDate(date, selectionConfiguration) {
* @param {Date} date the current date of the calendar
* @param {Object} selectionConfiguration the current selection configuration
* @param {Function} formatDateFull function to format dates
* @param {Date} month the current month of the calendar
* @param {Number} weekStartsOn index of the first day of the week
* @param {Boolean} ignoreOutsideDate ignore date outside current month
* @returns {String} selection type to be passed to the date
*/
function getSelectionType(date, selectionConfiguration, formatDateFull) {
function getSelectionType(
date,
selectionConfiguration,
formatDateFull,
month,
weekStartsOn,
ignoreOutsideDate,
) {
if (
selectionConfiguration.type === CALENDAR_SELECTION_TYPE.single &&
selectionConfiguration.date === formatDateFull(date)
Expand All @@ -104,6 +116,38 @@ function getSelectionType(date, selectionConfiguration, formatDateFull) {
) {
return SELECTION_TYPES.single;
}
if (
ignoreOutsideDate &&
selectionConfiguration.startDate &&
selectionConfiguration.endDate &&
isSameMonth(
selectionConfiguration.startDate,
selectionConfiguration.endDate,
) &&
isWithinRange(date, {
start: selectionConfiguration.startDate,
end: selectionConfiguration.endDate,
}) &&
!isSameMonth(month, date)
) {
return SELECTION_TYPES.none;
}
if (
ignoreOutsideDate &&
selectionConfiguration.startDate &&
selectionConfiguration.endDate &&
!isSameMonth(
selectionConfiguration.startDate,
selectionConfiguration.endDate,
) &&
!isSameMonth(month, date) &&
((isSameWeek(date, selectionConfiguration.endDate, { weekStartsOn }) &&
isAfter(date, selectionConfiguration.startDate)) ||
(isSameWeek(date, selectionConfiguration.startDate, { weekStartsOn }) &&
isBefore(date, selectionConfiguration.endDate)))
) {
return SELECTION_TYPES.middle;
}
if (
selectionConfiguration.startDate &&
selectionConfiguration.endDate &&
Expand Down Expand Up @@ -277,6 +321,7 @@ class Week extends Component {
selectionConfiguration,
ignoreOutsideDate,
dateProps,
weekStartsOn,
} = this.props;

if (ignoreOutsideDate) {
Expand All @@ -303,6 +348,9 @@ class Week extends Component {
date,
selectionConfiguration,
formatDateFull,
month,
weekStartsOn,
ignoreOutsideDate,
);

return (
Expand Down

0 comments on commit 863d756

Please sign in to comment.