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 2026/03/26 20:32:15 UTC

(myfaces-tobago) branch main updated: fix(suggest): Safari

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 9198f8a873 fix(suggest): Safari
9198f8a873 is described below

commit 9198f8a873ed70791cb01ca07238088d611d4daa
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Mar 26 20:34:44 2026 +0100

    fix(suggest): Safari
    
    * fix Safari
    * add tests
    
    Issue: TOBAGO-2494
---
 .../content/900-test/in/suggest/Suggest.xhtml      |   7 ++
 .../src/test/typescript/suggest.test.ts            | 127 +++++++++++++++++++++
 .../src/main/ts/tobago-suggest.ts                  |  10 +-
 3 files changed, 141 insertions(+), 3 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/in/suggest/Suggest.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/in/suggest/Suggest.xhtml
index 03d3decd55..b72166b9a0 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/in/suggest/Suggest.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/in/suggest/Suggest.xhtml
@@ -19,5 +19,12 @@
 
 <ui:composition template="/main.xhtml"
                 xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
                 xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
+
+  <tc:in id="inputField">
+    <tc:suggest id="suggest" totalCount="10" query="#{suggestController.query}">
+      <tc:selectItems value="#{suggestController.solarObjects}" var="name" itemValue="#{name}"/>
+    </tc:suggest>
+  </tc:in>
 </ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/test/typescript/suggest.test.ts b/tobago-example/tobago-example-demo/src/test/typescript/suggest.test.ts
index d0e0b4e588..2fd33d2145 100644
--- a/tobago-example/tobago-example-demo/src/test/typescript/suggest.test.ts
+++ b/tobago-example/tobago-example-demo/src/test/typescript/suggest.test.ts
@@ -19,6 +19,133 @@
 
 import {expect, test} from "@playwright/test";
 
