@danielgindi/selectbox 2.0.48 → 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.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @danielgindi/selectbox 2.0.48
2
+ * @danielgindi/selectbox 2.0.49
3
3
  * git://github.com/danielgindi/selectbox.git
4
4
  */
5
5
  (function (global, factory) {
@@ -9985,6 +9985,42 @@
9985
9985
  return title;
9986
9986
  };
9987
9987
 
9988
+
9989
+ function getFocusState(element) {
9990
+ if (!element)
9991
+ return null;
9992
+
9993
+ const state = { element };
9994
+
9995
+ if (typeof element.selectionStart === 'number' &&
9996
+ typeof element.selectionEnd === 'number') {
9997
+ state.selectionStart = element.selectionStart;
9998
+ state.selectionEnd = element.selectionEnd;
9999
+ state.selectionDirection = element.selectionDirection;
10000
+ }
10001
+
10002
+ return state;
10003
+ }
10004
+
10005
+ function restoreFocusState(state) {
10006
+ if (!(state !== null && state !== void 0 && state.element) || !document.body.contains(state.element))
10007
+ return false;
10008
+
10009
+ state.element.focus();
10010
+
10011
+ if (typeof state.selectionStart === 'number' &&
10012
+ typeof state.selectionEnd === 'number' &&
10013
+ typeof state.element.setSelectionRange === 'function') {var _state$selectionDirec;
10014
+ state.element.setSelectionRange(
10015
+ state.selectionStart,
10016
+ state.selectionEnd, (_state$selectionDirec =
10017
+ state.selectionDirection) !== null && _state$selectionDirec !== void 0 ? _state$selectionDirec : 'none'
10018
+ );
10019
+ }
10020
+
10021
+ return true;
10022
+ }
10023
+
9988
10024
  /*
9989
10025
  Emits the following events:
9990
10026
  ---------------------------
@@ -11249,6 +11285,8 @@
11249
11285
 
11250
11286
  this._trigger('open:before', { list: p.dropList });
11251
11287
 
11288
+ p.lastActiveElement = document.activeElement === document.body ? null : getFocusState(document.activeElement);
11289
+
11252
11290
  // Propagate direction to droplist
11253
11291
  p.dropList.setDirection(getComputedStyle(p.el).direction);
11254
11292
 
@@ -11283,6 +11321,11 @@
11283
11321
 
11284
11322
  p.dropList.hide();
11285
11323
 
11324
+ if (p.lastActiveElement) {
11325
+ restoreFocusState(p.lastActiveElement);
11326
+ p.lastActiveElement = null;
11327
+ }
11328
+
11286
11329
  return this;
11287
11330
  }
11288
11331
 
@@ -11875,9 +11918,10 @@
11875
11918
 
11876
11919
  this.closeList();
11877
11920
 
11878
- if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11879
- p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) {
11880
- p.input && p.input.blur();
11921
+ if ((p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11922
+ p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) &&
11923
+ p.input && document.activeElement === p.input) {
11924
+ p.input.blur();
11881
11925
  }
11882
11926
  }
11883
11927
  break;