diff --git a/media_server/static/js/app.js b/media_server/static/js/app.js index 65617a1..ecf4c76 100644 --- a/media_server/static/js/app.js +++ b/media_server/static/js/app.js @@ -133,6 +133,23 @@ Object.assign(window, { // Initialization (DOMContentLoaded) // ============================================================ +// Prevent .showModal() from auto-focusing the first input field. +// On touch devices this pops up the on-screen keyboard, which is confusing +// when the user just opened a dialog. Force focus onto the dialog itself. +const _origShowModal = HTMLDialogElement.prototype.showModal; +HTMLDialogElement.prototype.showModal = function (...args) { + if (!this.hasAttribute('tabindex')) { + this.setAttribute('tabindex', '-1'); + } + const result = _origShowModal.apply(this, args); + const active = document.activeElement; + if (active && active !== this && this.contains(active)) { + active.blur(); + this.focus({ preventScroll: true }); + } + return result; +}; + window.addEventListener('DOMContentLoaded', async () => { // Cache DOM references cacheDom();