Skip to content

Commit

Permalink
Focus inside input field on show show input modal
Browse files Browse the repository at this point in the history
- fix regression caused by #10795
- need to handle both tabcontrol element and single init focus element

Signed-off-by: Darshan-upadhyay1110 <darshan.upadhyay@collabora.com>
Change-Id: I5a29ddf7b4562221fc8a6c574a775d2a2e9180a8
  • Loading branch information
Darshan-upadhyay1110 committed Dec 26, 2024
1 parent ef0fb24 commit 1276de9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions browser/src/control/Control.JSDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,22 +397,25 @@ L.Control.JSDialog = L.Control.extend({
// this will only search in current instance and not in whole docuemnt
const tabControlWidget = this.findTabControl(instance);

let focusWidget ;
let focusWidget, firstFocusableElement ;

if (tabControlWidget) {
// get DOM element of tabControl from current instance
focusWidget = instance.content.querySelector('[id="' + tabControlWidget.id + '"]');
firstFocusableElement = JSDialog.GetFocusableElements(focusWidget);

} else {
focusWidget = instance.init_focus_id ? instance.container.querySelector('[id=\'' + instance.init_focus_id + '\']') : null;
// will directly set element of focusable element based on init focus id
firstFocusableElement = instance.init_focus_id ? instance.container.querySelector('[id=\'' + instance.init_focus_id + '\']') : null;
}

if (focusWidget && document.activeElement !== focusWidget && instance.canHaveFocus) {
var firstFocusable = JSDialog.GetFocusableElements(focusWidget);
if (firstFocusable && firstFocusable.length)
firstFocusable[0].focus();
else
console.error('cannot get focus for widget: "' + instance.init_focus_id + '"');
if (firstFocusableElement && document.activeElement !== focusWidget && instance.canHaveFocus) {
// for tab control case we have more then 1 element that can be focusable so select the first tab for the list
firstFocusableElement = firstFocusableElement.length > 0 ? firstFocusableElement[0] : firstFocusableElement;
firstFocusableElement.focus();
}
else
console.error('cannot get focus for widget: "' + instance.init_focus_id + '"');

if (instance.isDropdown && instance.isSubmenu) {
instance.container.addEventListener('mouseleave', function () {
Expand Down

0 comments on commit 1276de9

Please sign in to comment.