@kupola/kupola 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/dropdown.js CHANGED
@@ -170,7 +170,10 @@ class Dropdown {
170
170
 
171
171
  // Document click to close
172
172
  this._documentClickHandler = (e) => {
173
- if (!this.element.contains(e.target) && !this.menu.contains(e.target)) {
173
+ if (!this.isOpen) return;
174
+ const isInElement = this.element.contains(e.target);
175
+ const isInMenu = this.menu && this.menu.contains(e.target);
176
+ if (!isInElement && !isInMenu) {
174
177
  this.hideMenu();
175
178
  }
176
179
  };
@@ -183,8 +186,8 @@ class Dropdown {
183
186
 
184
187
  _bindMenuItems() {
185
188
  this.menu.querySelectorAll('.ds-dropdown__item').forEach(item => {
186
- item.addEventListener('click', (e) => this._itemClickHandler(e));
187
189
  item._dropdownItemClickHandler = (e) => this._itemClickHandler(e);
190
+ item.addEventListener('click', item._dropdownItemClickHandler);
188
191
  });
189
192
  }
190
193
 
@@ -383,11 +386,13 @@ class Dropdown {
383
386
  if (item.value !== undefined) {el.setAttribute('data-value', item.value);}
384
387
  if (item.icon) {el.innerHTML = item.icon + el.innerHTML;}
385
388
  if (item.disabled) {el.classList.add('is-disabled');}
389
+
390
+ el._dropdownItemClickHandler = (e) => this._itemClickHandler(e);
391
+ el.addEventListener('click', el._dropdownItemClickHandler);
392
+
386
393
  this.menu.appendChild(el);
387
394
  }
388
395
  });
389
-
390
- this._bindMenuItems();
391
396
  }
392
397
 
393
398
  destroy() {
package/js/select.js CHANGED
@@ -133,7 +133,10 @@ class Select {
133
133
 
134
134
  // Document click to close
135
135
  this._documentClickHandler = (e) => {
136
- if (!this.element.contains(e.target) && !this.optionsEl.contains(e.target)) {
136
+ if (!this.isOpen) return;
137
+ const isInElement = this.element.contains(e.target);
138
+ const isInOptions = this.optionsEl && this.optionsEl.contains(e.target);
139
+ if (!isInElement && !isInOptions) {
137
140
  this.hideOptions();
138
141
  }
139
142
  };
@@ -246,8 +249,8 @@ class Select {
246
249
  if (opt.disabled) el.classList.add('is-disabled');
247
250
  if (this.selectedValues.has(opt.value)) el.classList.add('is-selected');
248
251
 
249
- el.addEventListener('click', (e) => this._optionClickHandler(e));
250
252
  el._selectOptionClickHandler = (e) => this._optionClickHandler(e);
253
+ el.addEventListener('click', el._selectOptionClickHandler);
251
254
 
252
255
  this.optionsEl.appendChild(el);
253
256
  });
@@ -408,8 +411,8 @@ class Select {
408
411
 
409
412
  _bindOptionClicks() {
410
413
  this.optionsEl.querySelectorAll('.ds-select__option, .ds-select__item').forEach(option => {
411
- option.addEventListener('click', (e) => this._optionClickHandler(e));
412
414
  option._selectOptionClickHandler = (e) => this._optionClickHandler(e);
415
+ option.addEventListener('click', option._selectOptionClickHandler);
413
416
  });
414
417
  }
415
418
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kupola/kupola",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "A lightweight UI toolkit for any web project. No heavy frontend frameworks required.",
5
5
  "main": "dist/kupola.cjs.js",
6
6
  "module": "dist/kupola.esm.js",