+test.describe("900-test/in/suggest/Suggest.xhtml", () => {
+
+  test.beforeEach(async ({page}, testInfo) => {
+    await page.goto("/content/900-test/in/suggest/Suggest.xhtml");
+  });
+
+  test("Open suggest list, Escape", async ({page}) => {
+    const inputField = page.locator("input[id='page:mainForm:inputField::field']");
+    const suggestDropdownMenu = page.locator(".tobago-dropdown-menu[name='page:mainForm:suggest']");
+    const firstSuggest = suggestDropdownMenu.locator("li[data-result-index='0']");
+
+    await inputField.click();
+    await expect(inputField).toBeFocused();
+    await page.keyboard.press("S");
+    await expect(firstSuggest).toBeVisible();
+    await page.keyboard.press("Escape");
+    await expect(firstSuggest).not.toBeVisible();
+  });
+
+  test("Open suggest list, click on 'Sun'", async ({page}) => {
+    const inputField = page.locator("input[id='page:mainForm:inputField::field']");
+    const suggestDropdownMenu = page.locator(".tobago-dropdown-menu[name='page:mainForm:suggest']");
+    const firstSuggest = suggestDropdownMenu.locator("li[data-result-index='0']");
+    const firstSuggestButton = firstSuggest.locator("button");
+
+    await inputField.click();
+    await expect(inputField).toBeFocused();
+    await page.keyboard.press("S");
+    await expect(firstSuggest).toBeVisible();
+    await firstSuggestButton.click();
+    await expect(firstSuggest).not.toBeVisible();
+    await expect(inputField).toHaveValue("Sun");
+  });
+
+  test("Open suggest list with 'ma', ArrowDowns/Tabs, Enter", async ({page}) => {
+    const inputField = page.locator("input[id='page:mainForm:inputField::field']");
+    const suggestDropdownMenu = page.locator(".tobago-dropdown-menu[name='page:mainForm:suggest']");
+    const mars = suggestDropdownMenu.locator("li[data-result-index='0']");
+    const amalthea = suggestDropdownMenu.locator("li[data-result-index='1']");
+    const himalia = suggestDropdownMenu.locator("li[data-result-index='2']");
+    const mimas = suggestDropdownMenu.locator("li[data-result-index='3']");
+
+    await inputField.click();
+    await expect(inputField).toBeFocused();
+    await page.keyboard.press("m");
+    await page.keyboard.press("a");
+    await expect(mars).toBeVisible();
+    await expect(amalthea).toBeVisible();
+    await expect(himalia).toBeVisible();
+    await expect(mimas).toBeVisible();
+    await page.keyboard.press("ArrowDown");
+    await expect(mars.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowDown");
+    await expect(amalthea.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowDown");
+    await expect(himalia.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowDown");
+    await expect(mimas.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowDown");
+    await expect(mars.locator("button")).toBeFocused();
+    await page.keyboard.press("Tab");
+    await expect(amalthea.locator("button")).toBeFocused();
+    await page.keyboard.press("Tab");
+    await expect(himalia.locator("button")).toBeFocused();
+    await page.keyboard.press("Tab");
+    await expect(mimas.locator("button")).toBeFocused();
+    await page.keyboard.press("Tab");
+    await expect(mars.locator("button")).toBeFocused();
+    await page.keyboard.press("Enter");
+    await expect(mars).not.toBeVisible();
+    await expect(amalthea).not.toBeVisible();
+    await expect(himalia).not.toBeVisible();
+    await expect(mimas).not.toBeVisible();
+    await expect(inputField).toHaveValue("Mars");
+  });
+
+  test("Open suggest list with 'ma', ArrowUps/shift-Tabs, Enter", async ({page}) => {
+    const inputField = page.locator("input[id='page:mainForm:inputField::field']");
+    const suggestDropdownMenu = page.locator(".tobago-dropdown-menu[name='page:mainForm:suggest']");
+    const mars = suggestDropdownMenu.locator("li[data-result-index='0']");
+    const amalthea = suggestDropdownMenu.locator("li[data-result-index='1']");
+    const himalia = suggestDropdownMenu.locator("li[data-result-index='2']");
+    const mimas = suggestDropdownMenu.locator("li[data-result-index='3']");
+
+    await inputField.click();
+    await expect(inputField).toBeFocused();
+    await page.keyboard.press("m");
+    await page.keyboard.press("a");
+    await expect(mars).toBeVisible();
+    await expect(amalthea).toBeVisible();
+    await expect(himalia).toBeVisible();
+    await expect(mimas).toBeVisible();
+    await page.keyboard.press("ArrowUp");
+    await expect(mimas.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowUp");
+    await expect(himalia.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowUp");
+    await expect(amalthea.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowUp");
+    await expect(mars.locator("button")).toBeFocused();
+    await page.keyboard.press("ArrowUp");
+    await expect(mimas.locator("button")).toBeFocused();
+    await page.keyboard.down("Shift");
+    await page.keyboard.press("Tab");
+    await page.keyboard.up("Shift");
+    await expect(himalia.locator("button")).toBeFocused();
+    await page.keyboard.down("Shift");
+    await page.keyboard.press("Tab");
+    await page.keyboard.up("Shift");
+    await expect(amalthea.locator("button")).toBeFocused();
+    await page.keyboard.down("Shift");
+    await page.keyboard.press("Tab");
+    await page.keyboard.up("Shift");
+    await expect(mars.locator("button")).toBeFocused();
+    await page.keyboard.down("Shift");
+    await page.keyboard.press("Tab");
+    await page.keyboard.up("Shift");
+    await expect(mimas.locator("button")).toBeFocused();
+    await page.keyboard.press("Enter");
+    await expect(mars).not.toBeVisible();
+    await expect(amalthea).not.toBeVisible();
+    await expect(himalia).not.toBeVisible();
+    await expect(mimas).not.toBeVisible();
+    await expect(inputField).toHaveValue("Mimas");
+  });
+});
+
 test.describe("900-test/in/suggest/spinner/Spinner.xhtml", () => {
 
   test.beforeEach(async ({page}, testInfo) => {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
index cedde04e7d..ebb2aaf7b3 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
@@ -42,7 +42,7 @@ export class Suggest {
     this.tobagoSuggest.insertAdjacentHTML("beforebegin", `<div class="${Css.SPINNER}"/>`);
     this.spinner = new Spinner(this.tobagoIn, this.inputField, this.inputField, this.spinnerDiv);
 
-    this.tobagoSuggest.insertAdjacentHTML("beforebegin", `<div class="${Css.TOBAGO_DROPDOWN_MENU_ANCHOR}"}">
+    this.tobagoSuggest.insertAdjacentHTML("beforebegin", `<div class="${Css.TOBAGO_DROPDOWN_MENU_ANCHOR}">
     <ul id="${this.tobagoSuggest.id + "::dropdownMenu"}" class="${Css.TOBAGO_DROPDOWN_MENU}"
     name="${this.tobagoSuggest.id}" role="listbox"/></div>`);
     this.dropdownMenu = new DropdownMenu(this.dropdownMenuElement, this.inputField, this.tobagoIn, this.localMenu,
@@ -85,8 +85,12 @@ export class Suggest {
 
   private blurEvent(event: FocusEvent): void {
     const element = (event.relatedTarget as Element);
-    if (!this.isPartOfSuggest(element)) {
-      this.dropdownMenu.hide();
+
+    if (element !== null) {
+      //relatedTarget is the new focused element; null indicate a mouseclick or an inactive browser window
+      if (!this.isPartOfSuggest(element)) {
+        this.dropdownMenu.hide();
+      }
     }
   }