@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.cjs.js +50 -4
- package/dist/lib.cjs.js.map +1 -1
- package/dist/lib.cjs.min.js +2 -2
- package/dist/lib.cjs.min.js.map +1 -1
- package/dist/lib.es6.js +50 -4
- package/dist/lib.es6.js.map +1 -1
- package/dist/lib.es6.min.js +2 -2
- package/dist/lib.es6.min.js.map +1 -1
- package/dist/lib.umd.js +50 -4
- package/dist/lib.umd.js.map +1 -1
- package/dist/lib.umd.min.js +2 -2
- package/dist/lib.umd.min.js.map +1 -1
- package/lib/SelectBox.js +49 -3
- package/package.json +1 -1
package/dist/lib.es6.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @danielgindi/selectbox 2.0.
|
|
2
|
+
* @danielgindi/selectbox 2.0.50
|
|
3
3
|
* git://github.com/danielgindi/selectbox.git
|
|
4
4
|
*/
|
|
5
5
|
import { createElement, closestUntil, setElementAttrs, next, prev } from '@danielgindi/dom-utils/lib/Dom';
|
|
@@ -3496,6 +3496,42 @@ const defaultMultiPlaceholderFormatter = (items, labelProp) => {
|
|
|
3496
3496
|
return title;
|
|
3497
3497
|
};
|
|
3498
3498
|
|
|
3499
|
+
|
|
3500
|
+
function getFocusState(element) {
|
|
3501
|
+
if (!element)
|
|
3502
|
+
return null;
|
|
3503
|
+
|
|
3504
|
+
const state = { element };
|
|
3505
|
+
|
|
3506
|
+
if (typeof element.selectionStart === 'number' &&
|
|
3507
|
+
typeof element.selectionEnd === 'number') {
|
|
3508
|
+
state.selectionStart = element.selectionStart;
|
|
3509
|
+
state.selectionEnd = element.selectionEnd;
|
|
3510
|
+
state.selectionDirection = element.selectionDirection;
|
|
3511
|
+
}
|
|
3512
|
+
|
|
3513
|
+
return state;
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
function restoreFocusState(state) {
|
|
3517
|
+
if (!state?.element || !document.body.contains(state.element))
|
|
3518
|
+
return false;
|
|
3519
|
+
|
|
3520
|
+
state.element.focus();
|
|
3521
|
+
|
|
3522
|
+
if (typeof state.selectionStart === 'number' &&
|
|
3523
|
+
typeof state.selectionEnd === 'number' &&
|
|
3524
|
+
typeof state.element.setSelectionRange === 'function') {
|
|
3525
|
+
state.element.setSelectionRange(
|
|
3526
|
+
state.selectionStart,
|
|
3527
|
+
state.selectionEnd,
|
|
3528
|
+
state.selectionDirection ?? 'none',
|
|
3529
|
+
);
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
return true;
|
|
3533
|
+
}
|
|
3534
|
+
|
|
3499
3535
|
/*
|
|
3500
3536
|
Emits the following events:
|
|
3501
3537
|
---------------------------
|
|
@@ -4760,6 +4796,9 @@ class SelectBox {
|
|
|
4760
4796
|
|
|
4761
4797
|
this._trigger('open:before', { list: p.dropList });
|
|
4762
4798
|
|
|
4799
|
+
if (document.activeElement !== p.input)
|
|
4800
|
+
p.lastActiveElement = document.activeElement === document.body ? null : getFocusState(document.activeElement);
|
|
4801
|
+
|
|
4763
4802
|
// Propagate direction to droplist
|
|
4764
4803
|
p.dropList.setDirection(getComputedStyle(p.el).direction);
|
|
4765
4804
|
|
|
@@ -4794,6 +4833,12 @@ class SelectBox {
|
|
|
4794
4833
|
|
|
4795
4834
|
p.dropList.hide();
|
|
4796
4835
|
|
|
4836
|
+
if (p.lastActiveElement) {
|
|
4837
|
+
if (!p.multi && !p.searchable)
|
|
4838
|
+
restoreFocusState(p.lastActiveElement);
|
|
4839
|
+
p.lastActiveElement = null;
|
|
4840
|
+
}
|
|
4841
|
+
|
|
4797
4842
|
return this;
|
|
4798
4843
|
}
|
|
4799
4844
|
|
|
@@ -5386,9 +5431,10 @@ class SelectBox {
|
|
|
5386
5431
|
|
|
5387
5432
|
this.closeList();
|
|
5388
5433
|
|
|
5389
|
-
if (p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
|
|
5390
|
-
p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection)
|
|
5391
|
-
p.input && p.input
|
|
5434
|
+
if ((p.blurOnSingleSelection === 'touch' && hasTouchCapability ||
|
|
5435
|
+
p.blurOnSingleSelection !== 'touch' && p.blurOnSingleSelection) &&
|
|
5436
|
+
p.input && document.activeElement === p.input) {
|
|
5437
|
+
p.input.blur();
|
|
5392
5438
|
}
|
|
5393
5439
|
}
|
|
5394
5440
|
break;
|