Files
hestiacp/web/js/src/focusFirstInput.js

14 lines
439 B
JavaScript
Raw Normal View History

2024-03-19 22:05:27 +03:00
// If no dialog is open, focus first input in main content form
// TODO: Replace this with autofocus attributes in the HTML
export default function focusFirstInput() {
const openDialogs = document.querySelectorAll('dialog[open]');
if (openDialogs.length === 0) {
const input = document.querySelector(
'#main-form .form-control:not([disabled]), #main-form .form-select:not([disabled])'
);
if (input) {
input.focus();
}
}
}