Skip to content

Commit

Permalink
#613 - fixed range mode (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n authored May 26, 2024
1 parent a788d34 commit 071e9a4
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### v3.5.2
* fixed range mode [#613](https://github.com/t1m0n/air-datepicker/issues/613)

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ new AirDatepicker('#el' [, options]);

## Recent updates

### v3.5.2
* fixed range mode [#613](https://github.com/t1m0n/air-datepicker/issues/613)

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

Expand Down
3 changes: 3 additions & 0 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ new AirDatepicker('#el' [, options]);

## Recent updates

### v3.5.2
* fixed range mode [#613](https://github.com/t1m0n/air-datepicker/issues/613)

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

Expand Down
2 changes: 1 addition & 1 deletion dist/air-datepicker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "air-datepicker",
"version": "3.5.1",
"version": "3.5.2",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack",
"dev:serve": "cross-env NODE_ENV=development webpack serve",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "air-datepicker",
"version": "3.5.1",
"version": "3.5.2",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack",
"dev:serve": "cross-env NODE_ENV=development webpack serve",
Expand Down
6 changes: 5 additions & 1 deletion src/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let $datepickersContainer = '',

export default class Datepicker {
static defaults = defaults
static version = '3.5.1'
static version = '3.5.2'
static defaultGlobalContainerId = 'air-datepicker-global-container'
static buildGlobalContainer(id) {
containerBuilt = true;
Expand Down Expand Up @@ -586,6 +586,10 @@ export default class Datepicker {
_this.rangeDateTo = '';
_this._updateLastSelectedDate(false);
} else {
// Assume that if unselectDate has been called, then there is only one selected date
// in range mode, so we need to reset rangeDateTo
_this.rangeDateTo = '';

_this._updateLastSelectedDate(_this.selectedDates[_this.selectedDates.length - 1]);
}

Expand Down
31 changes: 28 additions & 3 deletions tests/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,14 @@ describe('OPTIONS TESTS', () => {
describe('range', () => {
it('should enable range mode', () => {
init({
range: true
range: true,
startDate: '2023-10-10',
});

dp.selectDate(['2023-10-10', '2023-10-22']);
dp.getCell('2023-10-10').click();
dp.getCell('2023-10-22').click();

expect(Boolean(dp.rangeDateFrom && dp.rangeDateTo)).toBeTruthy();
expect(dp.selectedDates).toHaveLength(2);
});

it('should select dates in proper', () => {
Expand Down Expand Up @@ -826,5 +828,28 @@ describe('OPTIONS TESTS', () => {
expect(timeFormat.format(dp.selectedDates[0])).toEqual('10:10');
expect(timeFormat.format(dp.selectedDates[1])).toEqual('20:20');
});

it('should work correctly when user unselects one date and then selects another', () => {
init({
range: true,
toggleSelected: true,
startDate: '2024-05-26',
});

// Select two dates
dp.getCell('2024-05-12').click();
dp.getCell('2024-05-17').click();

// Unselect the last one
dp.getCell('2024-05-17').click();

// Select other 'to' date
dp.getCell('2024-05-23').click();

expect(dp.selectedDates).toHaveLength(2);
expect(dp.selectedDates[0].toLocaleDateString('ru')).toEqual('12.05.2024');
expect(dp.selectedDates[1].toLocaleDateString('ru')).toEqual('23.05.2024');

});
});
});

0 comments on commit 071e9a4

Please sign in to comment.