Skip to content

Commit

Permalink
simplepicker: Don't modify elements outside the simplepicker elements.
Browse files Browse the repository at this point in the history
The bug here was initElMethod was called with wrong element, we fix this
by calling it in the init method where we first query the simplepicker
and then calling the method so scope the this.$ and this.$$ to it.

Fixes: #25.
  • Loading branch information
priyank-p committed Aug 26, 2020
1 parent 43e9cd3 commit 6ad2ed8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ class SimplePicker {
}

this.selectedDate = new Date();
this.initElMethod(el);
this.injectTemplate(el);
this.init(opts);
this.init(el, opts);
this.initListeners();

this._eventHandlers = {};
Expand All @@ -86,11 +85,12 @@ class SimplePicker {
this.$$ = (sel) => el.querySelectorAll(sel);
}

init(opts: SimplePickerOpts) {
const { $, $$ } = this;
init(el: HTMLElement, opts: SimplePickerOpts) {
this.$simplepickerWrapper = <HTMLElement> el.querySelector('.simplepicker-wrapper');
this.initElMethod(this.$simplepickerWrapper);

const { $, $$ } = this;
this.$simplepicker = $('.simpilepicker-date-picker');
this.$simplepickerWrapper = $('.simplepicker-wrapper');
this.$trs = $$('.simplepicker-calender tbody tr');
this.$tds = $$('.simplepicker-calender tbody td');
this.$headerMonthAndYear = $('.simplepicker-month-and-year');
Expand Down

0 comments on commit 6ad2ed8

Please sign in to comment.