Skip to content

A platform for community discussion. Free, open, simple.

FIX: prevent event bubbling in photoswipe on escape (#36134)

David Battersbyf38528538ff0
diff --git a/frontend/discourse/app/lib/lightbox.js b/frontend/discourse/app/lib/lightbox.js
index 55faa80d8ba..b8c567d59d8 100644
--- a/frontend/discourse/app/lib/lightbox.js
+++ b/frontend/discourse/app/lib/lightbox.js
@@ -55,19 +55,36 @@ export default async function lightbox(elem, siteSettings) {
errorMsg: i18n("lightbox.error"),
showHideAnimationType: isTestEnv ? "none" : "zoom",
counter: false,
+ escKey: false,
tapAction,
paddingFn,
pswpModule: async () => await import("photoswipe"),
appendToEl: isTesting() && document.getElementById("ember-testing"),
});
+ const keyDownHandler = function (event) {
+ if (event.key !== "Escape") {
+ return;
+ }
+
+ event.stopPropagation();
+ event.preventDefault();
+
+ lightboxEl.pswp.close();
+ };
+
lightboxEl.on("afterInit", () => {
const el = lightboxEl.pswp.currSlide.data.element;
el.querySelector(".meta")?.classList.add("open");
+
+ lightboxEl.pswp.element.addEventListener("keydown", (event) =>
+ keyDownHandler(event)
+ );
});
lightboxEl.on("close", function () {
lightboxEl.pswp.element.classList.add("pswp--behind-header");
+ lightboxEl.pswp.element.removeEventListener("keydown", keyDownHandler);
});
lightboxEl.on("destroy", () => {
diff --git a/plugins/chat/spec/system/shortcuts/drawer_spec.rb b/plugins/chat/spec/system/shortcuts/drawer_spec.rb
index c9db3aedfbf..75b8806b8ad 100644
--- a/plugins/chat/spec/system/shortcuts/drawer_spec.rb
+++ b/plugins/chat/spec/system/shortcuts/drawer_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe "Shortcuts | drawer", type: :system do
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
+ let(:lightbox) { PageObjects::Components::PhotoSwipe.new }
before do
chat_system_bootstrap(user_1, [channel_1, channel_2])
@@ -57,6 +58,29 @@ RSpec.describe "Shortcuts | drawer", type: :system do
expect(chat_page).to have_drawer
end
end
+
+ context "when lightbox is open" do
+ fab!(:upload)
+ fab!(:message) do
+ Fabricate(:chat_message, chat_channel: channel_1, upload_ids: [upload.id])
+ end
+
+ before { SiteSetting.experimental_lightbox = true }
+
+ it "does not close the drawer" do
+ expect(chat_page).to have_drawer
+
+ drawer_page.open_channel(channel_1)
+ find(".chat-img-upload").click
+
+ expect(lightbox).to be_visible
+
+ page.send_keys(:escape)
+
+ expect(lightbox).to be_hidden
+ expect(chat_page).to have_drawer
+ end
+ end
end
context "when pressing a letter" do