@danielgindi/selectbox 2.0.26 → 2.0.28

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.26
2
+ * @danielgindi/selectbox 2.0.28
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -6367,7 +6367,7 @@
6367
6367
  /** */
6368
6368
 
6369
6369
  /** @type {DropList.Options} */
6370
- let defaultOptions$1 = {
6370
+ const DefaultOptions$1 = {
6371
6371
  baseClassName: 'droplist',
6372
6372
 
6373
6373
  autoItemBlur: true,
@@ -6426,7 +6426,7 @@
6426
6426
  * @param {DropList.Options} options
6427
6427
  */
6428
6428
  constructor(options) {var _o$positionOptionsPro;
6429
- const o = _objectSpread2({}, defaultOptions$1);
6429
+ const o = _objectSpread2({}, DefaultOptions$1);
6430
6430
 
6431
6431
  for (let [key, value] of Object.entries(/**@type Object*/options))
6432
6432
  if (value !== undefined)
@@ -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
@@ -9893,6 +9894,7 @@
9893
9894
  * @property {string} [labelProp='label']
9894
9895
  * @property {string} [valueProp='value']
9895
9896
  * @property {string} [multiItemLabelProp='short_label']
9897
+ * @property {'after'|'before'|'none'} [multiItemRemovePosition='after']
9896
9898
  * @property {number} [maxMultiItems] maximum number of multi items. The rest will get a single item to represent.
9897
9899
  * @property {function(count: number, items: DropList.ItemBase[]):string} [multiItemsRestLabelProvider] label for the item representing the rest of the items.
9898
9900
  * @property {DropList.ItemBase[]|null} [items] initial items
@@ -9915,10 +9917,11 @@
9915
9917
  * @property {boolean} [closeListWhenLoading] whether we should close the list automatically when loading
9916
9918
  * @property {string[]} [clearInputWhen=['single_close','multi_select_single']] clear input box when closing the droplist or selecting <code>['single_close', 'multi_close', 'multi_select_single']</code>
9917
9919
  * */
9918
- const defaultOptions = {
9920
+ const DefaultOptions = {
9919
9921
  el: null,
9920
9922
  baseClassName: 'selectbox',
9921
9923
  disabled: false,
9924
+ readonly: false,
9922
9925
  clearable: true,
9923
9926
  hasOpenIndicator: true,
9924
9927
  placeholder: '',
@@ -9942,6 +9945,7 @@
9942
9945
  labelProp: 'label',
9943
9946
  valueProp: 'value',
9944
9947
  multiItemLabelProp: 'short_label',
9948
+ multiItemRemovePosition: 'after',
9945
9949
  maxMultiItems: null,
9946
9950
  multiItemsRestLabelProvider: null,
9947
9951
  items: [],
@@ -10000,7 +10004,7 @@
10000
10004
  * @param {SelectBox.Options} options
10001
10005
  */
10002
10006
  constructor(options) {
10003
- const o = _objectSpread2({}, defaultOptions);
10007
+ const o = _objectSpread2({}, DefaultOptions);
10004
10008
 
10005
10009
  for (let [key, value] of Object.entries(/**@type Object*/options))
10006
10010
  if (value !== undefined)
@@ -10016,6 +10020,7 @@
10016
10020
  listOptions: o.listOptions,
10017
10021
 
10018
10022
  disabled: !!o.disabled,
10023
+ readonly: !!o.readonly,
10019
10024
  clearable: !!o.clearable,
10020
10025
  hasOpenIndicator: !!o.hasOpenIndicator,
10021
10026
  placeholder: o.placeholder,
@@ -10038,6 +10043,7 @@
10038
10043
  labelProp: o.labelProp,
10039
10044
  valueProp: o.valueProp,
10040
10045
  multiItemLabelProp: o.multiItemLabelProp,
10046
+ multiItemRemovePosition: o.multiItemRemovePosition,
10041
10047
 
10042
10048
  maxMultiItems: o.maxMultiItems,
10043
10049
  multiItemsRestLabelProvider: o.multiItemsRestLabelProvider,
@@ -10097,6 +10103,7 @@
10097
10103
  p.multiItemEls = [];
10098
10104
 
10099
10105
  this.enable(!p.disabled);
10106
+ this.setReadOnly(!p.readonly);
10100
10107
 
10101
10108
  this._setupDropdownMenu();
10102
10109
 
@@ -10323,6 +10330,32 @@
10323
10330
  return this._p.disabled;
10324
10331
  }
10325
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.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
+
10326
10359
  /**
10327
10360
  * @param {string|string[]} classes
10328
10361
  * @returns {SelectBox}
@@ -10950,6 +10983,18 @@
10950
10983
  setMultiItemLabelProp(prop) {
10951
10984
  const p = this._p;
10952
10985
  p.multiItemLabelProp = prop;
10986
+ this._scheduleSync('render_items');
10987
+ return this;
10988
+ }
10989
+
10990
+ /**
10991
+ * @param {'before'|'after'|'none'} position
10992
+ * @returns {SelectBox}
10993
+ */
10994
+ setMultiItemRemovePosition(position) {
10995
+ const p = this._p;
10996
+ p.multiItemRemovePosition = position;
10997
+ this._scheduleSync('render_items');
10953
10998
  return this;
10954
10999
  }
10955
11000
 
@@ -11472,7 +11517,7 @@
11472
11517
  if (!Dom.closestUntil(evt.target, ".".concat(p.baseClassName, "__item_remove"), evt.currentTarget))
11473
11518
  return;
11474
11519
 
11475
- if (p.disabled) return;
11520
+ if (p.disabled || p.readonly) return;
11476
11521
 
11477
11522
  this._removeMultiItemFromEvent(
11478
11523
  /**@type Element*/
@@ -11525,6 +11570,7 @@
11525
11570
  if (p.hasOpenIndicator) {
11526
11571
  p.openIndicator = Dom.createElement('span', { class: "".concat(p.baseClassName, "__open_indicator") });
11527
11572
  p.el.appendChild(p.openIndicator);
11573
+ p.el.classList.add("".concat(p.baseClassName, "__has_open_indicator"));
11528
11574
  } else {
11529
11575
  DomCompat.remove(p.openIndicator);
11530
11576
  delete p.openIndicator;
@@ -11839,7 +11885,7 @@
11839
11885
 
11840
11886
  setTimeout(() => {
11841
11887
  if (this[DestroyedSymbol]) return; // destroyed by event handler
11842
- if (p.disabled) return;
11888
+ if (p.disabled || p.readonly) return;
11843
11889
 
11844
11890
  this._trigger('search:blur');
11845
11891
 
@@ -11982,7 +12028,8 @@
11982
12028
  p.lastKeyAllowsNonTypeKeys &&
11983
12029
  !p.multi &&
11984
12030
  !dropList.hasFocusedItem() &&
11985
- !p.disabled)
12031
+ !p.disabled &&
12032
+ !p.readonly)
11986
12033
  {
11987
12034
  this.toggleList();
11988
12035
  evt.preventDefault();
@@ -11994,20 +12041,20 @@
11994
12041
  if (p.input) {
11995
12042
  p.sink.
11996
12043
  add(p.input, 'input.dropdown', () => {var _p$dropList9;
11997
- if (p.disabled) return;
12044
+ if (p.disabled || p.readonly) return;
11998
12045
 
11999
12046
  p.filterTerm = p.input.value.trim();
12000
12047
  (_p$dropList9 = p.dropList) === null || _p$dropList9 === void 0 || _p$dropList9.setSearchTerm(p.filterTerm, true);
12001
12048
  }).
12002
12049
  add(p.input, 'click.dropdown', () => {
12003
- if (p.disabled) return;
12050
+ if (p.disabled || p.readonly) return;
12004
12051
 
12005
12052
  if (!p.multi && p.searchable) {
12006
12053
  this.openList();
12007
12054
  }
12008
12055
  }).
12009
12056
  add(p.input, 'focus.dropdown', () => {
12010
- if (p.disabled) return;
12057
+ if (p.disabled || p.readonly) return;
12011
12058
 
12012
12059
  this._trigger('search:focus');
12013
12060
 
@@ -12024,7 +12071,7 @@
12024
12071
 
12025
12072
  p.sink.
12026
12073
  add(p.el, 'mousedown.dropdown', () => {
12027
- if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled) {
12074
+ if (!p.multi && !p.searchable && !avoidToggleFromClick && !p.disabled && !p.readonly) {
12028
12075
  this.toggleList();
12029
12076
  }
12030
12077
  avoidToggleFromClick = false;
@@ -12033,7 +12080,7 @@
12033
12080
  if (currentTouchId) return;
12034
12081
  currentTouchId = evt.changedTouches[0].identifier;
12035
12082
 
12036
- if (this.isDisabled())
12083
+ if (this.isDisabled() || this.isReadOnly())
12037
12084
  return;
12038
12085
 
12039
12086
  if (Dom.closestUntil(evt.target, ".".concat(p.baseClassName, "__item,.").concat(p.baseClassName, "__clear"), p.el))
@@ -12473,7 +12520,7 @@
12473
12520
  p.el.classList.add("".concat(p.baseClassName, "__has_clear"));
12474
12521
 
12475
12522
  p.sink.add(p.clearButton, 'click', () => {
12476
- if (this.isDisabled()) return;
12523
+ if (this.isDisabled() || this.isReadOnly()) return;
12477
12524
  this.clear();
12478
12525
  });
12479
12526
  }
@@ -12670,22 +12717,29 @@
12670
12717
  if (label === false)
12671
12718
  return null;
12672
12719
 
12720
+ const elRemove = Dom.createElement('span', {
12721
+ class: "".concat(p.baseClassName, "__item_remove"),
12722
+ role: 'presentation'
12723
+ });
12724
+
12673
12725
  const itemEl = Dom.createElement('li',
12674
12726
  {
12675
12727
  class: "".concat(p.baseClassName, "__item"),
12676
12728
  tabindex: '0',
12677
12729
  title: label
12678
- },
12679
- [
12680
- Dom.createElement('span', {
12681
- class: "".concat(p.baseClassName, "__item_remove"),
12682
- role: 'presentation'
12683
- })]
12684
-
12730
+ }
12685
12731
  );
12686
12732
 
12733
+ if (p.multiItemRemovePosition === 'before') {
12734
+ itemEl.appendChild(elRemove);
12735
+ }
12736
+
12687
12737
  this._renderMultiItemContent(item, itemEl);
12688
12738
 
12739
+ if (p.multiItemRemovePosition === 'after') {
12740
+ itemEl.appendChild(elRemove);
12741
+ }
12742
+
12689
12743
  itemEl[ItemSymbol] = item;
12690
12744
 
12691
12745
  return itemEl;
@@ -13002,7 +13056,7 @@
13002
13056
  _handleMultiKeydown(event) {
13003
13057
  const p = this._p;
13004
13058
 
13005
- if (p.disabled) return;
13059
+ if (p.disabled || p.readonly) return;
13006
13060
 
13007
13061
  const isRtl = getComputedStyle(p.el).direction === 'rtl';
13008
13062