Skip to content

Commit

Permalink
fix: fixed update with view option when calendar is hidden, fixes t…
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0n committed May 18, 2022
1 parent ce53cd0 commit 716dbbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,9 @@ export default class Datepicker {

this.currentView = view;

if (this.elIsInput && this.visible) this.setPosition(undefined, true);
if (this.elIsInput && this.visible) {
this.setPosition(undefined, true);
}

// Trigger inner event before new view is inited, to avoid multiple render calls in datepicker body
this.trigger(consts.eventChangeCurrentView, view);
Expand All @@ -994,7 +996,9 @@ export default class Datepicker {
type: view
});

this.$content.appendChild(newView.$el);
if (this.shouldUpdateDOM) {
this.$content.appendChild(newView.$el);
}
}

// Trigger user event after, to be able to use datepicker api on rendered view
Expand Down Expand Up @@ -1274,6 +1278,10 @@ export default class Datepicker {
// Helpers
// -------------------------------------------------

get shouldUpdateDOM() {
return this.visible || this.treatAsInline;
}

get parsedViewDate() {
return getParsedDate(this.viewDate);
}
Expand Down
16 changes: 12 additions & 4 deletions tests/api.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {beforeAll, afterEach, describe, test, it, expect} from '@jest/globals';
import Datepicker from 'datepicker';
import {isSameDate} from 'utils';
import en from 'locale/en';
import de from 'locale/de';
import consts from 'consts';

let $input, $altInput, dp, $datepicker;

Expand Down Expand Up @@ -65,5 +61,17 @@ describe('API TESTS', () => {
});
}).not.toThrow();
});

test('update `view` when calendar is hidden', () => {
init({
visible: false
});
expect(() => {
dp.update({
view: 'months'
});
}
).not.toThrow();
});
});
});

0 comments on commit 716dbbe

Please sign in to comment.