Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Avoid duplicate search control tooltips https://github.com/siyuan-note/siyuan/issues/20338

Daniel8dd64f858a13
diff --git a/app/src/search/methodCapabilities.test.ts b/app/src/search/methodCapabilities.test.ts
index d5fe4d8e71..411438ae5f 100644
--- a/app/src/search/methodCapabilities.test.ts
+++ b/app/src/search/methodCapabilities.test.ts
@@ -31,7 +31,11 @@ const control = () => {
attributes, classes,
toggleAttribute: (name: string, force: boolean) => { if (force) { attributes[name] = ""; } else { delete attributes[name]; } },
setAttribute: (name: string, value: string) => { attributes[name] = value; },
- classList: {toggle: (name: string, force: boolean) => { if (force) { classes.add(name); } else { classes.delete(name); } }},
+ removeAttribute: (name: string) => { delete attributes[name]; },
+ classList: {
+ add: (name: string) => { classes.add(name); },
+ toggle: (name: string, force: boolean) => { if (force) { classes.add(name); } else { classes.delete(name); } },
+ },
};
};
@@ -52,7 +56,11 @@ for (const mobile of [true, false]) {
querySelector: (selector: string) => {
if (selector === ".toolbar") { return row; }
if (selector === "#searchExpand") { return expand; }
- if (!controls.has(selector)) { controls.set(selector, control()); }
+ if (!controls.has(selector)) {
+ const item = control();
+ item.attributes.title = "native tooltip";
+ controls.set(selector, item);
+ }
return controls.get(selector);
},
querySelectorAll: () => [control(), row],
@@ -68,7 +76,9 @@ for (const mobile of [true, false]) {
assert.equal(row.classes.has("fn__none"), true);
assert.equal(controls.get(filter).attributes["aria-disabled"], "true");
assert.equal(controls.get(include).attributes["aria-disabled"], "true");
- assert.ok(controls.get(filter).attributes.title.endsWith("unavailable"));
+ assert.ok(controls.get(filter).attributes["aria-label"].endsWith("unavailable"));
+ assert.ok(Array.from(controls.values()).filter(item => "aria-disabled" in item.attributes)
+ .every(item => item.classes.has("ariaLabel") && !("title" in item.attributes)));
config.method = 4;
refresh();
assert.equal(row.classes.has("fn__none"), true);
@@ -84,7 +94,9 @@ for (const mobile of [true, false]) {
config.idPath = [];
refresh();
assert.equal(controls.get(include).attributes["aria-disabled"], "true");
- assert.equal(controls.get(filter).attributes.title.includes("unavailable"), false);
+ assert.equal(controls.get(filter).attributes["aria-label"].includes("unavailable"), false);
+ assert.ok(Array.from(controls.values()).filter(item => "aria-disabled" in item.attributes)
+ .every(item => item.classes.has("ariaLabel") && !("title" in item.attributes)));
} finally {
globalThis.window = previousWindow;
globalThis.document = previousDocument;
diff --git a/app/src/search/methodCapabilities.ts b/app/src/search/methodCapabilities.ts
index 754ca999ca..5f5c805adf 100644
--- a/app/src/search/methodCapabilities.ts
+++ b/app/src/search/methodCapabilities.ts
@@ -25,8 +25,9 @@ export const setSearchControlAvailability = (element: Element | null, enabled: b
element.toggleAttribute("disabled", !enabled);
element.setAttribute("aria-disabled", String(!enabled));
const tip = methodUnavailable ? `${label} - ${window.siyuan.languages.searchControlUnavailable}` : label;
+ element.classList.add("ariaLabel");
element.setAttribute("aria-label", tip);
- element.setAttribute("title", tip);
+ element.removeAttribute("title");
};
export const updateSearchMethodControls = (element: Element, config: Config.IUILayoutTabSearchConfig,