dialog focus fix

This commit is contained in:
Yuri Kuznetsov
2022-08-29 17:12:01 +03:00
parent 9644729f68
commit 8b06f2c02c
+38 -1
View File
@@ -625,6 +625,39 @@ function (/** marked~ */marked, /** DOMPurify~ */ DOMPurify) {
$($modalContainer.get($modalContainer.length - 2)).removeClass('overlaid');
};
/**
* @private
* @param {Element} element
* @return {Element|null}
*/
Dialog.prototype._findClosestFocusableElement = function (element) {
let isVisible = !!(
element.offsetWidth ||
element.offsetHeight ||
element.getClientRects().length
);
if (isVisible) {
element.focus({preventScroll: true});
return element;
}
let $element = $(element);
if ($element.closest('.dropdown-menu').length) {
let $button = $element.closest('.btn-group').find(`[data-toggle="dropdown"]`);
if ($button.length) {
$button.get(0).focus({preventScroll: true});
return $button.get(0);
}
}
return null;
};
/**
* Close.
*/
@@ -635,7 +668,11 @@ function (/** marked~ */marked, /** DOMPurify~ */ DOMPurify) {
if (this.activeElement) {
setTimeout(() => {
this.activeElement.focus({preventScroll: true});
let element = this._findClosestFocusableElement(this.activeElement);
if (element) {
element.focus({preventScroll: true});
}
}, 50);
}
}