@danielgindi/selectbox 2.0.27 → 2.0.29
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 +45 -13
- 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 +45 -13
- 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 +45 -13
- 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 +44 -12
- package/package.json +1 -1
- package/scss/selectbox.scss +9 -1
- package/vue/SelectBox.vue +10 -0
package/lib/SelectBox.js
CHANGED
|
@@ -78,6 +78,7 @@ const inputBackbufferCssProps = [
|
|
|
78
78
|
* @property {string|string[]} [additionalClasses]
|
|
79
79
|
* @property {'ltr'|'rtl'|'auto'} [direction='auto']
|
|
80
80
|
* @property {boolean} [disabled=false] Should start as disabled?
|
|
81
|
+
* @property {boolean} [readOnly=false] Should start as readOnly?
|
|
81
82
|
* @property {boolean} [clearable=true] Has clear button?
|
|
82
83
|
* @property {boolean} [hasOpenIndicator=true] has open/close indicator?
|
|
83
84
|
* @property {string} [placeholder=''] Placeholder text
|
|
@@ -123,6 +124,7 @@ export const DefaultOptions = {
|
|
|
123
124
|
el: null,
|
|
124
125
|
baseClassName: 'selectbox',
|
|
125
126
|
disabled: false,
|
|
127
|
+
readOnly: false,
|
|
126
128
|
clearable: true,
|
|
127
129
|
hasOpenIndicator: true,
|
|
128
130
|
placeholder: '',
|
|
@@ -221,6 +223,7 @@ class SelectBox {
|
|
|
221
223
|
listOptions: o.listOptions,
|
|
222
224
|
|
|
223
225
|
disabled: !!o.disabled,
|
|
226
|
+
readOnly: !!o.readOnly,
|
|
224
227
|
clearable: !!o.clearable,
|
|
225
228
|
hasOpenIndicator: !!o.hasOpenIndicator,
|
|
226
229
|
placeholder: o.placeholder,
|
|
@@ -303,6 +306,7 @@ class SelectBox {
|
|
|
303
306
|
p.multiItemEls = [];
|
|
304
307
|
|
|
305
308
|
this.enable(!p.disabled);
|
|
309
|
+
this.setReadOnly(!p.readOnly);
|
|
306
310
|
|
|
307
311
|
this._setupDropdownMenu();
|
|
308
312
|
|
|
@@ -529,6 +533,32 @@ class SelectBox {
|
|
|
529
533
|
return this._p.disabled;
|
|
530
534
|
}
|
|
531
535
|
|
|
536
|
+
/**
|
|
537
|
+
* Sets read only mode
|
|
538
|
+
* @param {boolean=true} readOnly Should the control be read only?
|
|
539
|
+
* @returns {SelectBox}
|
|
540
|
+
*/
|
|
541
|
+
setReadOnly(readOnly) {
|
|
542
|
+
const p = this._p;
|
|
543
|
+
|
|
544
|
+
if (readOnly === undefined) {
|
|
545
|
+
readOnly = true;
|
|
546
|
+
}
|
|
547
|
+
p.readOnly = !readOnly;
|
|
548
|
+
p.el.setAttribute('aria-readOnly', p.readOnly.toString());
|
|
549
|
+
p.input.readOnly = !(p.searchable || p.multi) || !!p.readOnly;
|
|
550
|
+
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Is the control enabled?
|
|
556
|
+
* @returns {boolean}
|
|
557
|
+
*/
|
|
558
|
+
isReadOnly() {
|
|
559
|
+
return !this._p.readOnly;
|
|
560
|
+
}
|
|
561
|
+
|
|
532
562
|
/**
|
|
533
563
|
* @param {string|string[]} classes
|
|
534
564
|
* @returns {SelectBox}
|
|
@@ -1656,7 +1686,7 @@ class SelectBox {
|
|
|
1656
1686
|
spellcheck: 'false',
|
|
1657
1687
|
role: 'textbox',
|
|
1658
1688
|
'aria-autocomplete': 'list',
|
|
1659
|
-
readOnly: !(p.searchable || p.multi),
|
|
1689
|
+
readOnly: !(p.searchable || p.multi) || !!p.readOnly,
|
|
1660
1690
|
}),
|
|
1661
1691
|
);
|
|
1662
1692
|
}
|
|
@@ -1690,7 +1720,7 @@ class SelectBox {
|
|
|
1690
1720
|
if (!closestUntil(evt.target, `.${p.baseClassName}__item_remove`, evt.currentTarget))
|
|
1691
1721
|
return;
|
|
1692
1722
|
|
|
1693
|
-
if (p.disabled) return;
|
|
1723
|
+
if (p.disabled || p.readOnly) return;
|
|
1694
1724
|
|
|
1695
1725
|
this._removeMultiItemFromEvent(
|
|
1696
1726
|
/**@type Element*/
|
|
@@ -1743,6 +1773,7 @@ class SelectBox {
|
|
|
1743
1773
|
if (p.hasOpenIndicator) {
|
|
1744
1774
|
p.openIndicator = createElement('span', { class: `${p.baseClassName}__open_indicator` });
|
|
1745
1775
|
p.el.appendChild(p.openIndicator);
|
|
1776
|
+
p.el.classList.add(`${p.baseClassName}__has_open_indicator`);
|
|
1746
1777
|
} else {
|
|
1747
1778
|
remove(p.openIndicator);
|
|
1748
1779
|
delete p.openIndicator;
|
|
@@ -2057,7 +2088,7 @@ class SelectBox {
|
|
|
2057
2088
|
|
|
2058
2089
|
setTimeout(() => {
|
|
2059
2090
|
if (this[DestroyedSymbol]) return; // destroyed by event handler
|
|
2060
|
-
if (p.disabled) return;
|
|
2091
|
+
if (p.disabled || p.readOnly) return;
|
|
2061
2092
|
|
|
2062
2093
|
this._trigger('search:blur');
|
|
2063
2094
|
|
|
@@ -2200,7 +2231,8 @@ class SelectBox {
|
|
|
2200
2231
|
p.lastKeyAllowsNonTypeKeys &&
|
|
2201
2232
|
!p.multi &&
|
|
2202
2233
|
!dropList.hasFocusedItem() &&
|
|
2203
|
-
!p.disabled
|
|
2234
|
+
!p.disabled &&
|
|
2235
|
+
!p.readOnly
|
|
2204
2236
|
)) {
|
|
2205
2237
|
this.toggleList();
|
|
2206
2238
|
evt.preventDefault();
|
|
@@ -2212,20 +2244,20 @@ class SelectBox {
|
|
|
2212
2244
|
if (p.input) {
|
|
2213
2245
|
p.sink
|
|
2214
2246
|
.add(p.input, 'input.dropdown', () => {
|
|
2215
|
-
if (p.disabled) return;
|
|
2247
|
+
if (p.disabled || p.readOnly) return;
|
|
2216
2248
|
|
|
2217
2249
|
p.filterTerm = p.input.value.trim();
|
|
2218
2250
|
p.dropList?.setSearchTerm(p.filterTerm, true);
|
|
2219
2251
|
})
|
|
2220
2252
|
.add(p.input, 'click.dropdown', () => {
|
|
2221
|
-
if (p.disabled) return;
|
|
2253
|
+
if (p.disabled || p.readOnly) return;
|
|
2222
2254
|
|
|
2223
2255
|
if (!p.multi && p.searchable) {
|
|
2224
2256
|
this.openList();
|
|
2225
2257
|
}
|
|
2226
2258
|
})
|
|
2227
2259
|
.add(p.input, 'focus.dropdown', () => {
|
|
2228
|
-
if (p.disabled) return;
|
|
2260
|
+
if (p.disabled || p.readOnly) return;
|
|
2229
2261
|
|
|
2230
2262
|
this._trigger('search:focus');
|
|
2231
2263
|
|
|
@@ -2242,7 +2274,7 @@ class SelectBox {
|
|
|
2242
2274
|
|
|
2243
2275
|
p.sink
|
|
2244
2276
|
.add(p.el, 'mousedown.dropdown', () => {
|
|
2245
|
-
if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled) {
|
|
2277
|
+
if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled && !p.readOnly) {
|
|
2246
2278
|
this.toggleList();
|
|
2247
2279
|
}
|
|
2248
2280
|
avoidToggleFromClick = false;
|
|
@@ -2251,7 +2283,7 @@ class SelectBox {
|
|
|
2251
2283
|
if (currentTouchId) return;
|
|
2252
2284
|
currentTouchId = evt.changedTouches[0].identifier;
|
|
2253
2285
|
|
|
2254
|
-
if (this.isDisabled())
|
|
2286
|
+
if (this.isDisabled() || this.isReadOnly())
|
|
2255
2287
|
return;
|
|
2256
2288
|
|
|
2257
2289
|
if (closestUntil(evt.target, `.${p.baseClassName}__item,.${p.baseClassName}__clear`, p.el))
|
|
@@ -2691,7 +2723,7 @@ class SelectBox {
|
|
|
2691
2723
|
p.el.classList.add(`${p.baseClassName}__has_clear`);
|
|
2692
2724
|
|
|
2693
2725
|
p.sink.add(p.clearButton, 'click', () => {
|
|
2694
|
-
if (this.isDisabled()) return;
|
|
2726
|
+
if (this.isDisabled() || this.isReadOnly()) return;
|
|
2695
2727
|
this.clear();
|
|
2696
2728
|
});
|
|
2697
2729
|
}
|
|
@@ -2845,7 +2877,7 @@ class SelectBox {
|
|
|
2845
2877
|
if (p.input) p.input.readOnly = false;
|
|
2846
2878
|
p.el.classList.add(`${p.baseClassName}__searchable`);
|
|
2847
2879
|
} else {
|
|
2848
|
-
if (p.input) p.input.readOnly =
|
|
2880
|
+
if (p.input) p.input.readOnly = p.readOnly;
|
|
2849
2881
|
p.el.classList.remove(`${p.baseClassName}__searchable`);
|
|
2850
2882
|
}
|
|
2851
2883
|
|
|
@@ -3227,7 +3259,7 @@ class SelectBox {
|
|
|
3227
3259
|
_handleMultiKeydown(event) {
|
|
3228
3260
|
const p = this._p;
|
|
3229
3261
|
|
|
3230
|
-
if (p.disabled) return;
|
|
3262
|
+
if (p.disabled || p.readOnly) return;
|
|
3231
3263
|
|
|
3232
3264
|
const isRtl = getComputedStyle(p.el).direction === 'rtl';
|
|
3233
3265
|
|
package/package.json
CHANGED
package/scss/selectbox.scss
CHANGED
|
@@ -70,6 +70,14 @@ $spinner-transition-duration: .15s;
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
&[aria-readonly=true] {
|
|
74
|
+
cursor: default;
|
|
75
|
+
|
|
76
|
+
* {
|
|
77
|
+
cursor: default;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
&.has_droplist_above {
|
|
74
82
|
border-top-left-radius: 0;
|
|
75
83
|
border-top-right-radius: 0;
|
|
@@ -272,7 +280,7 @@ $spinner-transition-duration: .15s;
|
|
|
272
280
|
left: calc(var(--selectbox-clear-spacing) + var(--selectbox-open-indicator-width));
|
|
273
281
|
}
|
|
274
282
|
|
|
275
|
-
.selectbox[aria-disabled=true] > & {
|
|
283
|
+
.selectbox[aria-disabled=true] > &, .selectbox[aria-readonly=true] > & {
|
|
276
284
|
display: none;
|
|
277
285
|
}
|
|
278
286
|
}
|
package/vue/SelectBox.vue
CHANGED
|
@@ -40,6 +40,10 @@ export const PropTypes = {
|
|
|
40
40
|
type: Boolean,
|
|
41
41
|
default: false,
|
|
42
42
|
},
|
|
43
|
+
readOnly: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false,
|
|
46
|
+
},
|
|
43
47
|
clearable: {
|
|
44
48
|
type: Boolean,
|
|
45
49
|
default: true,
|
|
@@ -472,6 +476,11 @@ export default {
|
|
|
472
476
|
this.nonReactive.instance.disable(value);
|
|
473
477
|
},
|
|
474
478
|
|
|
479
|
+
readOnly(value) {
|
|
480
|
+
if (this.nonReactive.instance)
|
|
481
|
+
this.nonReactive.instance.setReadOnly(value ?? false);
|
|
482
|
+
},
|
|
483
|
+
|
|
475
484
|
clearable(value) {
|
|
476
485
|
if (this.nonReactive.instance)
|
|
477
486
|
this.nonReactive.instance.setClearable(value);
|
|
@@ -801,6 +810,7 @@ export default {
|
|
|
801
810
|
baseClass: this.baseClass,
|
|
802
811
|
direction: this.direction,
|
|
803
812
|
disabled: this.disabled,
|
|
813
|
+
readOnly: this.readOnly,
|
|
804
814
|
clearable: this.clearable,
|
|
805
815
|
hasOpenIndicator: this.hasOpenIndicator,
|
|
806
816
|
placeholder: this.placeholder,
|