@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/dist/lib.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.27
2
+ * @danielgindi/selectbox 2.0.29
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -9875,6 +9875,7 @@
9875
9875
  * @property {string|string[]} [additionalClasses]
9876
9876
  * @property {'ltr'|'rtl'|'auto'} [direction='auto']
9877
9877
  * @property {boolean} [disabled=false] Should start as disabled?
9878
+ * @property {boolean} [readOnly=false] Should start as readOnly?
9878
9879
  * @property {boolean} [clearable=true] Has clear button?
9879
9880
  * @property {boolean} [hasOpenIndicator=true] has open/close indicator?
9880
9881
  * @property {string} [placeholder=''] Placeholder text
@@ -9920,6 +9921,7 @@
9920
9921
  el: null,
9921
9922
  baseClassName: 'selectbox',
9922
9923
  disabled: false,
9924
+ readOnly: false,
9923
9925
  clearable: true,
9924
9926
  hasOpenIndicator: true,
9925
9927
  placeholder: '',
@@ -10018,6 +10020,7 @@
10018
10020
  listOptions: o.listOptions,
10019
10021
 
10020
10022
  disabled: !!o.disabled,
10023
+ readOnly: !!o.readOnly,
10021
10024
  clearable: !!o.clearable,
10022
10025
  hasOpenIndicator: !!o.hasOpenIndicator,
10023
10026
  placeholder: o.placeholder,
@@ -10100,6 +10103,7 @@
10100
10103
  p.multiItemEls = [];
10101
10104
 
10102
10105
  this.enable(!p.disabled);
10106
+ this.setReadOnly(!p.readOnly);
10103
10107
 
10104
10108
  this._setupDropdownMenu();
10105
10109
 
@@ -10326,6 +10330,32 @@
10326
10330
  return this._p.disabled;
10327
10331
  }
10328
10332
 
10333
+ /**
10334
+ * Sets read only mode
10335
+ * @param {boolean=true} readOnly Should the control be read only?
10336
+ * @returns {SelectBox}
10337
+ */
10338
+ setReadOnly(readOnly) {
10339
+ const p = this._p;
10340
+
10341
+ if (readOnly === undefined) {
10342
+ readOnly = true;
10343
+ }
10344
+ p.readOnly = !readOnly;
10345
+ p.el.setAttribute('aria-readOnly', p.readOnly.toString());
10346
+ p.input.readOnly = !(p.searchable || p.multi) || !!p.readOnly;
10347
+
10348
+ return this;
10349
+ }
10350
+
10351
+ /**
10352
+ * Is the control enabled?
10353
+ * @returns {boolean}
10354
+ */
10355
+ isReadOnly() {
10356
+ return !this._p.readOnly;
10357
+ }
10358
+
10329
10359
  /**
10330
10360
  * @param {string|string[]} classes
10331
10361
  * @returns {SelectBox}
@@ -11453,7 +11483,7 @@
11453
11483
  spellcheck: 'false',
11454
11484
  role: 'textbox',
11455
11485
  'aria-autocomplete': 'list',
11456
- readOnly: !(p.searchable || p.multi)
11486
+ readOnly: !(p.searchable || p.multi) || !!p.readOnly
11457
11487
  })
11458
11488
  );
11459
11489
  }
@@ -11487,7 +11517,7 @@
11487
11517
  if (!Dom.closestUntil(evt.target, ".".concat(p.baseClassName, "__item_remove"), evt.currentTarget))
11488
11518
  return;
11489
11519
 
11490
- if (p.disabled) return;
11520
+ if (p.disabled || p.readOnly) return;
11491
11521
 
11492
11522
  this._removeMultiItemFromEvent(
11493
11523
  /**@type Element*/
