@danielgindi/selectbox 1.0.132 → 1.0.134

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/lib/DropList.js CHANGED
@@ -137,9 +137,11 @@ Emits the following events:
137
137
  'hide:after': emitted after the hide css transition has ended, or immediately after 'hide'.
138
138
  'check' {value, item, checked: boolean, isGroup: boolean, isCheckingGroup: boolean}: item was selected (in multi mode).
139
139
  'groupcheck' {value, item, affectedItems}: item was selected (in multi mode).
140
+ 'blur' {event}: element lost focus
140
141
  'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
141
142
  'hide_subitems {value, item, el}': subitems dropdown did hide.
142
143
  'subitems:select' {value, item, event?, el}: item was selected (in single mode).
144
+ 'subitems:blur' {event}: subitems element lost focus
143
145
  */
144
146
 
145
147
  // noinspection JSUnusedGlobalSymbols
@@ -531,8 +533,9 @@ class DropList {
531
533
  const item = p.items[p.focusItemIndex];
532
534
  p.focusItemIndex = -1;
533
535
 
534
- if (!item)
536
+ if (!item) {
535
537
  return;
538
+ }
536
539
 
537
540
  if (p.currentSubDropList) {
538
541
  this._hideSublist();
@@ -1428,6 +1431,16 @@ class DropList {
1428
1431
  unrenderItem: p.unrenderItem,
1429
1432
  });
1430
1433
 
1434
+ let onBlur = event => {
1435
+ if (this[DestroyedSymbol]) return;
1436
+
1437
+ if (event.relatedTarget && this.elContains(event.relatedTarget, true))
1438
+ return;
1439
+
1440
+ this._delayBlurItemOnBlur();
1441
+ this._trigger('subitems:blur', event);
1442
+ };
1443
+
1431
1444
  droplist
1432
1445
  .on('select', event => {
1433
1446
  this._trigger('subitems:select', event);
@@ -1435,11 +1448,10 @@ class DropList {
1435
1448
  .on('subitems:select', event => {
1436
1449
  this._trigger('subitems:select', event);
1437
1450
  })
1451
+ .on('blur', onBlur)
1452
+ .on('subitems:blur', onBlur)
1438
1453
  .on('_back_key_pressed', () => {
1439
1454
  this._hideSublist();
1440
-
1441
- if (!this[DestroyedSymbol])
1442
- this.el.focus();
1443
1455
  });
1444
1456
 
1445
1457
  droplist.setItems(item._subitems);
@@ -1475,10 +1487,17 @@ class DropList {
1475
1487
  return;
1476
1488
 
1477
1489
  const data = p.currentSubDropList;
1490
+
1491
+ let subHadFocus = !!document.activeElement && data.droplist.elContains(document.activeElement, true);
1492
+
1478
1493
  data.droplist.hide();
1479
1494
  data.droplist.destroy();
1480
1495
  p.currentSubDropList = null;
1481
1496
 
1497
+ if (subHadFocus && !this[DestroyedSymbol]) {
1498
+ this.el.focus();
1499
+ }
1500
+
1482
1501
  this._trigger('hide_subitems', {
1483
1502
  value: data.item.value,
1484
1503
  item: data.item,
@@ -1795,12 +1814,14 @@ class DropList {
1795
1814
 
1796
1815
  this._focus(event, itemEl, null, false);
1797
1816
  })
1798
- .add(p.el, 'blur', () => {
1817
+ .add(p.el, 'blur', event => {
1799
1818
  setTimeout(() => {
1800
1819
  if (this[DestroyedSymbol]) return;
1801
1820
 
1802
- if (!p.el.contains(document.activeElement)) {
1821
+ if (!document.activeElement ||
1822
+ !this.elContains(document.activeElement, true)) {
1803
1823
  this._delayBlurItemOnBlur();
1824
+ this._trigger('blur', event);
1804
1825
  }
1805
1826
  });
1806
1827
  });
@@ -1967,6 +1988,10 @@ class DropList {
1967
1988
  _focus(event, itemEl, itemIndex, openSubitems) {
1968
1989
  const p = this._p;
1969
1990
 
1991
+ if (p._isFocusingItem)
1992
+ return;
1993
+ p._isFocusingItem = true;
1994
+
1970
1995
  if (!itemIndex && itemEl) {
1971
1996
  itemIndex = p.virtualListHelper.getItemIndexFromElement(itemEl);
1972
1997
  }
@@ -1979,11 +2004,13 @@ class DropList {
1979
2004
 
1980
2005
  let focusItemEl = itemEl || p.virtualListHelper.getItemElementAt(itemIndex);
1981
2006
  if (!focusItemEl || focusItemEl[ItemSymbol]._nointeraction) {
2007
+ p._isFocusingItem = false;
1982
2008
  this.blurFocusedItem();
1983
2009
  return;
1984
2010
  }
1985
2011
 
1986
2012
  if (focusItemEl === p.focusItemEl) {
2013
+ p._isFocusingItem = false;
1987
2014
  clearTimeout(p.blurTimer);
1988
2015
  return;
1989
2016
  }
@@ -2002,6 +2029,8 @@ class DropList {
2002
2029
  el: focusItemEl,
2003
2030
  });
2004
2031
 
2032
+ p._isFocusingItem = false;
2033
+
2005
2034
  if (openSubitems)
2006
2035
  this._showSublist(item, focusItemEl);
2007
2036
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielgindi/selectbox",
3
- "version": "1.0.132",
3
+ "version": "1.0.134",
4
4
  "description": "A collection of dom utilities. So you can work natively with the dom without dom frameworks.",
5
5
  "main": "dist/lib.cjs.min.js",
6
6
  "module": "lib/index.js",
package/vue/DropList.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <span v-show="false" />
2
+ <span v-show="false" />
3
3
  </template>
4
4
 
5
5
  <script>
@@ -14,8 +14,9 @@ const AllListEvents = [
14
14
  'itemfocus', 'itemblur', 'select',
15
15
  'show:before', 'show',
16
16
  'hide:before', 'hide', 'hide:after',
17
- 'check', 'groupcheck',
18
- 'show_subitems', 'hide_subitems', 'subitems:select',
17
+ 'check', 'groupcheck', 'blur',
18
+ 'show_subitems', 'hide_subitems',
19
+ 'subitems:select', 'subitems:blur',
19
20
  ];
20
21
 
21
22
  export default {
@@ -123,12 +124,13 @@ export default {
123
124
  'hide',
124
125
  'check',
125
126
  'groupcheck',
127
+ 'blur',
126
128
  'show_subitems',
127
129
  'hide_subitems',
128
130
  'subitems:select',
131
+ 'subitems:blur',
129
132
 
130
133
  // Element events
131
- 'blur',
132
134
  'keypress',
133
135
  'keydown',
134
136
  ],
@@ -136,7 +138,7 @@ export default {
136
138
  data() {
137
139
  return {
138
140
  el: undefined,
139
-
141
+
140
142
  nonReactive: Object.seal({
141
143
  instance: undefined,
142
144
  sink: new DomEventsSink(),
@@ -312,9 +314,11 @@ export default {
312
314
  case 'hide':
313
315
  case 'check':
314
316
  case 'groupcheck':
317
+ case 'blur':
315
318
  case 'show_subitems':
316
319
  case 'hide_subitems':
317
320
  case 'subitems:select':
321
+ case 'subitems:blur':
318
322
  this.$emit(event, ...(data === undefined ? [] : [data]));
319
323
  break;
320
324
  }
@@ -330,12 +334,6 @@ export default {
330
334
  this.el = list.el;
331
335
  this.nonReactive.instance = list;
332
336
 
333
- this.nonReactive.sink.add(this.nonReactive.instance.el, 'blur.vue', evt => {
334
- if (this.nonReactive.instance.el.contains(evt.relatedTarget))
335
- return;
336
- this.$emit('blur', evt);
337
- }, true);
338
-
339
337
  this.nonReactive.sink.add(this.nonReactive.instance.el, 'keydown.vue', evt => {
340
338
  this.$emit('keydown', evt);
341
339
  }, true);