Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus inside input field on show show input modal #10789

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 !== firstFocusableElement && 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
Loading