A platform for community discussion. Free, open, simple.
FIX: Allow typing in modals opened from the mobile topic-footer menu (#40510)
Alan Guo Xiang Tan396ee1488fdd
diff --git a/frontend/discourse/app/ui-kit/d-modal.gjs b/frontend/discourse/app/ui-kit/d-modal.gjsindex e34a7f58430..635c64bfcca 100644--- a/frontend/discourse/app/ui-kit/d-modal.gjs+++ b/frontend/discourse/app/ui-kit/d-modal.gjs@@ -234,12 +234,13 @@ export default class DModal extends Component {}// Prevent keyboard events from leaking to elements behind the modal.- // Allow events when focus is inside a float-kit portal (menu/tooltip)- // opened from this modal, since those render outside the modal DOM.+ // Allow events when focus is inside another modal stacked above this one,+ // or inside a float-kit portal (menu/tooltip) opened from this modal,+ // since those render outside the modal DOM.if (!this.wrapperElement.contains(document.activeElement) &&!document.activeElement?.closest(- ".fk-d-menu, .fk-d-menu-modal, .fk-d-tooltip"+ ".d-modal, .fk-d-menu, .fk-d-menu-modal, .fk-d-tooltip")) {event.stopPropagation();diff --git a/frontend/discourse/tests/integration/ui-kit/d-modal-test.gjs b/frontend/discourse/tests/integration/ui-kit/d-modal-test.gjsindex 7c9298fd6dd..9722912bb2c 100644--- a/frontend/discourse/tests/integration/ui-kit/d-modal-test.gjs+++ b/frontend/discourse/tests/integration/ui-kit/d-modal-test.gjs@@ -288,4 +288,32 @@ module("Integration | ui-kit | DModal", function (hooks) {"pressing enter inside select-kit does not trigger the default button");});++ test("does not swallow keystrokes aimed at a modal stacked above it", async function (assert) {+ await render(+ <template>+ <DModal @inline={{true}} @title="Underlying modal" />+ <DModal @inline={{true}} @title="Stacked modal">+ <:body>+ <input type="text" class="stacked-modal-input" />+ </:body>+ </DModal>+ </template>+ );++ const inputElement = document.querySelector(".stacked-modal-input");+ inputElement.focus();++ const event = new KeyboardEvent("keydown", {+ key: "a",+ bubbles: true,+ cancelable: true,+ });+ inputElement.dispatchEvent(event);++ assert.false(+ event.defaultPrevented,+ "the underlying modal does not preventDefault keystrokes aimed at the modal stacked above it"+ );+ });});