@danielgindi/selectbox 2.0.37 → 2.0.39

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.37
2
+ * @danielgindi/selectbox 2.0.39
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,6 +2803,10 @@ class DropList {
2803
2803
  let next = p.virtualListHelper.getItemElementAt(matchIndex);
2804
2804
  this._focus(evt, next || null, matchIndex, true);
2805
2805
 
2806
+ if (autoSelect) {
2807
+ this.triggerItemSelection(next ? null : items[matchIndex], evt);
2808
+ }
2809
+
2806
2810
  // Record the last filter used
2807
2811
  p.previousFilter = keyword;
2808
2812
 
@@ -3416,6 +3420,7 @@ const inputBackbufferCssProps = [
3416
3420
  * @property {function(item: DropList.ItemBase, itemEl: Element):(*|false)} [renderRestMultiItem]
3417
3421
  * @property {function(item: DropList.ItemBase, itemEl: Element)} [unrenderRestMultiItem]
3418
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
3419
3424
  * @property {string} [noResultsText='No matching results'] text for no results (empty for none)
3420
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.
3421
3426
  * @property {number} [filterThrottleWindow=300] throttle time (milliseconds) for filtering
@@ -3546,6 +3551,7 @@ class SelectBox {
3546
3551
  showPlaceholderInTooltip: o.showPlaceholderInTooltip,
3547
3552
  multiPlaceholderFormatter: o.multiPlaceholderFormatter,
3548
3553
  searchable: o.searchable,
3554
+ allowTypeToSelect: o.allowTypeToSelect,
3549
3555
  noResultsText: o.noResultsText,
3550
3556
  autoSelectTextOnCheck: o.autoSelectTextOnCheck,
3551
3557
 
@@ -4328,6 +4334,20 @@ class SelectBox {
4328
4334
  return this;
4329
4335
  }
4330
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
+
4331
4351
  /**
4332
4352
  * @returns {boolean}
4333
4353
  */
@@ -5527,11 +5547,17 @@ class SelectBox {
5527
5547
  break;
5528
5548
 
5529
5549
  default:
5530
- if (!dropList.isVisible()) {
5550
+ if (dropList.isVisible()) {
5551
+ dropList._keydownFreeType(evt, false);
5552
+ } else if (p.allowTypeToSelect) {
5553
+ dropList._keydownFreeType(evt, true);
5554
+ } else {
5531
5555
  this.openList();
5556
+ setTimeout(() => {
5557
+ if (this[DestroyedSymbol]) return; // destroyed by event handler
5558
+ dropList._keydownFreeType(evt, false);
5559
+ });
5532
5560
  }
5533
-
5534
- dropList._keydownFreeType(evt);
5535
5561
  break;
5536
5562
  }
5537
5563