You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2025/08/15 11:27:35 UTC

(myfaces-tobago) branch main updated: fix(popup): modal

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/main by this push:
     new fb5cd82cc3 fix(popup): modal
fb5cd82cc3 is described below

commit fb5cd82cc36bb76c3d8cdd19e58a9e9735cfdaa6
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Aug 15 11:07:11 2025 +0200

    fix(popup): modal
    
    ESC button is now disabled on modal=true.
    Add test.
    
    Issue: TOBAGO-2434
---
 .../internal/renderkit/renderer/PopupRenderer.java |  1 +
 .../2400-popup/Popup_staticBackdrop.test.js        | 67 ++++++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PopupRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PopupRenderer.java
index 84122d41bd..4d56312f46 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PopupRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/PopupRenderer.java
@@ -52,6 +52,7 @@ public void encodeBeginInternal(final FacesContext facesContext, final T compone
 
     if (modal) {
       ComponentUtils.putDataAttribute(component, "bs-backdrop", "static");
+      ComponentUtils.putDataAttribute(component, "bs-keyboard", "false");
     }
 
     writer.startElement(HtmlElements.TOBAGO_POPUP);
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2400-popup/Popup_staticBackdrop.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2400-popup/Popup_staticBackdrop.test.js
index c8e9be695c..684558f6b2 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2400-popup/Popup_staticBackdrop.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/2400-popup/Popup_staticBackdrop.test.js
@@ -53,6 +53,41 @@ it("Open 'modal=false'-Popup, close it, press 'Submit'", function (done) {
   test.start();
 });
 
+it("Open 'modal=false'-Popup, close it via ESC, press 'Submit'", function (done) {
+  const timestampOutput = querySelectorFn("#page\\:mainForm\\:timestamp .form-control-plaintext");
+  const openButton = elementByIdFn("page:mainForm:showModalFalse");
+  const submit = elementByIdFn("page:mainForm:submit");
+  const wrapper = elementByIdFn("page:mainForm:popupWrapper");
+  const popup = elementByIdFn("page:mainForm:modalFalse");
+  const collapse = elementByIdFn("page:mainForm:modalFalse::collapse");
+
+  let timestamp;
+  let shownEventCount = 0;
+  let hiddenEventCount = 0;
+  wrapper().addEventListener("shown.bs.modal", () => shownEventCount++);
+  wrapper().addEventListener("hidden.bs.modal", () => hiddenEventCount++);
+
+  const test = new JasmineTestTool(done);
+  test.do(() => expect(popup().classList).not.toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("true"));
+
+  test.event("click", openButton, () => shownEventCount === 1);
+  test.do(() => expect(popup().classList).toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("false"));
+
+  test.do(() => popup().dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true})));
+  test.wait(() => hiddenEventCount === 1);
+  test.do(() => expect(popup().classList).not.toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("true"));
+
+  test.do(() => timestamp = Number(timestampOutput().textContent));
+  test.event("click", submit, () => Number(timestampOutput().textContent) > timestamp);
+  test.do(() => expect(popup().classList).not.toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("true"));
+
+  test.start();
+});
+
 it("Open 'modal=true'-Popup, close it, press 'Submit'", function (done) {
   const body = querySelectorFn("body");
   const timestampOutput = querySelectorFn("#page\\:mainForm\\:timestamp .form-control-plaintext");
@@ -87,6 +122,38 @@ it("Open 'modal=true'-Popup, close it, press 'Submit'", function (done) {
   test.start();
 });
 
+it("Open 'modal=true'-Popup, try to close it via ESC", function (done) {
+  const body = querySelectorFn("body");
+  const openButton = elementByIdFn("page:mainForm:showModalTrue");
+  const wrapper = elementByIdFn("page:mainForm:popupWrapper");
+  const popup = elementByIdFn("page:mainForm:modalTrue");
+  const collapse = elementByIdFn("page:mainForm:modalTrue::collapse");
+  const closeButton = elementByIdFn("page:mainForm:modalTrue:hideModalTrue");
+
+  let shownEventCount = 0;
+  wrapper().addEventListener("shown.bs.modal", () => shownEventCount++);
+
+  const test = new JasmineTestTool(done);
+  test.do(() => expect(popup().classList).not.toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("true"));
+
+  test.event("click", openButton, () => shownEventCount === 1);
+  test.do(() => expect(popup().classList).toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("false"));
+
+  test.do(() => popup().dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true})));
+  test.waitMs(1000);
+  test.do(() => expect(popup().classList).toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("false"));
+
+  //finally close via close button
+  test.event("click", closeButton, () => !body().classList.contains("modal-open"));
+  test.do(() => expect(popup().classList).not.toContain("show"));
+  test.do(() => expect(collapse().getAttribute("value")).toBe("true"));
+
+  test.start();
+});
+
 it("Open Popup 3, close it, press 'Submit'", function (done) {
   const timestampOutput = querySelectorFn("#page\\:mainForm\\:timestamp .form-control-plaintext");
   const openButton = elementByIdFn("page:mainForm:showPopup3");