@danielgindi/selectbox 2.0.53 → 2.0.55
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/css/droplist.css +1 -1
- package/css/droplist.css.map +1 -1
- package/dist/lib.cjs.js +4732 -13521
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -4
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +4716 -7041
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -4
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +4758 -13539
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -4
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/DropList.js +150 -118
- package/lib/SelectBox.js +20 -9
- package/package.json +12 -18
- package/scss/droplist.scss +18 -12
package/lib/DropList.js
CHANGED
|
@@ -48,6 +48,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
48
48
|
* @property {number} [autoItemBlurDelay=300] How long to wait before deciding to blur the focused item (when the droplist loses focus)?
|
|
49
49
|
* @property {boolean} [capturesFocus=true] Should this DropList be added to the TAB-key stack?
|
|
50
50
|
* @property {boolean} [multi=false] Does this DropList show checkboxes for multiple item selection?
|
|
51
|
+
* @property {*} [singleSelectedValue] Current selected value when using single selection.
|
|
51
52
|
* @property {function} [keyDownHandler=null] An alternative "keydown" event handler. Return true to prevent default behaviour.
|
|
52
53
|
* @property {boolean} [autoCheckGroupChildren=true] When a group is checked/unchecked - all items beneath it will update accordingly
|
|
53
54
|
* @property {boolean} [useExactTargetWidth=false] Use the exact target's width, do not allow growing
|
|
@@ -63,8 +64,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
|
63
64
|
* @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderNoResultsItem]
|
|
64
65
|
* @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderNoResultsItem]
|
|
65
66
|
* @property {function(name: string, data: *)} [on]
|
|
66
|
-
* @property {boolean} [isHeaderVisible=false] show header element
|
|
67
|
-
* @property {boolean} [isFooterVisible=false] show footer element
|
|
67
|
+
* @property {boolean} [isHeaderVisible=false] show header element
|
|
68
|
+
* @property {boolean} [isFooterVisible=false] show footer element
|
|
68
69
|
* @property {boolean} [searchable=false] include inline search box
|
|
69
70
|
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
70
71
|
* @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
|
|
@@ -122,6 +123,7 @@ export const DefaultOptions = {
|
|
|
122
123
|
autoItemBlurDelay: 300,
|
|
123
124
|
capturesFocus: true,
|
|
124
125
|
multi: false,
|
|
126
|
+
singleSelectedValue: undefined,
|
|
125
127
|
keyDownHandler: null,
|
|
126
128
|
autoCheckGroupChildren: true,
|
|
127
129
|
useExactTargetWidth: false,
|
|
@@ -137,8 +139,8 @@ export const DefaultOptions = {
|
|
|
137
139
|
|
|
138
140
|
on: null,
|
|
139
141
|
|
|
140
|
-
isHeaderVisible: false,
|
|
141
|
-
isFooterVisible: false,
|
|
142
|
+
isHeaderVisible: false,
|
|
143
|
+
isFooterVisible: false,
|
|
142
144
|
searchable: false,
|
|
143
145
|
noResultsText: 'No matching results',
|
|
144
146
|
filterThrottleWindow: 300,
|
|
@@ -163,7 +165,7 @@ Emits the following events:
|
|
|
163
165
|
'groupcheck' {value, item, affectedCount: number}: item was selected (in multi mode).
|
|
164
166
|
'blur' {event}: element lost focus
|
|
165
167
|
'show_subitems {value, item, el, droplist: DropList}': subitems dropdown will show.
|
|
166
|
-
'hide_subitems {value, item, el}': subitems dropdown did hide.
|
|
168
|
+
'hide_subitems {value, item, el, droplist: DropList}': subitems dropdown did hide.
|
|
167
169
|
'subitems:select' {value, item, event?, el}: item was selected (in single mode).
|
|
168
170
|
'subitems:blur' {event}: subitems element lost focus
|
|
169
171
|
*/
|
|
@@ -193,6 +195,7 @@ class DropList {
|
|
|
193
195
|
autoItemBlurDelay: o.autoItemBlurDelay,
|
|
194
196
|
capturesFocus: o.capturesFocus,
|
|
195
197
|
multi: o.multi,
|
|
198
|
+
singleSelectedValue: o.singleSelectedValue,
|
|
196
199
|
keyDownHandler: o.keyDownHandler,
|
|
197
200
|
autoCheckGroupChildren: o.autoCheckGroupChildren,
|
|
198
201
|
useExactTargetWidth: o.useExactTargetWidth,
|
|
@@ -211,8 +214,8 @@ class DropList {
|
|
|
211
214
|
positionOptionsProvider: o.positionOptionsProvider ?? null,
|
|
212
215
|
|
|
213
216
|
searchable: o.searchable,
|
|
214
|
-
isHeaderVisible: o.isHeaderVisible,
|
|
215
|
-
isFooterVisible: o.isFooterVisible,
|
|
217
|
+
isHeaderVisible: o.isHeaderVisible,
|
|
218
|
+
isFooterVisible: o.isFooterVisible,
|
|
216
219
|
|
|
217
220
|
silenceEvents: true,
|
|
218
221
|
mitt: mitt(),
|
|
@@ -266,27 +269,27 @@ class DropList {
|
|
|
266
269
|
menuEl.role = 'menu';
|
|
267
270
|
p.menuEl = menuEl;
|
|
268
271
|
|
|
269
|
-
p.headerEl = createElement('div', {
|
|
270
|
-
class: p.baseClassName + '_header',
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
p.footerEl = createElement('div', {
|
|
274
|
-
class: p.baseClassName + '_footer',
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
if (o.searchable) {
|
|
278
|
-
this.setSearchable(true);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (o.isHeaderVisible)
|
|
282
|
-
this.setHeaderVisible(o.isHeaderVisible);
|
|
283
|
-
|
|
284
|
-
wrapperEl.appendChild(menuEl);
|
|
285
|
-
|
|
286
|
-
if (o.isFooterVisible)
|
|
287
|
-
this.setFooterVisible(o.isFooterVisible);
|
|
288
|
-
|
|
289
|
-
p.items = [];
|
|
272
|
+
p.headerEl = createElement('div', {
|
|
273
|
+
class: p.baseClassName + '_header',
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
p.footerEl = createElement('div', {
|
|
277
|
+
class: p.baseClassName + '_footer',
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
if (o.searchable) {
|
|
281
|
+
this.setSearchable(true);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (o.isHeaderVisible)
|
|
285
|
+
this.setHeaderVisible(o.isHeaderVisible);
|
|
286
|
+
|
|
287
|
+
wrapperEl.appendChild(menuEl);
|
|
288
|
+
|
|
289
|
+
if (o.isFooterVisible)
|
|
290
|
+
this.setFooterVisible(o.isFooterVisible);
|
|
291
|
+
|
|
292
|
+
p.items = [];
|
|
290
293
|
p.groupCount = 0; // This will keep state of how many `group` items we have
|
|
291
294
|
p.mouseHandled = false;
|
|
292
295
|
|
|
@@ -342,28 +345,37 @@ class DropList {
|
|
|
342
345
|
|
|
343
346
|
const classList = itemEl.classList;
|
|
344
347
|
|
|
345
|
-
if (
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
+
if (item) {
|
|
349
|
+
if (p.multi) {
|
|
350
|
+
if (item._nocheck) {
|
|
351
|
+
classList.add(`${p.baseClassName}__item_multi_nocheck`);
|
|
352
|
+
} else {
|
|
353
|
+
classList.add(`${p.baseClassName}__item_multi`);
|
|
354
|
+
|
|
355
|
+
if (item._checked) {
|
|
356
|
+
classList.add(`${p.baseClassName}__item_checked`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
348
359
|
} else {
|
|
349
|
-
classList.add(`${p.baseClassName}
|
|
360
|
+
classList.add(`${p.baseClassName}__item_single`);
|
|
350
361
|
|
|
351
|
-
if (item.
|
|
352
|
-
classList.add(`${p.baseClassName}
|
|
362
|
+
if (p.singleSelectedValue !== undefined && item.value === p.singleSelectedValue) {
|
|
363
|
+
classList.add(`${p.baseClassName}__item_selected`);
|
|
364
|
+
p.singleSelectedItemEl = itemEl;
|
|
365
|
+
} else if (p.singleSelectedItemEl === itemEl) {
|
|
366
|
+
p.singleSelectedItemEl = null;
|
|
353
367
|
}
|
|
354
368
|
}
|
|
355
|
-
} else {
|
|
356
|
-
classList.add(`${p.baseClassName}__item_single`);
|
|
357
|
-
}
|
|
358
369
|
|
|
359
|
-
|
|
360
|
-
|
|
370
|
+
if (item._group)
|
|
371
|
+
classList.add(`${p.baseClassName}__item_group`);
|
|
361
372
|
|
|
362
|
-
|
|
363
|
-
|
|
373
|
+
if (item._child)
|
|
374
|
+
classList.add(`${p.baseClassName}__item_child`);
|
|
364
375
|
|
|
365
|
-
|
|
366
|
-
|
|
376
|
+
if (item._nointeraction)
|
|
377
|
+
classList.add(`${p.baseClassName}__item_nointeraction`);
|
|
378
|
+
}
|
|
367
379
|
|
|
368
380
|
if (p.focusItemIndex === index) {
|
|
369
381
|
p.focusItemEl = itemEl;
|
|
@@ -445,7 +457,7 @@ class DropList {
|
|
|
445
457
|
}
|
|
446
458
|
|
|
447
459
|
get el() {
|
|
448
|
-
return this._p
|
|
460
|
+
return this._p?.el ?? null;
|
|
449
461
|
}
|
|
450
462
|
|
|
451
463
|
/**
|
|
@@ -697,12 +709,17 @@ class DropList {
|
|
|
697
709
|
return false;
|
|
698
710
|
}
|
|
699
711
|
|
|
712
|
+
if (item._subitems?.length) {
|
|
713
|
+
this._showSublist(item, p.focusItemEl);
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
|
|
700
717
|
if (p.multi) {
|
|
701
718
|
if (this.hasFocusedItem()) {
|
|
702
719
|
this.toggleFocusedItem();
|
|
703
720
|
}
|
|
704
721
|
} else {
|
|
705
|
-
this._setSingleSelectedItemEl(p.focusItemEl);
|
|
722
|
+
this._setSingleSelectedItemEl(p.focusItemEl, item ? item.value : undefined);
|
|
706
723
|
|
|
707
724
|
this._trigger('select', {
|
|
708
725
|
value: item ? item.value : undefined,
|
|
@@ -1537,23 +1554,23 @@ class DropList {
|
|
|
1537
1554
|
let verticalBorderWidth = (parseFloat(elComputedStyle.borderTopWidth) || 0) +
|
|
1538
1555
|
(parseFloat(elComputedStyle.borderBottomWidth) || 0);
|
|
1539
1556
|
|
|
1540
|
-
let headerHeight = 0;
|
|
1541
|
-
if (p.headerEl) {
|
|
1542
|
-
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
let footerHeight = 0;
|
|
1546
|
-
if (p.footerEl) {
|
|
1547
|
-
footerHeight = getElementHeight(p.footerEl, true, true);
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
if (p.virtualListHelper.isVirtual()) {
|
|
1551
|
-
maxViewHeight =
|
|
1552
|
-
p.virtualListHelper.estimateFullHeight() +
|
|
1553
|
-
verticalPadding +
|
|
1554
|
-
verticalBorderWidth +
|
|
1555
|
-
headerHeight +
|
|
1556
|
-
footerHeight;
|
|
1557
|
+
let headerHeight = 0;
|
|
1558
|
+
if (p.headerEl) {
|
|
1559
|
+
headerHeight = getElementHeight(p.headerEl, true, true);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
let footerHeight = 0;
|
|
1563
|
+
if (p.footerEl) {
|
|
1564
|
+
footerHeight = getElementHeight(p.footerEl, true, true);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
if (p.virtualListHelper.isVirtual()) {
|
|
1568
|
+
maxViewHeight =
|
|
1569
|
+
p.virtualListHelper.estimateFullHeight() +
|
|
1570
|
+
verticalPadding +
|
|
1571
|
+
verticalBorderWidth +
|
|
1572
|
+
headerHeight +
|
|
1573
|
+
footerHeight;
|
|
1557
1574
|
} else {
|
|
1558
1575
|
// Another method to calculate height is measuring the whole thing at once.
|
|
1559
1576
|
// This causes relayout of course.
|
|
@@ -1694,12 +1711,12 @@ class DropList {
|
|
|
1694
1711
|
viewCss.left += 'px';
|
|
1695
1712
|
viewCss.top += 'px';
|
|
1696
1713
|
setCssProps(el, viewCss);
|
|
1697
|
-
setElementHeight(el, viewSize.height, true, true);
|
|
1698
|
-
|
|
1699
|
-
if (menuEl !== el) {
|
|
1700
|
-
let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
|
|
1701
|
-
setElementHeight(menuEl, menuHeight, true, true);
|
|
1702
|
-
}
|
|
1714
|
+
setElementHeight(el, viewSize.height, true, true);
|
|
1715
|
+
|
|
1716
|
+
if (menuEl !== el) {
|
|
1717
|
+
let menuHeight = viewSize.height - headerHeight - footerHeight - verticalBorderWidth - verticalPadding;
|
|
1718
|
+
setElementHeight(menuEl, menuHeight, true, true);
|
|
1719
|
+
}
|
|
1703
1720
|
|
|
1704
1721
|
// Update the scroll position for virtual lists
|
|
1705
1722
|
p.virtualListHelper.render();
|
|
@@ -1865,7 +1882,7 @@ class DropList {
|
|
|
1865
1882
|
if (!p.onDocumentMouseDown) {
|
|
1866
1883
|
// Detect mouse tap outside of the droplist, to blur the focused item
|
|
1867
1884
|
p.sink.add(document, 'mousedown', p.onDocumentMouseDown = (event) => {
|
|
1868
|
-
if (!
|
|
1885
|
+
if (!this.elContains(event.target, true))
|
|
1869
1886
|
this._delayBlurItemOnBlur();
|
|
1870
1887
|
});
|
|
1871
1888
|
}
|
|
@@ -2029,46 +2046,46 @@ class DropList {
|
|
|
2029
2046
|
* Get a reference to the header element in order to add custom content.
|
|
2030
2047
|
* @returns {Element}
|
|
2031
2048
|
*/
|
|
2032
|
-
getHeaderElement() {
|
|
2033
|
-
return this._p.headerEl;
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
/**
|
|
2037
|
-
* Change visibility of the footer element
|
|
2038
|
-
* You should probably call `relayout()` after this.
|
|
2039
|
-
* @param {boolean} visible
|
|
2040
|
-
*/
|
|
2041
|
-
setFooterVisible(visible) {
|
|
2042
|
-
let isVisible = this.isFooterVisible();
|
|
2043
|
-
if (isVisible === !!visible)
|
|
2044
|
-
return;
|
|
2045
|
-
|
|
2046
|
-
if (visible) {
|
|
2047
|
-
this._p.el.appendChild(this._p.footerEl);
|
|
2048
|
-
} else {
|
|
2049
|
-
this._p.footerEl.remove();
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
|
|
2053
|
-
/**
|
|
2054
|
-
* Is the footer element visible?
|
|
2055
|
-
* @returns {boolean}
|
|
2056
|
-
*/
|
|
2057
|
-
isFooterVisible() {
|
|
2058
|
-
return !!this._p.footerEl.parentNode;
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
/**
|
|
2062
|
-
* Get a reference to the footer element in order to add custom content.
|
|
2063
|
-
* @returns {Element}
|
|
2064
|
-
*/
|
|
2065
|
-
getFooterElement() {
|
|
2066
|
-
return this._p.footerEl;
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
/**
|
|
2070
|
-
* Set inline search visibility
|
|
2071
|
-
* You should probably call `relayout()` after this.
|
|
2049
|
+
getHeaderElement() {
|
|
2050
|
+
return this._p.headerEl;
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* Change visibility of the footer element
|
|
2055
|
+
* You should probably call `relayout()` after this.
|
|
2056
|
+
* @param {boolean} visible
|
|
2057
|
+
*/
|
|
2058
|
+
setFooterVisible(visible) {
|
|
2059
|
+
let isVisible = this.isFooterVisible();
|
|
2060
|
+
if (isVisible === !!visible)
|
|
2061
|
+
return;
|
|
2062
|
+
|
|
2063
|
+
if (visible) {
|
|
2064
|
+
this._p.el.appendChild(this._p.footerEl);
|
|
2065
|
+
} else {
|
|
2066
|
+
this._p.footerEl.remove();
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
/**
|
|
2071
|
+
* Is the footer element visible?
|
|
2072
|
+
* @returns {boolean}
|
|
2073
|
+
*/
|
|
2074
|
+
isFooterVisible() {
|
|
2075
|
+
return !!this._p.footerEl.parentNode;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
/**
|
|
2079
|
+
* Get a reference to the footer element in order to add custom content.
|
|
2080
|
+
* @returns {Element}
|
|
2081
|
+
*/
|
|
2082
|
+
getFooterElement() {
|
|
2083
|
+
return this._p.footerEl;
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* Set inline search visibility
|
|
2088
|
+
* You should probably call `relayout()` after this.
|
|
2072
2089
|
* @param {boolean} searchable
|
|
2073
2090
|
*/
|
|
2074
2091
|
setSearchable(searchable) {
|
|
@@ -2163,6 +2180,8 @@ class DropList {
|
|
|
2163
2180
|
if (!item._subitems?.length) return;
|
|
2164
2181
|
|
|
2165
2182
|
const p = this._p;
|
|
2183
|
+
if (p.currentSubDropList?.item === item)
|
|
2184
|
+
return;
|
|
2166
2185
|
|
|
2167
2186
|
const droplist = new DropList({
|
|
2168
2187
|
baseClassName: p.baseClassName,
|
|
@@ -2180,6 +2199,7 @@ class DropList {
|
|
|
2180
2199
|
estimatedItemHeight: p.estimatedItemHeight,
|
|
2181
2200
|
estimateWidth: p.estimateWidth,
|
|
2182
2201
|
virtualMinItems: p.virtualMinItems,
|
|
2202
|
+
singleSelectedValue: p.singleSelectedValue,
|
|
2183
2203
|
labelProp: p.labelProp,
|
|
2184
2204
|
valueProp: p.valueProp,
|
|
2185
2205
|
renderItem: p.renderItem,
|
|
@@ -2204,6 +2224,12 @@ class DropList {
|
|
|
2204
2224
|
.on('subitems:select', event => {
|
|
2205
2225
|
this._trigger('subitems:select', event);
|
|
2206
2226
|
})
|
|
2227
|
+
.on('show_subitems', event => {
|
|
2228
|
+
this._trigger('show_subitems', event);
|
|
2229
|
+
})
|
|
2230
|
+
.on('hide_subitems', event => {
|
|
2231
|
+
this._trigger('hide_subitems', event);
|
|
2232
|
+
})
|
|
2207
2233
|
.on('blur', onBlur)
|
|
2208
2234
|
.on('subitems:blur', onBlur)
|
|
2209
2235
|
.on('_back_key_pressed', () => {
|
|
@@ -2259,6 +2285,7 @@ class DropList {
|
|
|
2259
2285
|
value: data.item.value,
|
|
2260
2286
|
item: data.item,
|
|
2261
2287
|
el: data.itemElement,
|
|
2288
|
+
droplist: data.droplist,
|
|
2262
2289
|
});
|
|
2263
2290
|
}
|
|
2264
2291
|
|
|
@@ -2308,16 +2335,19 @@ class DropList {
|
|
|
2308
2335
|
return this.setFocusedItemAtIndex(this.itemIndexByValue(value));
|
|
2309
2336
|
}
|
|
2310
2337
|
|
|
2311
|
-
setSingleSelectedItemAtIndex(itemIndex) {
|
|
2338
|
+
setSingleSelectedItemAtIndex(itemIndex, value) {
|
|
2312
2339
|
const p = this._p;
|
|
2313
2340
|
|
|
2314
2341
|
this.rushRefilter();
|
|
2315
2342
|
|
|
2316
2343
|
let itemEl = null;
|
|
2344
|
+
let item;
|
|
2317
2345
|
|
|
2318
2346
|
if (itemIndex > -1 && !p.items[itemIndex]._nointeraction) {
|
|
2347
|
+
item = p.items[itemIndex];
|
|
2348
|
+
value = item.value;
|
|
2349
|
+
|
|
2319
2350
|
if (p.filteredItems) {
|
|
2320
|
-
const item = p.items[itemIndex];
|
|
2321
2351
|
itemIndex = p.filteredItems.indexOf(item);
|
|
2322
2352
|
}
|
|
2323
2353
|
|
|
@@ -2326,7 +2356,7 @@ class DropList {
|
|
|
2326
2356
|
}
|
|
2327
2357
|
}
|
|
2328
2358
|
|
|
2329
|
-
this._setSingleSelectedItemEl(itemEl);
|
|
2359
|
+
this._setSingleSelectedItemEl(itemEl, value);
|
|
2330
2360
|
|
|
2331
2361
|
return this;
|
|
2332
2362
|
}
|
|
@@ -2344,7 +2374,7 @@ class DropList {
|
|
|
2344
2374
|
}
|
|
2345
2375
|
|
|
2346
2376
|
setSingleSelectedItemByValue(value) {
|
|
2347
|
-
return this.setSingleSelectedItemAtIndex(this.itemIndexByValue(value));
|
|
2377
|
+
return this.setSingleSelectedItemAtIndex(this.itemIndexByValue(value), value);
|
|
2348
2378
|
}
|
|
2349
2379
|
|
|
2350
2380
|
next(event) {
|
|
@@ -2487,16 +2517,18 @@ class DropList {
|
|
|
2487
2517
|
return itemIndex;
|
|
2488
2518
|
}
|
|
2489
2519
|
|
|
2490
|
-
_setSingleSelectedItemEl(itemEl) {
|
|
2520
|
+
_setSingleSelectedItemEl(itemEl, value) {
|
|
2491
2521
|
const p = this._p;
|
|
2492
2522
|
|
|
2493
2523
|
if (p.singleSelectedItemEl) {
|
|
2494
|
-
p.singleSelectedItemEl.classList.remove(`${p.baseClassName}
|
|
2524
|
+
p.singleSelectedItemEl.classList.remove(`${p.baseClassName}__item_selected`);
|
|
2495
2525
|
p.singleSelectedItemEl = null;
|
|
2496
2526
|
}
|
|
2497
2527
|
|
|
2498
|
-
|
|
2499
|
-
|
|
2528
|
+
p.singleSelectedValue = value;
|
|
2529
|
+
|
|
2530
|
+
if (itemEl && value !== undefined) {
|
|
2531
|
+
itemEl.classList.add(`${p.baseClassName}__item_selected`);
|
|
2500
2532
|
p.singleSelectedItemEl = itemEl;
|
|
2501
2533
|
}
|
|
2502
2534
|
|
|
@@ -2923,7 +2955,7 @@ class DropList {
|
|
|
2923
2955
|
_move(direction, event) {
|
|
2924
2956
|
const p = this._p;
|
|
2925
2957
|
|
|
2926
|
-
let next, nextIndex, directionUp
|
|
2958
|
+
let next, nextIndex, directionUp;
|
|
2927
2959
|
const items = p.filteredItems ?? p.items;
|
|
2928
2960
|
|
|
2929
2961
|
if (direction === 'first') {
|
package/lib/SelectBox.js
CHANGED
|
@@ -502,7 +502,7 @@ class SelectBox {
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
get el() {
|
|
505
|
-
return this._p
|
|
505
|
+
return this._p?.el ?? null;
|
|
506
506
|
}
|
|
507
507
|
|
|
508
508
|
get droplistInstance() {
|
|
@@ -1969,6 +1969,12 @@ class SelectBox {
|
|
|
1969
1969
|
p.resortBySelectionNeeded = true;
|
|
1970
1970
|
}
|
|
1971
1971
|
|
|
1972
|
+
const preventDropListMouseDownBlur = (event) => {
|
|
1973
|
+
const li = closestUntil(event.target, 'li', event.currentTarget);
|
|
1974
|
+
if (!li) return;
|
|
1975
|
+
|
|
1976
|
+
event.preventDefault();
|
|
1977
|
+
};
|
|
1972
1978
|
const dropList = p.dropList = new DropList({
|
|
1973
1979
|
virtualMinItems: 10,
|
|
1974
1980
|
|
|
@@ -1976,6 +1982,7 @@ class SelectBox {
|
|
|
1976
1982
|
...p.listOptions,
|
|
1977
1983
|
|
|
1978
1984
|
multi: p.multi,
|
|
1985
|
+
singleSelectedValue: !p.multi ? this.getValue() : undefined,
|
|
1979
1986
|
capturesFocus: false,
|
|
1980
1987
|
|
|
1981
1988
|
labelProp: p.labelProp,
|
|
@@ -2176,6 +2183,14 @@ class SelectBox {
|
|
|
2176
2183
|
}
|
|
2177
2184
|
break;
|
|
2178
2185
|
|
|
2186
|
+
case 'show_subitems':
|
|
2187
|
+
p.sink.add(event.droplist.el, 'mousedown.subitems', preventDropListMouseDownBlur);
|
|
2188
|
+
break;
|
|
2189
|
+
|
|
2190
|
+
case 'hide_subitems':
|
|
2191
|
+
p.sink.remove(event.droplist.el, '.subitems');
|
|
2192
|
+
break;
|
|
2193
|
+
|
|
2179
2194
|
case 'blur':
|
|
2180
2195
|
this._handleOnBlur();
|
|
2181
2196
|
break;
|
|
@@ -2191,12 +2206,7 @@ class SelectBox {
|
|
|
2191
2206
|
},
|
|
2192
2207
|
});
|
|
2193
2208
|
|
|
2194
|
-
p.sink.add(dropList.el, 'mousedown',
|
|
2195
|
-
const li = closestUntil(event.target, 'li', event.currentTarget);
|
|
2196
|
-
if (!li) return;
|
|
2197
|
-
|
|
2198
|
-
event.preventDefault();
|
|
2199
|
-
});
|
|
2209
|
+
p.sink.add(dropList.el, 'mousedown', preventDropListMouseDownBlur);
|
|
2200
2210
|
|
|
2201
2211
|
this._registerDropdownEvents();
|
|
2202
2212
|
}
|
|
@@ -2556,11 +2566,12 @@ class SelectBox {
|
|
|
2556
2566
|
if (p.multi) {
|
|
2557
2567
|
p.dropList.setCheckedValues(p.selectedValues);
|
|
2558
2568
|
} else {
|
|
2559
|
-
const
|
|
2569
|
+
const singleValue = this.getValue();
|
|
2570
|
+
const singleItemIndex = p.dropList.itemIndexByValue(singleValue);
|
|
2560
2571
|
|
|
2561
2572
|
p.dropList
|
|
2562
2573
|
.setFocusedItemAtIndex(singleItemIndex)
|
|
2563
|
-
.
|
|
2574
|
+
.setSingleSelectedItemByValue(singleValue);
|
|
2564
2575
|
|
|
2565
2576
|
hasRefocusedItem = p.dropList.hasFocusedItem();
|
|
2566
2577
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielgindi/selectbox",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.55",
|
|
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",
|
|
@@ -32,26 +32,20 @@
|
|
|
32
32
|
"homepage": "https://github.com/danielgindi/selectbox#readme",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"@eslint/eslintrc": "^3.3.4",
|
|
39
|
-
"@eslint/js": "^9.39.3",
|
|
40
|
-
"@rollup/plugin-babel": "^6.1.0",
|
|
41
|
-
"@rollup/plugin-commonjs": "^29.0.0",
|
|
42
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
43
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
44
|
-
"core-js": "^3.48.0",
|
|
45
|
-
"eslint": "^9.39.3",
|
|
35
|
+
"@eslint/eslintrc": "^3.3.6",
|
|
36
|
+
"@eslint/js": "^10.0.1",
|
|
37
|
+
"eslint": "^10.7.0",
|
|
46
38
|
"eslint-formatter-codeframe": "^7.32.2",
|
|
47
|
-
"eslint-plugin-vue": "^9.
|
|
48
|
-
"
|
|
49
|
-
"globals": "^17.4.0",
|
|
39
|
+
"eslint-plugin-vue": "^10.9.2",
|
|
40
|
+
"globals": "^17.7.0",
|
|
50
41
|
"husky": "^9.1.7",
|
|
42
|
+
"magic-string": "^1.0.0",
|
|
51
43
|
"pinst": "^3.0.0",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"vite": "^8.1.
|
|
44
|
+
"sass": "^1.101.0",
|
|
45
|
+
"terser": "^5.49.0",
|
|
46
|
+
"vite": "^8.1.5",
|
|
47
|
+
"vue": "^3.5.40",
|
|
48
|
+
"vue-eslint-parser": "^10.4.1"
|
|
55
49
|
},
|
|
56
50
|
"dependencies": {
|
|
57
51
|
"@danielgindi/dom-utils": "^1.0.11",
|
package/scss/droplist.scss
CHANGED
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
max-width: 100%;
|
|
33
33
|
line-height: 1.3;
|
|
34
34
|
|
|
35
|
-
.droplist_header,
|
|
36
|
-
.droplist_footer {
|
|
37
|
-
position: relative;
|
|
38
|
-
padding: 0.5em;
|
|
39
|
-
box-sizing: inherit;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.droplist_header {
|
|
43
|
-
input[type=search] {
|
|
44
|
-
box-sizing: inherit;
|
|
45
|
-
width: 100%;
|
|
35
|
+
.droplist_header,
|
|
36
|
+
.droplist_footer {
|
|
37
|
+
position: relative;
|
|
38
|
+
padding: 0.5em;
|
|
39
|
+
box-sizing: inherit;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.droplist_header {
|
|
43
|
+
input[type=search] {
|
|
44
|
+
box-sizing: inherit;
|
|
45
|
+
width: 100%;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -96,10 +96,16 @@
|
|
|
96
96
|
overflow: hidden;
|
|
97
97
|
|
|
98
98
|
&.droplist__item_focus {
|
|
99
|
-
|
|
99
|
+
background-color: #c7c7c7;
|
|
100
|
+
}
|
|
101
|
+
&.droplist__item_selected {
|
|
100
102
|
background-color: #3e3f48;
|
|
101
103
|
color: #fff;
|
|
102
104
|
}
|
|
105
|
+
&.droplist__item_selected.droplist__item_focus {
|
|
106
|
+
background-color: #2e3038;
|
|
107
|
+
color: #fff;
|
|
108
|
+
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
li {
|