@danielgindi/selectbox 1.0.133 → 1.0.135

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.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 1.0.133
2
+ * @danielgindi/selectbox 1.0.135
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -2602,9 +2602,11 @@ Emits the following events:
2602
2602
  'hide:after': emitted after the hide css transition has ended, or immediately after 'hide'.
2603
2603
  'check' {value, item, checked: boolean, isGroup: boolean, isCheckingGroup: boolean}: item was selected (in multi mode).
2604
2604
  'groupcheck' {value, item, affectedItems}: item was selected (in multi mode).
2605
+ 'blur' {event}: element lost focus
2605
2606
  'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
2606
2607
  'hide_subitems {value, item, el}': subitems dropdown did hide.
2607
2608
  'subitems:select' {value, item, event?, el}: item was selected (in single mode).
2609
+ 'subitems:blur' {event}: subitems element lost focus
2608
2610
  */
2609
2611
 
2610
2612
  // noinspection JSUnusedGlobalSymbols
@@ -2862,24 +2864,6 @@ class DropList {
2862
2864
  return false;
2863
2865
  }
2864
2866
 
2865
- /**
2866
- * Returns true if document's active element is this droplist (or owned submenus)
2867
- * @param {boolean} [considerSubmenus=true]
2868
- * @returns {boolean}
2869
- */
2870
- hasFocus() {var _this$_p$currentSubDr2;let considerSubmenus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
2871
- if (!document.activeElement)
2872
- return false;
2873
-
2874
- if (document.activeElement.contains(this.el))
2875
- return true;
2876
-
2877
- if (considerSubmenus && (_this$_p$currentSubDr2 = this._p.currentSubDropList) !== null && _this$_p$currentSubDr2 !== void 0 && (_this$_p$currentSubDr2 = _this$_p$currentSubDr2.droplist) !== null && _this$_p$currentSubDr2 !== void 0 && _this$_p$currentSubDr2.hasFocus())
2878
- return true;
2879
-
2880
- return false;
2881
- }
2882
-
2883
2867
  /**
2884
2868
  * @param {string|string[]} classes
2885
2869
  * @returns {DropList}
@@ -3014,8 +2998,9 @@ class DropList {
3014
2998
  const item = p.items[p.focusItemIndex];
3015
2999
  p.focusItemIndex = -1;
3016
3000
 
3017
- if (!item)
3018
- return;
3001
+ if (!item) {
3002
+ return;
3003
+ }
3019
3004
 
3020
3005
  if (p.currentSubDropList) {
3021
3006
  this._hideSublist();
@@ -3392,6 +3377,8 @@ class DropList {
3392
3377
  // Now set the width of the dropdown
3393
3378
  if (positionOptions.updateWidth || typeof positionOptions.updateWidth === 'number') {
3394
3379
  this._updateWidth(positionOptions);
3380
+ } else {
3381
+ this._updateWidth();
3395
3382
  }
3396
3383
 
3397
3384
  // How much space is there above, and how much below?
@@ -3911,6 +3898,16 @@ class DropList {
3911
3898
  unrenderItem: p.unrenderItem
3912
3899
  });
3913
3900
 
3901
+ let onBlur = (event) => {
3902
+ if (this[DestroyedSymbol$1]) return;
3903
+
3904
+ if (event.relatedTarget && this.elContains(event.relatedTarget, true))
3905
+ return;
3906
+
3907
+ this._delayBlurItemOnBlur();
3908
+ this._trigger('subitems:blur', event);
3909
+ };
3910
+
3914
3911
  droplist.
3915
3912
  on('select', (event) => {
3916
3913
  this._trigger('subitems:select', event);
@@ -3918,6 +3915,8 @@ class DropList {
3918
3915
  on('subitems:select', (event) => {
3919
3916
  this._trigger('subitems:select', event);
3920
3917
  }).
3918
+ on('blur', onBlur).
3919
+ on('subitems:blur', onBlur).
3921
3920
  on('_back_key_pressed', () => {
3922
3921
  this._hideSublist();
3923
3922
  });
@@ -3956,7 +3955,7 @@ class DropList {
3956
3955
 
3957
3956
  const data = p.currentSubDropList;
3958
3957
 
3959
- let subHadFocus = data.droplist.hasFocus(true);
3958
+ let subHadFocus = !!document.activeElement && data.droplist.elContains(document.activeElement, true);
3960
3959
 
3961
3960
  data.droplist.hide();
3962
3961
  data.droplist.destroy();
@@ -4282,12 +4281,14 @@ class DropList {
4282
4281
 
4283
4282
  this._focus(event, itemEl, null, false);
4284
4283
  }).
4285
- add(p.el, 'blur', () => {
4284
+ add(p.el, 'blur', (event) => {
4286
4285
  setTimeout(() => {
4287
4286
  if (this[DestroyedSymbol$1]) return;
4288
4287
 
4289
- if (!p.el.contains(document.activeElement)) {
4288
+ if (!document.activeElement ||
4289
+ !this.elContains(document.activeElement, true)) {
4290
4290
  this._delayBlurItemOnBlur();
4291
+ this._trigger('blur', event);
4291
4292
  }
4292
4293
  });
4293
4294
  });
@@ -4454,6 +4455,10 @@ class DropList {
4454
4455
  _focus(event, itemEl, itemIndex, openSubitems) {var _item$ItemSymbol6;
4455
4456
  const p = this._p;
4456
4457
 
4458
+ if (p._isFocusingItem)
4459
+ return;
4460
+ p._isFocusingItem = true;
4461
+
4457
4462
  if (!itemIndex && itemEl) {
4458
4463
  itemIndex = p.virtualListHelper.getItemIndexFromElement(itemEl);
4459
4464
  }
@@ -4466,11 +4471,13 @@ class DropList {
4466
4471
 
4467
4472
  let focusItemEl = itemEl || p.virtualListHelper.getItemElementAt(itemIndex);
4468
4473
  if (!focusItemEl || focusItemEl[ItemSymbol$1]._nointeraction) {
4474
+ p._isFocusingItem = false;
4469
4475
  this.blurFocusedItem();
4470
4476
  return;
4471
4477
  }
4472
4478
 
4473
4479
  if (focusItemEl === p.focusItemEl) {
4480
+ p._isFocusingItem = false;
4474
4481
  clearTimeout(p.blurTimer);
4475
4482
  return;
4476
4483
  }
@@ -4489,6 +4496,8 @@ class DropList {
4489
4496
  el: focusItemEl
4490
4497
  });
4491
4498
 
4499
+ p._isFocusingItem = false;
4500
+
4492
4501
  if (openSubitems)
4493
4502
  this._showSublist(item, focusItemEl);
4494
4503
  }