@danielgindi/selectbox 1.0.137 → 1.0.139

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/dist/lib.es6.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 1.0.137
2
+ * @danielgindi/selectbox 1.0.139
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -1561,7 +1561,7 @@ class DropList {
1561
1561
  let itemPos, previousPos = -1;
1562
1562
  let maxIterations = 30; // Some zoom/scroll issues can make it so that it takes almost forever
1563
1563
 
1564
- // eslint-disable-next-line no-constant-condition
1564
+
1565
1565
  while (maxIterations-- > 0) {
1566
1566
  itemPos = p.virtualListHelper.getItemPosition(itemIndex);
1567
1567
 
@@ -1803,11 +1803,12 @@ class DropList {
1803
1803
  setTimeout(() => {
1804
1804
  if (this[DestroyedSymbol$1]) return;
1805
1805
 
1806
- if (!document.activeElement ||
1807
- !this.elContains(document.activeElement, true)) {
1808
- this._delayBlurItemOnBlur();
1809
- this._trigger('blur', event);
1806
+ if (document.activeElement && this.elContains(document.activeElement, true)) {
1807
+ return;
1810
1808
  }
1809
+
1810
+ this._delayBlurItemOnBlur();
1811
+ this._trigger('blur', event);
1811
1812
  });
1812
1813
  });
1813
1814
  }
@@ -2099,7 +2100,7 @@ class DropList {
2099
2100
  let base = getElementOffset(p.focusItemEl).top;
2100
2101
  let height = getElementHeight(p.el, true);
2101
2102
 
2102
- while (true) { // eslint-disable-line no-constant-condition
2103
+ while (true) {
2103
2104
  next = p.focusItemEl.nextElementSibling;
2104
2105
  if (!next) return;
2105
2106
  if (next.tagName !== 'LI') continue;
@@ -2919,6 +2920,20 @@ class SelectBox {
2919
2920
  return this._p.el;
2920
2921
  }
2921
2922
 
2923
+ get droplistInstance() {
2924
+ return this._p.dropList;
2925
+ }
2926
+
2927
+ /**
2928
+ * Returns true if other is an inclusive descendant of droplist node, false otherwise, and undefined if the droplist is not initiated.
2929
+ * @param {Node} other
2930
+ * @param {boolean} [considerSubmenus=true]
2931
+ * @returns {boolean|undefined}
2932
+ */
2933
+ droplistElContains(other, considerSubmenus = true) {
2934
+ return this._p.dropList?.elContains(other, considerSubmenus);
2935
+ }
2936
+
2922
2937
  /**
2923
2938
  * Enables the control
2924
2939
  * @param {boolean=true} enabled Should the control be enabled?
@@ -4413,6 +4428,9 @@ class SelectBox {
4413
4428
  }
4414
4429
  }
4415
4430
  break;
4431
+
4432
+ case 'blur':
4433
+ this._handleOnBlur();
4416
4434
  }
4417
4435
  },
4418
4436
  });
@@ -4427,6 +4445,27 @@ class SelectBox {
4427
4445
  this._registerDropdownEvents();
4428
4446
  }
4429
4447
 
4448
+ _handleOnBlur() {
4449
+ const p = this._p;
4450
+
4451
+ setTimeout(() => {
4452
+ if (p.disabled) return;
4453
+
4454
+ this._trigger('search:blur');
4455
+
4456
+ if (this[DestroyedSymbol]) return; // destroyed by event handler
4457
+
4458
+ if (document.activeElement &&
4459
+ (p.input && p.input.contains(document.activeElement) ||
4460
+ p.dropList && this.droplistElContains(document.activeElement, true))) {
4461
+ return;
4462
+ }
4463
+ if (p.throttledUpdateListItems)
4464
+ p.throttledUpdateListItems.cancel();
4465
+ this.closeList();
4466
+ });
4467
+ }
4468
+
4430
4469
  _unregisterDropdownEvents() {
4431
4470
  const p = this._p;
4432
4471
 
@@ -4596,18 +4635,7 @@ class SelectBox {
4596
4635
  avoidToggleFromClick = true;
4597
4636
  setTimeout(() => { avoidToggleFromClick = false; }, 10);
4598
4637
  })
4599
- .add(p.input, 'blur.dropdown', () => {
4600
- if (p.disabled) return;
4601
-
4602
- this._trigger('search:blur');
4603
-
4604
- if (this[DestroyedSymbol]) return; // destroyed by event handler
4605
-
4606
- if (p.throttledUpdateListItems)
4607
- p.throttledUpdateListItems.cancel();
4608
-
4609
- this.closeList();
4610
- });
4638
+ .add(p.input, 'blur.dropdown', () => this._handleOnBlur());
4611
4639
  }
4612
4640
 
4613
4641
  p.sink