@danielgindi/selectbox 2.0.48 → 2.0.50

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.50
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,9 @@
11249
11285
 
11250
11286
  this._trigger('open:before', { list: p.dropList });
11251
11287
 
11288
+ if (document.activeElement !== p.input)
11289
+ p.lastActiveElement = document.activeElement === document.body ? null : getFocusState(document.activeElement);
11290
+
11252
11291
  // Propagate direction to droplist
11253
11292
  p.dropList.setDirection(getComputedStyle(p.el).direction);
11254
11293
 
@@ -11283,6 +11322,12 @@
11283
11322
 
11284
11323
  p.dropList.hide();
11285
11324
 
11325
+ if (p.lastActiveElement) {
11326
+ if (!p.multi && !p.searchable)
11327
+ restoreFocusState(p.lastActiveElement);
11328
+ p.lastActiveElement = null;
11329
+ }
11330
+
11286
11331
  return this;
11287
11332
  }
11288
11333
 
@@ -11875,9 +11920,10 @@
11875
11920
 
11876
11921
  this.closeList();
11877
11922
 
11878
- if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11879
- p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) {
11880
- p.input && p.input.blur();
11923
+ if ((p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
11924
+ p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) &&
11925
+ p.input && document.activeElement === p.input) {
11926
+ p.input.blur();
11881
11927
  }
11882
11928
  }
11883
11929
  break;