@danielgindi/selectbox 1.0.54 → 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.cjs.js +44 -18
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +48 -22
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +44 -18
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/DropList.js +47 -21
- package/package.json +1 -1
- package/vue/DropList.vue +34 -8
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 1.0.
|
|
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 {
|
|
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
|
-
|
|
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 = {
|
|
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
|
-
|
|
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) {
|
|
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) {
|
|
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', {
|
|
467
|
+
this._trigger('itemblur', {value: item.value, item: item[ItemSymbol$1] ?? item});
|
|
461
468
|
}
|
|
462
469
|
|
|
463
470
|
nextPage(event) {
|
|
@@ -510,7 +517,12 @@ class DropList {
|
|
|
510
517
|
this._setSingleSelectedItemEl(p.focusItemEl);
|
|
511
518
|
}
|
|
512
519
|
|
|
513
|
-
this._trigger('select', {
|
|
520
|
+
this._trigger('select', {
|
|
521
|
+
value: item ? item.value : undefined,
|
|
522
|
+
item: item[ItemSymbol$1] ?? item,
|
|
523
|
+
event: event,
|
|
524
|
+
el: p.focusItemEl,
|
|
525
|
+
});
|
|
514
526
|
|
|
515
527
|
return true;
|
|
516
528
|
}
|
|
@@ -919,8 +931,8 @@ class DropList {
|
|
|
919
931
|
|
|
920
932
|
if (p.autoFlipDirection) {
|
|
921
933
|
if ((position.specX === 'right' &&
|
|
922
|
-
|
|
923
|
-
|
|
934
|
+
viewCss.left < minX &&
|
|
935
|
+
(Math.max(viewCss.left, minX) + viewSize.width - targetBox.left) / targetBox.width > 0.5) ||
|
|
924
936
|
(position.specX === 'left' &&
|
|
925
937
|
viewCss.left > maxX &&
|
|
926
938
|
(Math.min(viewCss.left, maxX) - targetBox.left) / targetBox.width < 0.5)) {
|
|
@@ -1104,7 +1116,7 @@ class DropList {
|
|
|
1104
1116
|
// Detect mouse tap outside of the droplist, to blur the focused item
|
|
1105
1117
|
p.sink.add(document, 'mousedown', p.onDocumentMouseDown = (event) => {
|
|
1106
1118
|
if (!p.el.contains(event.target))
|
|
1107
|
-
this.
|
|
1119
|
+
this._delayBlurItemOnBlur();
|
|
1108
1120
|
});
|
|
1109
1121
|
}
|
|
1110
1122
|
});
|
|
@@ -1253,7 +1265,12 @@ class DropList {
|
|
|
1253
1265
|
itemElement.classList.add(`${p.baseClassName}__item_focus`);
|
|
1254
1266
|
p.focusItemEl = itemElement;
|
|
1255
1267
|
|
|
1256
|
-
this._trigger('itemfocus', {
|
|
1268
|
+
this._trigger('itemfocus', {
|
|
1269
|
+
value: itemElement.value,
|
|
1270
|
+
item: itemElement[ItemSymbol$1],
|
|
1271
|
+
event: null,
|
|
1272
|
+
el: itemElement,
|
|
1273
|
+
});
|
|
1257
1274
|
}
|
|
1258
1275
|
}
|
|
1259
1276
|
|
|
@@ -1528,7 +1545,9 @@ class DropList {
|
|
|
1528
1545
|
|
|
1529
1546
|
// Track scrolling
|
|
1530
1547
|
let didScroll = false;
|
|
1531
|
-
let onScroll = () => {
|
|
1548
|
+
let onScroll = () => {
|
|
1549
|
+
didScroll = true;
|
|
1550
|
+
};
|
|
1532
1551
|
let onTouchCancel = () => {
|
|
1533
1552
|
currentTouchId = null;
|
|
1534
1553
|
p.sink.remove(null, '.dropdown_touchextra');
|
|
@@ -1577,7 +1596,7 @@ class DropList {
|
|
|
1577
1596
|
if (this[DestroyedSymbol$1]) return;
|
|
1578
1597
|
|
|
1579
1598
|
if (!p.el.contains(document.activeElement)) {
|
|
1580
|
-
this.
|
|
1599
|
+
this._delayBlurItemOnBlur();
|
|
1581
1600
|
}
|
|
1582
1601
|
});
|
|
1583
1602
|
});
|
|
@@ -1760,21 +1779,24 @@ class DropList {
|
|
|
1760
1779
|
p.focusItemIndex = itemIndex;
|
|
1761
1780
|
|
|
1762
1781
|
const item = p.items[itemIndex];
|
|
1763
|
-
this._trigger('itemfocus', {
|
|
1782
|
+
this._trigger('itemfocus', {value: item.value, item: item[ItemSymbol$1] ?? item, event: event, el: focusItemEl});
|
|
1764
1783
|
}
|
|
1765
1784
|
|
|
1766
|
-
|
|
1785
|
+
_delayBlurItemOnBlur() {
|
|
1767
1786
|
if (this[DestroyedSymbol$1])
|
|
1768
1787
|
return;
|
|
1769
1788
|
|
|
1770
1789
|
const p = this._p;
|
|
1771
1790
|
|
|
1791
|
+
if (!p.autoItemBlur)
|
|
1792
|
+
return;
|
|
1793
|
+
|
|
1772
1794
|
clearTimeout(p.blurTimer);
|
|
1773
1795
|
|
|
1774
1796
|
p.blurTimer = setTimeout(() => {
|
|
1775
1797
|
if (this[DestroyedSymbol$1]) return;
|
|
1776
1798
|
this.blurFocusedItem();
|
|
1777
|
-
}, p.
|
|
1799
|
+
}, p.autoItemBlurDelay);
|
|
1778
1800
|
}
|
|
1779
1801
|
|
|
1780
1802
|
_move(direction, event) {
|
|
@@ -1960,7 +1982,11 @@ class DropList {
|
|
|
1960
1982
|
}
|
|
1961
1983
|
|
|
1962
1984
|
// Fire event
|
|
1963
|
-
this._trigger('groupcheck', {
|
|
1985
|
+
this._trigger('groupcheck', {
|
|
1986
|
+
value: item.value,
|
|
1987
|
+
item: item[ItemSymbol$1] ?? item,
|
|
1988
|
+
affectedItems: affectedItems
|
|
1989
|
+
});
|
|
1964
1990
|
} else if (p.groupCount > 0) {
|
|
1965
1991
|
items = p.items;
|
|
1966
1992
|
itemIndex = items.indexOf(item);
|
|
@@ -2117,7 +2143,7 @@ class DropList {
|
|
|
2117
2143
|
if (p.multi) {
|
|
2118
2144
|
if (!item._nocheck) {
|
|
2119
2145
|
itemEl.insertBefore(
|
|
2120
|
-
createElement('span', {
|
|
2146
|
+
createElement('span', {class: 'checkbox'}),
|
|
2121
2147
|
itemEl.firstChild,
|
|
2122
2148
|
);
|
|
2123
2149
|
}
|