Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8816 chore(eslint): fail lint on icon-only native buttons without an accessible name (#10172)

Jiayuan Zhang0465fef013e3
diff --git a/apps/desktop/src/renderer/src/components/update-notification.tsx b/apps/desktop/src/renderer/src/components/update-notification.tsx
index f6ee1ece4e..e99884f6e3 100644
--- a/apps/desktop/src/renderer/src/components/update-notification.tsx
+++ b/apps/desktop/src/renderer/src/components/update-notification.tsx
@@ -33,6 +33,7 @@ export function UpdateNotification() {
type="button"
onClick={() => setDismissed(true)}
className="absolute top-2 right-2 rounded-md p-1 text-muted-foreground hover:text-foreground transition-colors"
+ aria-label="Dismiss"
>
<X className="size-3.5" />
</button>
diff --git a/apps/web/features/landing/components/features-section.tsx b/apps/web/features/landing/components/features-section.tsx
index 1b53e221c1..33da376406 100644
--- a/apps/web/features/landing/components/features-section.tsx
+++ b/apps/web/features/landing/components/features-section.tsx
@@ -559,7 +559,7 @@ function SkillsVisual() {
<div className="w-[200px] shrink-0 border-r flex flex-col">
<div className="flex items-center justify-between border-b px-3 py-2">
<span className="text-caption font-semibold">Skills</span>
- <button type="button" className="rounded-xs p-0.5 text-muted-foreground hover:bg-accent transition-colors">
+ <button type="button" aria-label="New skill" className="rounded-xs p-0.5 text-muted-foreground hover:bg-accent transition-colors">
<Sparkles className="h-3.5 w-3.5" />
</button>
</div>
diff --git a/packages/eslint-config/icon-button-name.js b/packages/eslint-config/icon-button-name.js
index b2ad733d4f..9e2175f59a 100644
--- a/packages/eslint-config/icon-button-name.js
+++ b/packages/eslint-config/icon-button-name.js
@@ -8,11 +8,16 @@
// JSX. When the Button is the `render` element of a trigger, the trigger's own
// props and children reach the button too, so they count as well.
//
+// A native `<button>` has no size to go by, so it is checked only when all of
+// its content is icons imported from @multica/ui/icons, possibly chosen by a
+// conditional. Any other child could render text, so the button is left alone.
+//
// Registered by the shared React config, so every package that extends it
// gets the rule without repeating it.
const NAME_ATTRIBUTES = new Set(["aria-label", "aria-labelledby"]);
const SR_ONLY = /(^|\s)sr-only(\s|$)/;
+const ICONS_MODULE = "@multica/ui/icons";
function attributeName(attr) {
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier"
@@ -98,10 +103,71 @@ function isNamed(element) {
return !!host && (namesItself(host.openingElement) || host.children.some(mayRenderText));
}
+function importedIcons(program) {
+ const names = new Set();
+ const namespaces = new Set();
+ for (const statement of program.body) {
+ if (statement.type !== "ImportDeclaration" || statement.source.value !== ICONS_MODULE) continue;
+ for (const specifier of statement.specifiers) {
+ (specifier.type === "ImportNamespaceSpecifier" ? namespaces : names).add(specifier.local.name);
+ }
+ }
+ return { names, namespaces };
+}
+
+function isIcon(opening, icons) {
+ const { name } = opening;
+ if (name.type === "JSXIdentifier") return icons.names.has(name.name);
+ return (
+ name.type === "JSXMemberExpression" &&
+ name.object.type === "JSXIdentifier" &&
+ icons.namespaces.has(name.object.name)
+ );
+}
+
+// "icon" when the content shows only icons, "empty" when it shows nothing,
+// "other" when it may show anything else.
+function iconContent(nodes, icons) {
+ const kinds = nodes.map((node) => contentKind(node, icons));
+ if (kinds.includes("other")) return "other";
+ return kinds.includes("icon") ? "icon" : "empty";
+}
+
+function contentKind(node, icons) {
+ switch (node.type) {
+ case "JSXText":
+ return /\S/.test(node.value) ? "other" : "empty";
+ case "JSXElement":
+ return isIcon(node.openingElement, icons) ? "icon" : "other";
+ case "JSXFragment":
+ return iconContent(node.children, icons);
+ case "JSXExpressionContainer":
+ return contentKind(node.expression, icons);
+ case "JSXEmptyExpression":
+ return "empty";
+ case "ConditionalExpression":
+ return iconContent([node.consequent, node.alternate], icons);
+ case "LogicalExpression":
+ return iconContent(node.operator === "&&" ? [node.right] : [node.left, node.right], icons);
+ case "Literal":
+ return node.value === null || typeof node.value === "boolean" || node.value === "" ? "empty" : "other";
+ case "Identifier":
+ return node.name === "undefined" ? "empty" : "other";
+ default:
+ return "other";
+ }
+}
+
+function isIconOnlyNativeButton(element, icons) {
+ const host = renderHost(element);
+ const content = host ? [...element.children, ...host.children] : element.children;
+ return iconContent(content, icons) === "icon";
+}
+
const iconButtonName = {
meta: {
type: "problem",
- docs: { description: "Require an accessible name on icon-size Buttons." },
+ docs: { description: "Require an accessible name on icon-size Buttons and icon-only native buttons." },
schema: [],
messages: {
unnamed:
@@ -109,11 +175,20 @@ const iconButtonName = {
},
},
create(context) {
+ let icons = { names: new Set(), namespaces: new Set() };
return {
+ Program(program) {
+ icons = importedIcons(program);
+ },
JSXElement(node) {
const opening = node.openingElement;
- if (opening.name.type !== "JSXIdentifier" || opening.name.name !== "Button") return;
- if (!isIconSize(opening) || isNamed(node)) return;
+ if (opening.name.type !== "JSXIdentifier") return;
+ if (opening.name.name === "Button") {
+ if (!isIconSize(opening)) return;
+ } else if (opening.name.name !== "button" || !isIconOnlyNativeButton(node, icons)) {
+ return;
+ }
+ if (isNamed(node)) return;
context.report({ node: opening, messageId: "unnamed" });
},
};
diff --git a/packages/eslint-config/icon-button-name.test.js b/packages/eslint-config/icon-button-name.test.js
index 6dd2396471..4bb6c2aca9 100644
--- a/packages/eslint-config/icon-button-name.test.js
+++ b/packages/eslint-config/icon-button-name.test.js
@@ -58,6 +58,50 @@ const ALLOWED = [
["IconButton", '<IconButton label="Close"><X /></IconButton>'],
];
+const ICONS = 'import { ChevronDown, ChevronUp, X, X as XIcon } from "@multica/ui/icons";\n';
+
+const NATIVE_FLAGGED = [
+ ["icon-only native button", '<button type="button"><X /></button>'],
+ ["aliased icon import", '<button type="button"><XIcon className="size-4" /></button>'],
+ ["namespace icon import", 'import * as Icons from "@multica/ui/icons";\n<button type="button"><Icons.X /></button>'],
+ ["several icons", "<button><ChevronUp /><ChevronDown /></button>"],
+ ["icon chosen by a conditional", "<button>{open ? <ChevronUp /> : <ChevronDown />}</button>"],
+ ["icon behind &&", "<button>{open && <ChevronUp />}</button>"],
+ ["icon inside a fragment", "<button><><X /></></button>"],
+ ["native render-prop trigger with the icon inside", "<TooltipTrigger render={<button><X /></button>} />"],
+ ["native render-prop trigger with the icon as a child", "<TooltipTrigger render={<button />}><X /></TooltipTrigger>"],
+ [
+ "native button with the label only in a tooltip",
+ "<Tooltip><TooltipTrigger render={<button><X /></button>} /><TooltipContent>Close</TooltipContent></Tooltip>",
+ ],
+];
+
+const NATIVE_ALLOWED = [
+ ["native aria-label", '<button aria-label="Close"><X /></button>'],
+ ["native translated aria-label", "<button aria-label={t(($) => $.close)}><X /></button>"],
+ ["native aria-labelledby", '<button aria-labelledby="title-id"><X /></button>'],
+ ["native props spread", "<button {...props}><X /></button>"],
+ ["native icon and text", "<button><X /> Close</button>"],
+ ["native icon and expression", "<button><X />{label}</button>"],
+ ["native sr-only child", '<button><X /><span className="sr-only">Close</span></button>'],
+ ["native child component that may render text", "<button><X /><Label /></button>"],
+ ["native icon or text", "<button>{busy ? <X /> : label}</button>"],
+ ["icon not from @multica/ui/icons", 'import { X } from "./x";\n<button><X /></button>'],
+ ["empty native button", "<button />"],
+ ["native named render-prop trigger", '<TooltipTrigger aria-label="Close" render={<button />}><X /></TooltipTrigger>'],
+ ["native render-prop trigger with text", "<TooltipTrigger render={<button />}><X /> Close</TooltipTrigger>"],
+];
+
+const withIcons = (code) => (code.startsWith("import") ? code : ICONS + code);
+
+for (const [name, code] of NATIVE_FLAGGED) {
+ test(`flags ${name}`, () => assert.equal(flagged(withIcons(code)), true));
+}
+
+for (const [name, code] of NATIVE_ALLOWED) {
+ test(`allows ${name}`, () => assert.equal(flagged(withIcons(code)), false));
+}
+
for (const [name, code] of FLAGGED) {
test(`flags ${name}`, () => assert.equal(flagged(code), true));
}
diff --git a/packages/ui/markdown/Markdown.tsx b/packages/ui/markdown/Markdown.tsx
index 6c3c1d86f0..b2e65fcf83 100644
--- a/packages/ui/markdown/Markdown.tsx
+++ b/packages/ui/markdown/Markdown.tsx
@@ -125,6 +125,7 @@ function createComponents(
type="button"
className="shrink-0 rounded-md p-1 text-muted-foreground transition-colors hover:bg-secondary hover:text-foreground"
onClick={() => window.open(href, '_blank', 'noopener,noreferrer')}
+ aria-label={filename ? `Download ${filename}` : 'Download'}
>
<Download className="size-3.5" />
</button>
diff --git a/packages/views/autopilots/components/autopilot-dialog.tsx b/packages/views/autopilots/components/autopilot-dialog.tsx
index 9c18ac1a5f..861537f680 100644
--- a/packages/views/autopilots/components/autopilot-dialog.tsx
+++ b/packages/views/autopilots/components/autopilot-dialog.tsx
@@ -520,6 +520,7 @@ export function AutopilotDialog(props: AutopilotDialogProps) {
type="button"
onClick={() => setIsExpanded((v) => !v)}
className="rounded-sm p-1.5 opacity-70 hover:opacity-100 hover:bg-accent/60 transition-all cursor-pointer"
+ aria-label={isExpanded ? t(($) => $.dialog.collapse) : t(($) => $.dialog.expand)}
>
{isExpanded ? <Minimize2 className="size-4" /> : <Maximize2 className="size-4" />}
</button>
@@ -536,6 +537,7 @@ export function AutopilotDialog(props: AutopilotDialogProps) {
type="button"
onClick={() => onOpenChange(false)}
className="rounded-sm p-1.5 opacity-70 hover:opacity-100 hover:bg-accent/60 transition-all cursor-pointer"
+ aria-label={t(($) => $.dialog.close)}
>
<XIcon className="size-4" />
</button>
diff --git a/packages/views/locales/en/modals.json b/packages/views/locales/en/modals.json
index 770a2a3177..8d87e0c60e 100644
--- a/packages/views/locales/en/modals.json
+++ b/packages/views/locales/en/modals.json
@@ -156,7 +156,8 @@
"local_pick_failed": "Could not open the directory picker.",
"local_invalid_dir": "This directory can't be used. Pick another.",
"local_hint": "Agents on other machines won't see this path — they'll fail to start. Use repos for shared work.",
- "repos_ref_default": "Default branch"
+ "repos_ref_default": "Default branch",
+ "repos_remove_aria": "Remove {{repo}}"
},
"create_issue": {
"sr_manual": "New Issue",
diff --git a/packages/views/locales/es/modals.json b/packages/views/locales/es/modals.json
index 0a918f7fa8..64233128fd 100644
--- a/packages/views/locales/es/modals.json
+++ b/packages/views/locales/es/modals.json
@@ -140,7 +140,8 @@
"local_pick_failed": "No se ha podido abrir el selector de directorios.",
"local_invalid_dir": "Este directorio no se puede usar. Elige otro.",
"local_hint": "Los agentes en otras máquinas no verán esta ruta: fallarán al arrancar. Usa repos para trabajo compartido.",
- "repos_ref_default": "Rama por defecto"
+ "repos_ref_default": "Rama por defecto",
+ "repos_remove_aria": "Quitar {{repo}}"
},
"create_issue": {
"sr_manual": "Nueva tarea",
diff --git a/packages/views/locales/fr/modals.json b/packages/views/locales/fr/modals.json
index c3e605cb97..c7b1d5a36e 100644
--- a/packages/views/locales/fr/modals.json
+++ b/packages/views/locales/fr/modals.json
@@ -156,7 +156,8 @@
"local_pick_failed": "Impossible d'ouvrir le sélecteur de répertoire.",
"local_invalid_dir": "Ce répertoire ne peut pas être utilisé. Choisissez-en un autre.",
"local_hint": "Les agents des autres machines ne verront pas ce chemin — ils ne pourront pas démarrer. Utilisez des dépôts pour le travail partagé.",
- "repos_ref_default": "Branche par défaut"
+ "repos_ref_default": "Branche par défaut",
+ "repos_remove_aria": "Retirer {{repo}}"
},
"create_issue": {
"sr_manual": "Nouvelle tâche",
diff --git a/packages/views/locales/ja/modals.json b/packages/views/locales/ja/modals.json
index f70648c392..da83017020 100644
--- a/packages/views/locales/ja/modals.json
+++ b/packages/views/locales/ja/modals.json
@@ -154,7 +154,8 @@
"local_pick_failed": "ディレクトリ選択画面を開けませんでした。",
"local_invalid_dir": "このディレクトリは使用できません。別のものを選択してください。",
"local_hint": "他のマシンのエージェントはこのパスを参照できず、起動に失敗します。共有作業にはリポジトリを使用してください。",
- "repos_ref_default": "デフォルトブランチ"
+ "repos_ref_default": "デフォルトブランチ",
+ "repos_remove_aria": "{{repo}} を削除"
},
"create_issue": {
"sr_manual": "新規タスク",
diff --git a/packages/views/locales/ko/modals.json b/packages/views/locales/ko/modals.json
index a56bd87e19..780d215b2e 100644
--- a/packages/views/locales/ko/modals.json
+++ b/packages/views/locales/ko/modals.json
@@ -154,7 +154,8 @@
"local_pick_failed": "디렉터리 선택 창을 열 수 없습니다.",
"local_invalid_dir": "이 디렉터리는 사용할 수 없습니다. 다른 디렉터리를 선택하세요.",
"local_hint": "다른 기기의 에이전트는 이 경로를 볼 수 없어 시작에 실패합니다. 공유 작업에는 저장소를 사용하세요.",
- "repos_ref_default": "기본 브랜치"
+ "repos_ref_default": "기본 브랜치",
+ "repos_remove_aria": "{{repo}} 제거"
},
"create_issue": {
"sr_manual": "새 태스크",
diff --git a/packages/views/locales/ru/modals.json b/packages/views/locales/ru/modals.json
index cad4505e66..3fa42ba650 100644
--- a/packages/views/locales/ru/modals.json
+++ b/packages/views/locales/ru/modals.json
@@ -153,6 +153,7 @@
"local_invalid_dir": "Эта директория не может быть использована. Выберите другую.",
"local_hint": "Агенты на других устройствах не увидят этот путь — они не смогут запуститься. Используйте репозитории для совместной работы.",
"repos_ref_default": "Ветка по умолчанию",
+ "repos_remove_aria": "Удалить {{repo}}",
"repos_pill_count_few": "{{count}} репозитория",
"repos_pill_count_many": "{{count}} репозиториев"
},
diff --git a/packages/views/locales/zh-Hans/modals.json b/packages/views/locales/zh-Hans/modals.json
index dfcc7d0544..cb39d79215 100644
--- a/packages/views/locales/zh-Hans/modals.json
+++ b/packages/views/locales/zh-Hans/modals.json
@@ -154,7 +154,8 @@
"local_pick_failed": "无法打开目录选择器。",
"local_invalid_dir": "该目录不可用,请重新选择。",
"local_hint": "其他机器上的智能体看不到这个路径,会启动失败。需要协作请用仓库模式。",
- "repos_ref_default": "默认分支"
+ "repos_ref_default": "默认分支",
+ "repos_remove_aria": "移除 {{repo}}"
},
"create_issue": {
"sr_manual": "新建任务",
diff --git a/packages/views/locales/zh-Hant/modals.json b/packages/views/locales/zh-Hant/modals.json
index 4ba4392ab2..c7e48b1505 100644
--- a/packages/views/locales/zh-Hant/modals.json
+++ b/packages/views/locales/zh-Hant/modals.json
@@ -154,7 +154,8 @@
"local_pick_failed": "無法開啟目錄選擇器。",
"local_invalid_dir": "該目錄不可用,請重新選擇。",
"local_hint": "其他機器上的 AI 代理看不到這個路徑,會啟動失敗。需要協作請用倉庫模式。",
- "repos_ref_default": "預設分支"
+ "repos_ref_default": "預設分支",
+ "repos_remove_aria": "移除 {{repo}}"
},
"create_issue": {
"sr_manual": "新建任務",
diff --git a/packages/views/modals/create-project.tsx b/packages/views/modals/create-project.tsx
index fdd791a110..7fbd1e0797 100644
--- a/packages/views/modals/create-project.tsx
+++ b/packages/views/modals/create-project.tsx
@@ -498,6 +498,11 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {
type="button"
onClick={() => setIsExpanded(!isExpanded)}
className="rounded-sm p-1.5 opacity-70 hover:opacity-100 hover:bg-accent/60 transition-all cursor-pointer"
+ aria-label={
+ isExpanded
+ ? t(($) => $.common.collapse_tooltip)
+ : t(($) => $.common.expand_tooltip)
+ }
>
{isExpanded ? <Minimize2 className="size-4" /> : <Maximize2 className="size-4" />}
</button>
@@ -516,6 +521,7 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {
type="button"
onClick={onClose}
className="rounded-sm p-1.5 opacity-70 hover:opacity-100 hover:bg-accent/60 transition-all cursor-pointer"
+ aria-label={t(($) => $.common.close)}
>
<XIcon className="size-4" />
</button>
@@ -936,6 +942,9 @@ export function CreateProjectModal({ onClose }: { onClose: () => void }) {
if (editingRefFor === url) setEditingRefFor(null);
}}
className="shrink-0 text-muted-foreground hover:text-foreground"
+ aria-label={t(($) => $.create_project.repos_remove_aria, {
+ repo: githubShortLabel(url),
+ })}
>
<XIcon className="size-3" />
</button>