@danielgindi/selectbox 2.0.36 → 2.0.38

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.es6.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.36
2
+ * @danielgindi/selectbox 2.0.38
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
@@ -2737,14 +2737,14 @@ class DropList {
2737
2737
 
2738
2738
  // Inline search box not available, then support typing to focus by first letters
2739
2739
  if (!p.searchable)
2740
- this._keydownFreeType(event);
2740
+ this._keydownFreeType(event, !this.isVisible());
2741
2741
 
2742
2742
  preventDefault = false;
2743
2743
  }
2744
2744
  }
2745
2745
  }
2746
2746
 
2747
- _keydownFreeType(evt) {
2747
+ _keydownFreeType(evt, autoSelect) {
2748
2748
  const p = this._p;
2749
2749
 
2750
2750
  // noinspection JSDeprecatedSymbols
@@ -2803,7 +2803,7 @@ class DropList {
2803
2803
  let next = p.virtualListHelper.getItemElementAt(matchIndex);
2804
2804
  this._focus(evt, next || null, matchIndex, true);
2805
2805
 
2806
- if (!this.isVisible()) {
2806
+ if (autoSelect) {
2807
2807
  this.triggerItemSelection(next ? null : items[matchIndex], evt);
2808
2808
  }
2809
2809
 
@@ -3420,6 +3420,7 @@ const inputBackbufferCssProps = [
3420
3420
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
3421
3421
  * @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
3422
3422
  * @property {boolean} [searchable=false] is it searchable?
3423
+ * @property {boolean} [allowTypeToSelect=true] default behavior of type to select (focus first item starting with the search term) when searchable is true
3423
3424
  * @property {string} [noResultsText='No matching results'] text for no results (empty for none)
3424
3425
  * @property {boolean} [autoSelectTextOnCheck=true] automatically select text in input when an item is checked (multi mode). Used to allow the user to quickly type multiple items.
3425
3426
  * @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
@@ -3550,6 +3551,7 @@ class SelectBox {
3550
3551
  showPlaceholderInTooltip: o.showPlaceholderInTooltip,
3551
3552
  multiPlaceholderFormatter: o.multiPlaceholderFormatter,
3552
3553
  searchable: o.searchable,
3554
+ allowTypeToSelect: o.allowTypeToSelect,
3553
3555
  noResultsText: o.noResultsText,
3554
3556
  autoSelectTextOnCheck: o.autoSelectTextOnCheck,
3555
3557
 
@@ -4332,6 +4334,20 @@ class SelectBox {
4332
4334
  return this;
4333
4335
  }
4334
4336
 
4337
+ /**
4338
+ * @param {boolean} allowTypeToSelect
4339
+ * @returns {SelectBox}
4340
+ */
4341
+ setAllowTypeToSelect(allowTypeToSelect) {
4342
+ const p = this._p;
4343
+ allowTypeToSelect = !!allowTypeToSelect;
4344
+ if (p.allowTypeToSelect === allowTypeToSelect)
4345
+ return this;
4346
+
4347
+ p.allowTypeToSelect = allowTypeToSelect;
4348
+ return this;
4349
+ }
4350
+
4335
4351
  /**
4336
4352
  * @returns {boolean}
4337
4353
  */
@@ -5531,7 +5547,15 @@ class SelectBox {
5531
5547
  break;
5532
5548
 
5533
5549
  default:
5534
- dropList._keydownFreeType(evt);
5550
+ if (p.allowTypeToSelect) {
5551
+ dropList._keydownFreeType(evt, true);
5552
+ } else {
5553
+ this.openList();
5554
+ setTimeout(() => {
5555
+ if (this[DestroyedSymbol]) return; // destroyed by event handler
5556
+ dropList._keydownFreeType(evt, false);
5557
+ });
5558
+ }
5535
5559
  break;
5536
5560
  }
5537
5561