@danielgindi/selectbox 1.0.57 → 1.0.58

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.57
2
+ * @danielgindi/selectbox 1.0.58
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -23,7 +23,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
23
23
  * @property {Element} [el] An element to attach to, instead of creating a new one
24
24
  * @property {string} [baseClassName='droplist'] class name for the menu root element
25
25
  * @property {string|string[]} [additionalClasses]
26
- * @property {number} [itemBlurDelay=300] How long to wait before deciding to blur the focused item?
26
+ * @property {boolean} [autoItemBlur=true] Should we automatically blur the focused item when the droplist loses focus?
27
+ * @property {number} [autoItemBlurDelay=300] How long to wait before deciding to blur the focused item (when the droplist loses focus)?
27
28
  * @property {boolean} [capturesFocus=true] Should this DropList be added to the TAB-key stack?
28
29
  * @property {boolean} [multi=false] Does this DropList show checkboxes for multiple item selection?
29
30
  * @property {function} [keyDownHandler=null] An alternative "keydown" event handler. Return true to prevent default behaviour.
@@ -83,7 +84,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
83
84
  let defaultOptions$1 = {
84
85
  baseClassName: 'droplist',
85
86
 
86
- itemBlurDelay: 300,
87
+ autoItemBlur: true,
88
+ autoItemBlurDelay: 300,
87
89
  capturesFocus: true,
88
90
  multi: false,
89
91
  keyDownHandler: null,
@@ -106,9 +108,9 @@ let defaultOptions$1 = {
106
108
  Emits the following events:
107
109
  ---------------------------
108
110
 
109
- 'itemfocus' {value, item, event}: item gained focus.
111
+ 'itemfocus' {value, item, event?, el}: item gained focus.
110
112
  'itemblur' {value, item}: item lost focus.
111
- 'select' {value, item}: item was selected (in single mode).
113
+ 'select' {value, item, event?, el}: item was selected (in single mode).
112
114
  'show:before': the drop list will show.
113
115
  'show': the drop list has been shown.
114
116
  'hide:before': the drop list will hide.
@@ -125,7 +127,7 @@ class DropList {
125
127
  * @param {DropList.Options} options
126
128
  */
127
129
  constructor(options) {
128
- const o = { ...defaultOptions$1 };
130
+ const o = {...defaultOptions$1};
129
131
 
130
132
  for (let [key, value] of Object.entries(/**@type Object*/options))
131
133
  if (value !== undefined)
@@ -137,7 +139,8 @@ class DropList {
137
139
 
138
140
  baseClassName: o.baseClassName,
139
141
  additionalClasses: o.additionalClasses,
140
- itemBlurDelay: o.itemBlurDelay,
142
+ autoItemBlur: o.autoItemBlur,
143
+ autoItemBlurDelay: o.autoItemBlurDelay,
141
144
  capturesFocus: o.capturesFocus,
142
145
  multi: o.multi,
143
146
  keyDownHandler: o.keyDownHandler,
@@ -274,7 +277,9 @@ class DropList {
274
277
  p.virtualListHelper.setOnItemUnrender(el => {
275
278
  try {
276
279
  fn(el[ItemSymbol$1][ItemSymbol$1], el);
277
- } catch (err) { console.error(err); } // eslint-disable-line no-console
280
+ } catch (err) {
281
+ console.error(err);
282
+ } // eslint-disable-line no-console
278
283
  delete el[ItemSymbol$1];
279
284
 
280
285
  if (p.focusItemEl === el)
@@ -393,7 +398,9 @@ class DropList {
393
398
  p.virtualListHelper.setOnItemUnrender(el => {
394
399
  try {
395
400
  fn(el[ItemSymbol$1][ItemSymbol$1], el);
396
- } catch (err) { console.error(err); } // eslint-disable-line no-console
401
+ } catch (err) {
402
+ console.error(err);
403
+ } // eslint-disable-line no-console
397
404
  delete el[ItemSymbol$1];
398
405
 
399
406
  if (p.focusItemEl === el)
@@ -457,7 +464,7 @@ class DropList {
457
464
  if (!item)
458
465
  return;
459
466
 
460
- this._trigger('itemblur', { value: item.value, item: item[ItemSymbol$1] ?? item });
467
+ this._trigger('itemblur', {value: item.value, item: item[ItemSymbol$1] ?? item});
461
468
  }
462
469
 
463
470
  nextPage(event) {
@@ -514,6 +521,7 @@ class DropList {
514
521
  value: item ? item.value : undefined,
515
522
  item: item[ItemSymbol$1] ?? item,
516
523
  event: event,
524
+ el: p.focusItemEl,
517
525
  });
518
526
 
519
527
  return true;
@@ -923,8 +931,8 @@ class DropList {
923
931
 
924
932
  if (p.autoFlipDirection) {
925
933
  if ((position.specX === 'right' &&
926
- viewCss.left < minX &&
927
- (Math.max(viewCss.left, minX) + viewSize.width - targetBox.left) / targetBox.width > 0.5) ||
934
+ viewCss.left < minX &&
935
+ (Math.max(viewCss.left, minX) + viewSize.width - targetBox.left) / targetBox.width > 0.5) ||
928
936
  (position.specX === 'left' &&
929
937
  viewCss.left > maxX &&
930
938
  (Math.min(viewCss.left, maxX) - targetBox.left) / targetBox.width < 0.5)) {
@@ -1108,7 +1116,7 @@ class DropList {
1108
1116
  // Detect mouse tap outside of the droplist, to blur the focused item
1109
1117
  p.sink.add(document, 'mousedown', p.onDocumentMouseDown = (event) => {
1110
1118
  if (!p.el.contains(event.target))
1111
- this._delayBlur();
1119
+ this._delayBlurItemOnBlur();
1112
1120
  });
1113
1121
  }
1114
1122
  });
@@ -1257,7 +1265,12 @@ class DropList {
1257
1265
  itemElement.classList.add(`${p.baseClassName}__item_focus`);
1258
1266
  p.focusItemEl = itemElement;
1259
1267
 
1260
- this._trigger('itemfocus', { value: itemElement.value, item: itemElement[ItemSymbol$1], event: null });
1268
+ this._trigger('itemfocus', {
1269
+ value: itemElement.value,
1270
+ item: itemElement[ItemSymbol$1],
1271
+ event: null,
1272
+ el: itemElement,
1273
+ });
1261
1274
  }
1262
1275
  }
1263
1276
 
@@ -1532,7 +1545,9 @@ class DropList {
1532
1545
 
1533
1546
  // Track scrolling
1534
1547
  let didScroll = false;
1535
- let onScroll = () => { didScroll = true; };
1548
+ let onScroll = () => {
1549
+ didScroll = true;
1550
+ };
1536
1551
  let onTouchCancel = () => {
1537
1552
  currentTouchId = null;
1538
1553
  p.sink.remove(null, '.dropdown_touchextra');
@@ -1581,7 +1596,7 @@ class DropList {
1581
1596
  if (this[DestroyedSymbol$1]) return;
1582
1597
 
1583
1598
  if (!p.el.contains(document.activeElement)) {
1584
- this._delayBlur();
1599
+ this._delayBlurItemOnBlur();
1585
1600
  }
1586
1601
  });
1587
1602
  });
@@ -1764,21 +1779,24 @@ class DropList {
1764
1779
  p.focusItemIndex = itemIndex;
1765
1780
 
1766
1781
  const item = p.items[itemIndex];
1767
- this._trigger('itemfocus', { value: item.value, item: item[ItemSymbol$1] ?? item, event: event });
1782
+ this._trigger('itemfocus', {value: item.value, item: item[ItemSymbol$1] ?? item, event: event, el: focusItemEl});
1768
1783
  }
1769
1784
 
1770
- _delayBlur() {
1785
+ _delayBlurItemOnBlur() {
1771
1786
  if (this[DestroyedSymbol$1])
1772
1787
  return;
1773
1788
 
1774
1789
  const p = this._p;
1775
1790
 
1791
+ if (!p.autoItemBlur)
1792
+ return;
1793
+
1776
1794
  clearTimeout(p.blurTimer);
1777
1795
 
1778
1796
  p.blurTimer = setTimeout(() => {
1779
1797
  if (this[DestroyedSymbol$1]) return;
1780
1798
  this.blurFocusedItem();
1781
- }, p.itemBlurDelay);
1799
+ }, p.autoItemBlurDelay);
1782
1800
  }
1783
1801
 
1784
1802
  _move(direction, event) {
@@ -1964,7 +1982,11 @@ class DropList {
1964
1982
  }
1965
1983
 
1966
1984
  // Fire event
1967
- this._trigger('groupcheck', { value: item.value, item: item[ItemSymbol$1] ?? item, affectedItems: affectedItems });
1985
+ this._trigger('groupcheck', {
1986
+ value: item.value,
1987
+ item: item[ItemSymbol$1] ?? item,
1988
+ affectedItems: affectedItems
1989
+ });
1968
1990
  } else if (p.groupCount > 0) {
1969
1991
  items = p.items;
1970
1992
  itemIndex = items.indexOf(item);
@@ -2121,7 +2143,7 @@ class DropList {
2121
2143
  if (p.multi) {
2122
2144
  if (!item._nocheck) {
2123
2145
  itemEl.insertBefore(
2124
- createElement('span', { class: 'checkbox' }),
2146
+ createElement('span', {class: 'checkbox'}),
2125
2147
  itemEl.firstChild,
2126
2148
  );
2127
2149
  }