@@ -11540,6 +11570,7 @@
11540
11570
  if (p.hasOpenIndicator) {
11541
11571
  p.openIndicator = Dom.createElement('span', { class: "".concat(p.baseClassName, "__open_indicator") });
11542
11572
  p.el.appendChild(p.openIndicator);
11573
+ p.el.classList.add("".concat(p.baseClassName, "__has_open_indicator"));
11543
11574
  } else {
11544
11575
  DomCompat.remove(p.openIndicator);
11545
11576
  delete p.openIndicator;
@@ -11854,7 +11885,7 @@
11854
11885
 
11855
11886
  setTimeout(() => {
11856
11887
  if (this[DestroyedSymbol]) return; // destroyed by event handler
11857
- if (p.disabled) return;
11888
+ if (p.disabled || p.readOnly) return;
11858
11889
 
11859
11890
  this._trigger('search:blur');
11860
11891
 
@@ -11997,7 +12028,8 @@
11997
12028
  p.lastKeyAllowsNonTypeKeys &&
11998
12029
  !p.multi &&
11999
12030
  !dropList.hasFocusedItem() &&
12000
- !p.disabled)
12031
+ !p.disabled &&
12032
+ !p.readOnly)
12001
12033
  {
12002
12034
  this.toggleList();
12003
12035
  evt.preventDefault();
@@ -12009,20 +12041,20 @@
12009
12041
  if (p.input) {
12010
12042
  p.sink.
12011
12043
  add(p.input, 'input.dropdown', () => {var _p$dropList9;
12012
- if (p.disabled) return;
12044
+ if (p.disabled || p.readOnly) return;
12013
12045
 
12014
12046
  p.filterTerm = p.input.value.trim();
12015
12047
  (_p$dropList9 = p.dropList) === null || _p$dropList9 === void 0 || _p$dropList9.setSearchTerm(p.filterTerm, true);
12016
12048
  }).
12017
12049
  add(p.input, 'click.dropdown', () => {
12018
- if (p.disabled) return;
12050
+ if (p.disabled || p.readOnly) return;
12019
12051
 
12020
12052
  if (!p.multi && p.searchable) {
12021
12053
  this.openList();
12022
12054
  }
12023
12055
  }).
12024
12056
  add(p.input, 'focus.dropdown', () => {
12025
- if (p.disabled) return;
12057
+ if (p.disabled || p.readOnly) return;
12026
12058
 
12027
12059
  this._trigger('search:focus');
12028
12060
 
@@ -12039,7 +12071,7 @@
12039
12071
 
12040
12072
  p.sink.
12041
12073
  add(p.el, 'mousedown.dropdown', () => {
12042
- if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled) {
12074
+ if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled && !p.readOnly) {
12043
12075
  this.toggleList();
12044
12076
  }
12045
12077
  avoidToggleFromClick = false;
@@ -12048,7 +12080,7 @@
12048
12080
  if (currentTouchId) return;
12049
12081
  currentTouchId = evt.changedTouches[0].identifier;
12050
12082
 
12051
- if (this.isDisabled())
12083
+ if (this.isDisabled() || this.isReadOnly())
12052
12084
  return;
12053
12085
 
12054
12086
  if (Dom.closestUntil(evt.target, ".".concat(p.baseClassName, "__item,.").concat(p.baseClassName, "__clear"), p.el))
@@ -12488,7 +12520,7 @@
12488
12520
  p.el.classList.add("".concat(p.baseClassName, "__has_clear"));
12489
12521
 
12490
12522
  p.sink.add(p.clearButton, 'click', () => {
12491
- if (this.isDisabled()) return;
12523
+ if (this.isDisabled() || this.isReadOnly()) return;
12492
12524
  this.clear();
12493
12525
  });
12494
12526
  }
@@ -12642,7 +12674,7 @@
12642
12674
  if (p.input) p.input.readOnly = false;
12643
12675
  p.el.classList.add("".concat(p.baseClassName, "__searchable"));
12644
12676
  } else {
12645
- if (p.input) p.input.readOnly = true;
12677
+ if (p.input) p.input.readOnly = p.readOnly;
12646
12678
  p.el.classList.remove("".concat(p.baseClassName, "__searchable"));
12647
12679
  }
12648
12680
 
@@ -13024,7 +13056,7 @@
13024
13056
  _handleMultiKeydown(event) {
13025
13057
  const p = this._p;
13026
13058
 
13027
- if (p.disabled) return;
13059
+ if (p.disabled || p.readOnly) return;
13028
13060
 
13029
13061
  const isRtl = getComputedStyle(p.el).direction === 'rtl';
13030
13062