@danielgindi/selectbox 2.0.47 → 2.0.49

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.cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.47
2
+ * @danielgindi/selectbox 2.0.49
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  'use strict';
@@ -6947,9 +6947,8 @@ class DropList {
6947
6947
  }
6948
6948
 
6949
6949
  if (p.multi) {
6950
- if (p.focusItemIndex >= 0) {
6950
+ if (this.hasFocusedItem()) {
6951
6951
  this.toggleFocusedItem();
6952
- event.preventDefault();
6953
6952
  }
6954
6953
  } else {var _item$ItemSymbol3;
6955
6954
  this._setSingleSelectedItemEl(p.focusItemEl);
@@ -8739,8 +8738,6 @@ class DropList {
8739
8738
  if (this[DestroyedSymbol$1])
8740
8739
  return;
8741
8740
 
8742
- this.toggleFocusedItem();
8743
-
8744
8741
  if (document.activeElement !== this.el && p.focusItemEl) {
8745
8742
  clearTimeout(p.blurTimer);
8746
8743
  }
@@ -9992,6 +9989,42 @@ const defaultMultiPlaceholderFormatter = (items, labelProp) => {
9992
9989
  return title;
9993
9990
  };
9994
9991
 
9992
+
9993
+ function getFocusState(element) {
9994
+ if (!element)
9995
+ return null;
9996
+
9997
+ const state = { element };
9998
+
9999
+ if (typeof element.selectionStart === 'number' &&
10000
+ typeof element.selectionEnd === 'number') {
10001
+ state.selectionStart = element.selectionStart;
10002
+ state.selectionEnd = element.selectionEnd;
10003
+ state.selectionDirection = element.selectionDirection;
10004
+ }
10005
+
10006
+ return state;
10007
+ }
10008
+
10009
+ function restoreFocusState(state) {
10010
+ if (!(state !== null && state !== void 0 && state.element) || !document.body.contains(state.element))
10011
+ return false;
10012
+
10013
+ state.element.focus();
10014
+
10015
+ if (typeof state.selectionStart === 'number' &&
10016
+ typeof state.selectionEnd === 'number' &&
10017
+ typeof state.element.setSelectionRange === 'function') {var _state$selectionDirec;
10018
+ state.element.setSelectionRange(
10019
+ state.selectionStart,
10020
+ state.selectionEnd, (_state$selectionDirec =
10021
+ state.selectionDirection) !== null && _state$selectionDirec !== void 0 ? _state$selectionDirec : 'none'
10022
+ );
10023
+ }
10024
+
10025
+ return true;
10026
+ }
10027
+
9995
10028
  /*
9996
10029
  Emits the following events:
9997
10030
  ---------------------------
@@ -11256,6 +11289,8 @@ class SelectBox {
11256
11289
 
11257
11290
  this._trigger('open:before', { list: p.dropList });
11258
11291
 
11292
+ p.lastActiveElement = document.activeElement === document.body ? null : getFocusState(document.activeElement);
11293
+
11259
11294
  // Propagate direction to droplist
11260
11295
  p.dropList.setDirection(getComputedStyle(p.el).direction);
11261
11296
 
@@ -11290,6 +11325,11 @@ class SelectBox {
11290
11325
 
11291
11326
  p.dropList.hide();
11292
11327
 
11328
+ if (p.lastActiveElement) {
11329
+ restoreFocusState(p.lastActiveElement);
11330
+ p.lastActiveElement = null;
11331
+ }
11332
+
11293
11333
  return this;
11294
11334
  }
11295
11335
 
@@ -11882,9 +11922,10 @@ class SelectBox {
11882
11922
 
11883
11923
  this.closeList();
11884
11924
 
11885
- if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11886
- p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) {
11887
- p.input && p.input.blur();
11925
+ if ((p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11926
+ p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) &&
11927
+ p.input && document.activeElement === p.input) {
11928
+ p.input.blur();
11888
11929
  }
11889
11930
  }
11890
11931
  break;