Skip to content

Agent Zero AI framework

Suppress tooltips on devices without hover support

Alessandro35376ac053e8
diff --git a/tests/test_webui_tooltips.py b/tests/test_webui_tooltips.py
new file mode 100644
index 000000000..b83636e16
--- /dev/null
+++ b/tests/test_webui_tooltips.py
@@ -0,0 +1,75 @@
+"""Touch taps must activate controls without leaving Bootstrap tooltips open."""
+
+import mimetypes
+from pathlib import Path
+from urllib.parse import urlparse
+
+import pytest
+
+
+playwright = pytest.importorskip("playwright.sync_api")
+WEBUI = Path(__file__).resolve().parents[1] / "webui"
+
+
+def test_touch_taps_suppress_tooltips_and_mouse_hover_still_works():
+ html = """<!doctype html><html><head>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <script src="/vendor/bootstrap/bootstrap.bundle.min.js"></script>
+ </head><body>
+ <button title="Helpful description" onclick="window.clicks++">Action</button>
+ <script>window.clicks = 0;</script>
+ </body></html>"""
+
+ def serve(route):
+ path = urlparse(route.request.url).path
+ if path == "/":
+ route.fulfill(content_type="text/html", body=html)
+ else:
+ asset = WEBUI / path.lstrip("/")
+ if asset.is_file():
+ route.fulfill(path=asset, content_type=mimetypes.guess_type(asset)[0])
+ else:
+ route.abort()
+
+ with playwright.sync_playwright() as p:
+ try:
+ browser = p.chromium.launch()
+ except playwright.Error as error:
+ if "Executable doesn't exist" in str(error):
+ pytest.skip("Install a Playwright Chromium browser to run DOM regressions.")
+ raise
+ try:
+ for touch in (True, False):
+ context = browser.new_context(
+ viewport={"width": 390, "height": 844},
+ is_mobile=touch, has_touch=touch,
+ )
+ page = context.new_page()
+ page.route("**/*", serve)
+ page.goto("http://tooltips.test/")
+ page.evaluate("""async () => {
+ window.tooltips = (await import('/components/tooltips/tooltip-store.js')).store;
+ tooltips.init();
+ }""")
+ button = page.get_by_role("button", name="Action")
+ if touch:
+ button.tap()
+ assert page.evaluate("window.clicks") == 1
+ playwright.expect(page.locator(".tooltip")).to_have_count(0)
+ # Also covers a delayed or programmatic show after the tap.
+ button.evaluate("el => bootstrap.Tooltip.getInstance(el).show()")
+ playwright.expect(page.locator(".tooltip")).to_have_count(0)
+ assert button.get_attribute("title") is None
+ assert button.get_attribute("aria-describedby") is None
+ else:
+ button.hover()
+ playwright.expect(page.locator(".tooltip.show")).to_have_count(1)
+ page.mouse.move(300, 400)
+ playwright.expect(page.locator(".tooltip")).to_have_count(0)
+ button.focus()
+ page.keyboard.press("Enter")
+ assert page.evaluate("window.clicks") == 1
+ page.evaluate("tooltips.cleanup()")
+ context.close()
+ finally:
+ browser.close()
diff --git a/webui/components/tooltips/AGENTS.md b/webui/components/tooltips/AGENTS.md
index 735400002..467e19d7e 100644
--- a/webui/components/tooltips/AGENTS.md
+++ b/webui/components/tooltips/AGENTS.md
@@ -12,6 +12,7 @@
- Keep tooltip positioning compatible with desktop and mobile layouts.
- Do not make tooltips required for completing a workflow.
+- Cancel Bootstrap tooltip opening when the device reports no hover support; touch-generated hover events must not open a tooltip or interfere with the control's click action. Keep title normalization active to avoid native tooltip fallbacks.
- Finish pending tooltip fade callbacks before disposing detached controls, including rows moved between sidebar sections.
- Tooltip content wraps, including long unbroken strings such as file paths (`overflow-wrap: anywhere` on `.tooltip` in `webui/index.css`, inherited by `.tooltip-inner`); keep that rule when restyling.
diff --git a/webui/components/tooltips/tooltip-store.js b/webui/components/tooltips/tooltip-store.js
index 39b4de75c..58fb57cc5 100644
--- a/webui/components/tooltips/tooltip-store.js
+++ b/webui/components/tooltips/tooltip-store.js
@@ -2,6 +2,10 @@ import { createStore } from "/js/AlpineStore.js";
let bootstrapTooltipObserver = null;
+function preventTouchTooltip(event) {
+ if (window.matchMedia("(hover: none)").matches) event.preventDefault();
+}
+
function ensureBootstrapTooltip(element) {
if (!element || !(element instanceof Element)) return;
@@ -122,6 +126,7 @@ function observeBootstrapTooltips() {
}
function cleanupTooltipObserver() {
+ document.removeEventListener("show.bs.tooltip", preventTouchTooltip);
if (bootstrapTooltipObserver) {
bootstrapTooltipObserver.disconnect();
bootstrapTooltipObserver = null;
@@ -130,6 +135,7 @@ function cleanupTooltipObserver() {
export const store = createStore("tooltips", {
init() {
+ document.addEventListener("show.bs.tooltip", preventTouchTooltip);
initBootstrapTooltips();
observeBootstrapTooltips();
},