@danielgindi/selectbox 1.0.67 → 1.0.70
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/selectbox.css +1 -1
- package/css/selectbox.css.map +1 -1
- package/dist/lib.cjs.js +94 -25
- 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 +62 -7
- 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 +94 -25
- 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/SelectBox.js +61 -6
- package/package.json +1 -1
- package/scss/selectbox.scss +5 -1
- package/vue/SelectBox.vue +25 -17
package/lib/SelectBox.js
CHANGED
|
@@ -92,6 +92,7 @@ const inputBackbufferCssProps = [
|
|
|
92
92
|
* @property {boolean|'touch'} [blurOnSingleSelection='touch']
|
|
93
93
|
* @property {boolean} [multi=false] can multiple values be selected?
|
|
94
94
|
* @property {boolean} [showSelection=true] show selection? if false, the placeholder will take effect
|
|
95
|
+
* @property {boolean} [showPlaceholderInTooltip=false] show placeholder in title attribute
|
|
95
96
|
* @property {function(items: DropList.ItemBase[]):string} [multiPlaceholderFormatter] formatter for placeholder for multi items mode
|
|
96
97
|
* @property {boolean} [searchable=false] is it searchable?
|
|
97
98
|
* @property {string} [noResultsText='No matching results'] text for no results (empty for none)
|
|
@@ -135,6 +136,7 @@ const defaultOptions = {
|
|
|
135
136
|
blurOnSingleSelection: 'touch',
|
|
136
137
|
multi: false,
|
|
137
138
|
showSelection: true,
|
|
139
|
+
showPlaceholderInTooltip: false,
|
|
138
140
|
multiPlaceholderFormatter: null,
|
|
139
141
|
searchable: true,
|
|
140
142
|
noResultsText: 'No matching results',
|
|
@@ -225,6 +227,7 @@ class SelectBox {
|
|
|
225
227
|
blurOnSingleSelection: o.blurOnSingleSelection,
|
|
226
228
|
multi: o.multi,
|
|
227
229
|
showSelection: o.showSelection,
|
|
230
|
+
showPlaceholderInTooltip: o.showPlaceholderInTooltip,
|
|
228
231
|
multiPlaceholderFormatter: o.multiPlaceholderFormatter,
|
|
229
232
|
searchable: o.searchable,
|
|
230
233
|
noResultsText: o.noResultsText,
|
|
@@ -360,6 +363,7 @@ class SelectBox {
|
|
|
360
363
|
}
|
|
361
364
|
|
|
362
365
|
this.setItems(o.items);
|
|
366
|
+
delete o.items; // we do not need this in memory anymore
|
|
363
367
|
|
|
364
368
|
if (o.multi && Array.isArray(o.selectedValues)) {
|
|
365
369
|
this.setSelectedValues(o.selectedValues);
|
|
@@ -511,6 +515,8 @@ class SelectBox {
|
|
|
511
515
|
p.filteredItems = null;
|
|
512
516
|
p.itemsChanged = true;
|
|
513
517
|
|
|
518
|
+
this._updateItemByValueMap();
|
|
519
|
+
|
|
514
520
|
if (resetValues) {
|
|
515
521
|
this.setSelectedValues(this.getSelectedValues());
|
|
516
522
|
}
|
|
@@ -540,9 +546,9 @@ class SelectBox {
|
|
|
540
546
|
}
|
|
541
547
|
|
|
542
548
|
updateItemByValue(value, newItem) {
|
|
543
|
-
const p = this._p
|
|
549
|
+
const p = this._p;
|
|
544
550
|
|
|
545
|
-
let existingItem = p.
|
|
551
|
+
let existingItem = p.itemByValueMap.get(value);
|
|
546
552
|
if (existingItem)
|
|
547
553
|
Object.assign(existingItem, newItem);
|
|
548
554
|
|
|
@@ -823,7 +829,7 @@ class SelectBox {
|
|
|
823
829
|
if (p.showSelection === showSelection)
|
|
824
830
|
return this;
|
|
825
831
|
|
|
826
|
-
|
|
832
|
+
p.showSelection = showSelection;
|
|
827
833
|
this._scheduleSync('full');
|
|
828
834
|
return this;
|
|
829
835
|
}
|
|
@@ -835,6 +841,28 @@ class SelectBox {
|
|
|
835
841
|
return this._p.showSelection;
|
|
836
842
|
}
|
|
837
843
|
|
|
844
|
+
/**
|
|
845
|
+
* @param {boolean} showPlaceholderInTooltip
|
|
846
|
+
* @returns {SelectBox}
|
|
847
|
+
*/
|
|
848
|
+
setShowPlaceholderInTooltip(showPlaceholderInTooltip) {
|
|
849
|
+
const p = this._p;
|
|
850
|
+
showPlaceholderInTooltip = !!showPlaceholderInTooltip;
|
|
851
|
+
if (p.showPlaceholderInTooltip === showPlaceholderInTooltip)
|
|
852
|
+
return this;
|
|
853
|
+
|
|
854
|
+
p.showPlaceholderInTooltip = showPlaceholderInTooltip;
|
|
855
|
+
this._scheduleSync('full');
|
|
856
|
+
return this;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* @returns {boolean}
|
|
861
|
+
*/
|
|
862
|
+
isShowPlaceholderInTooltipEnabled() {
|
|
863
|
+
return this._p.showPlaceholderInTooltip;
|
|
864
|
+
}
|
|
865
|
+
|
|
838
866
|
/**
|
|
839
867
|
* @param {function(items: DropList.ItemBase[]):string} formatter
|
|
840
868
|
* @returns {SelectBox}
|
|
@@ -845,7 +873,7 @@ class SelectBox {
|
|
|
845
873
|
if (p.multiPlaceholderFormatter === formatter)
|
|
846
874
|
return this;
|
|
847
875
|
|
|
848
|
-
|
|
876
|
+
p.multiPlaceholderFormatter = formatter;
|
|
849
877
|
this._scheduleSync('full');
|
|
850
878
|
return this;
|
|
851
879
|
}
|
|
@@ -859,7 +887,7 @@ class SelectBox {
|
|
|
859
887
|
if (p.blurOnSingleSelection === value)
|
|
860
888
|
return this;
|
|
861
889
|
|
|
862
|
-
|
|
890
|
+
p.blurOnSingleSelection = value;
|
|
863
891
|
return this;
|
|
864
892
|
}
|
|
865
893
|
|
|
@@ -1064,11 +1092,17 @@ class SelectBox {
|
|
|
1064
1092
|
*/
|
|
1065
1093
|
setValueProp(prop) {
|
|
1066
1094
|
const p = this._p;
|
|
1095
|
+
|
|
1096
|
+
if (p.valueProp === prop)
|
|
1097
|
+
return this;
|
|
1098
|
+
|
|
1067
1099
|
p.valueProp = prop;
|
|
1068
1100
|
|
|
1069
1101
|
if (p.dropList)
|
|
1070
1102
|
p.dropList.setValueProp(prop);
|
|
1071
1103
|
|
|
1104
|
+
this._updateItemByValueMap();
|
|
1105
|
+
|
|
1072
1106
|
return this;
|
|
1073
1107
|
}
|
|
1074
1108
|
|
|
@@ -1220,7 +1254,7 @@ class SelectBox {
|
|
|
1220
1254
|
|
|
1221
1255
|
selectedValues.push(value);
|
|
1222
1256
|
|
|
1223
|
-
let item = p.
|
|
1257
|
+
let item = p.itemByValueMap.get(value);
|
|
1224
1258
|
if (item !== undefined) {
|
|
1225
1259
|
selectedItems.push(item);
|
|
1226
1260
|
} else {
|
|
@@ -1441,6 +1475,21 @@ class SelectBox {
|
|
|
1441
1475
|
return this;
|
|
1442
1476
|
}
|
|
1443
1477
|
|
|
1478
|
+
/**
|
|
1479
|
+
* Prepare the mapping between values and items.
|
|
1480
|
+
* This reduces search time greatly (i.e when checking items), especially when Vue proxies are in place.
|
|
1481
|
+
* @private
|
|
1482
|
+
*/
|
|
1483
|
+
_updateItemByValueMap() {
|
|
1484
|
+
const p = this._p;
|
|
1485
|
+
|
|
1486
|
+
const itemByValueMap = p.itemByValueMap = new Map();
|
|
1487
|
+
const valueProp = p.valueProp;
|
|
1488
|
+
for (let item of p.items) {
|
|
1489
|
+
itemByValueMap.set(item[valueProp], item);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1444
1493
|
/** @private */
|
|
1445
1494
|
_renderBase() {
|
|
1446
1495
|
const p = this._p;
|
|
@@ -2599,6 +2648,12 @@ class SelectBox {
|
|
|
2599
2648
|
|
|
2600
2649
|
// Set input placeholder
|
|
2601
2650
|
p.input.setAttribute('placeholder', placeholder);
|
|
2651
|
+
|
|
2652
|
+
if (p.showPlaceholderInTooltip) {
|
|
2653
|
+
p.input.setAttribute('title', placeholder);
|
|
2654
|
+
} else {
|
|
2655
|
+
p.input.removeAttribute('title');
|
|
2656
|
+
}
|
|
2602
2657
|
}
|
|
2603
2658
|
|
|
2604
2659
|
/** @private */
|
package/package.json
CHANGED
package/scss/selectbox.scss
CHANGED
|
@@ -234,7 +234,7 @@ $spinner-transition-duration: .15s;
|
|
|
234
234
|
font-size: 13px;
|
|
235
235
|
line-height: 1.4;
|
|
236
236
|
margin: 0;
|
|
237
|
-
padding: 0
|
|
237
|
+
padding: 0;
|
|
238
238
|
border: 0;
|
|
239
239
|
background: none;
|
|
240
240
|
|
|
@@ -261,6 +261,10 @@ $spinner-transition-duration: .15s;
|
|
|
261
261
|
left: 14px;
|
|
262
262
|
}
|
|
263
263
|
}
|
|
264
|
+
|
|
265
|
+
.selectbox[aria-disabled=true] > & {
|
|
266
|
+
display: none;
|
|
267
|
+
}
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
.selectbox__spinner {
|
package/vue/SelectBox.vue
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* 'search:focus': input box has gained focus
|
|
25
25
|
* 'search:blur': input box has lost focus
|
|
26
26
|
* 'input:resize': input box resized
|
|
27
|
-
* 'input': (on select, clear, addsel, removesel)
|
|
27
|
+
* 'input': (on select, clear, addsel, removesel) - fired after any of the above events.
|
|
28
28
|
* 'itemschanged': `{term, mutated, count}` = the current set of items has changed
|
|
29
29
|
*
|
|
30
30
|
* Slots:
|
|
@@ -77,6 +77,10 @@
|
|
|
77
77
|
type: Boolean,
|
|
78
78
|
default: true,
|
|
79
79
|
},
|
|
80
|
+
showPlaceholderInTooltip: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
default: true,
|
|
83
|
+
},
|
|
80
84
|
multiPlaceholderFormatter: {
|
|
81
85
|
type: Function,
|
|
82
86
|
required: false,
|
|
@@ -443,6 +447,11 @@
|
|
|
443
447
|
this._box.setShowSelection(value);
|
|
444
448
|
},
|
|
445
449
|
|
|
450
|
+
showPlaceholderInTooltip(value) {
|
|
451
|
+
if (this._box)
|
|
452
|
+
this._box.setShowPlaceholderInTooltip(value);
|
|
453
|
+
},
|
|
454
|
+
|
|
446
455
|
multiPlaceholderFormatter(formatter) {
|
|
447
456
|
if (this._box)
|
|
448
457
|
this._box.setMultiPlaceholderFormatter(formatter);
|
|
@@ -632,27 +641,11 @@
|
|
|
632
641
|
|
|
633
642
|
methods: {
|
|
634
643
|
_handleBoxEvents(event, data) {
|
|
635
|
-
if (event === 'select' ||
|
|
636
|
-
event === 'clear' ||
|
|
637
|
-
event === 'addsel' ||
|
|
638
|
-
event === 'removesel') {
|
|
639
|
-
let value = event === 'select' ? data.value : this._box.getValue();
|
|
640
|
-
if (value === undefined && event !== 'select' && this.useNullForEmptyValue)
|
|
641
|
-
value = null;
|
|
642
|
-
this.$emit('input', value);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
if (event === 'search') {
|
|
646
|
-
this.$emit(event, data.value);
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
644
|
switch (event) {
|
|
651
645
|
case 'clear:before':
|
|
652
646
|
case 'clear':
|
|
653
647
|
case 'open':
|
|
654
648
|
case 'close':
|
|
655
|
-
case 'search':
|
|
656
649
|
case 'search:focus':
|
|
657
650
|
case 'search:blur':
|
|
658
651
|
case 'addsel:before':
|
|
@@ -665,6 +658,20 @@
|
|
|
665
658
|
case 'itemschanged':
|
|
666
659
|
this.$emit(event, ...(data === undefined ? [] : [data]));
|
|
667
660
|
break;
|
|
661
|
+
|
|
662
|
+
case 'search':
|
|
663
|
+
this.$emit(event, data.value);
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
if (event === 'select' ||
|
|
668
|
+
event === 'clear' ||
|
|
669
|
+
event === 'addsel' ||
|
|
670
|
+
event === 'removesel') {
|
|
671
|
+
let value = event === 'select' ? data.value : this._box.getValue();
|
|
672
|
+
if (value === undefined && event !== 'select' && this.useNullForEmptyValue)
|
|
673
|
+
value = null;
|
|
674
|
+
this.$emit('input', value);
|
|
668
675
|
}
|
|
669
676
|
},
|
|
670
677
|
|
|
@@ -689,6 +696,7 @@
|
|
|
689
696
|
sortItemComparator: this.sortItemComparator,
|
|
690
697
|
splitListCheckedGroups: this.splitListCheckedGroups,
|
|
691
698
|
showSelection: this.showSelection,
|
|
699
|
+
showPlaceholderInTooltip: this.showPlaceholderInTooltip,
|
|
692
700
|
multiPlaceholderFormatter: this.multiPlaceholderFormatter,
|
|
693
701
|
blurOnSingleSelection: this.blurOnSingleSelection,
|
|
694
702
|
multi: this.multi,
|