mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-18 16:08:55 +00:00
fix(ui): restore toolbar icon hover feedback (#2990)
Toolbar and tool window icon buttons (IconButton) paint --bg-toolbar-hover across their hit target again, so hovering shows the clickable area. Disabled buttons stay transparent; pressed, selected, focus ring and icon colours are unchanged. The hover colours match the toolbar tokens already used for the pressed state in Islands Light and Dark. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
This commit is contained in:
@@ -28,6 +28,8 @@ Style components with CSS Modules: `Thing.module.css` next to `Thing.tsx`, impor
|
||||
|
||||
Build from the primitives in `src/ui/` before writing your own: `Button`, `BarButton`, `Input`, `Checkbox`, `Select`, `Dialog`, `Popup`, `Menu`, `Tooltip`, `List`, `Tree`, `Tabs`, `Splitter`, `Scrollbar`, `Spinner`, `Kbd`, and `T` for translated text. They already handle focus, keyboard navigation, theming and translation of their labels. Workbench-level pieces (tool windows, status items, overlays) come from [contributions](/en/contribute/architecture/frontend#contributions), not from custom layout.
|
||||
|
||||
Toolbar icon actions use `IconButton`: its full hit target uses `--bg-toolbar-hover` on hover, while pressed and selected states use their corresponding toolbar tokens. Keep semantic icon colours and the keyboard focus ring intact.
|
||||
|
||||
## Accessibility
|
||||
|
||||
- Use real `<button>` and `<input>` elements (or the primitives that render them), never clickable `<div>`s.
|
||||
|
||||
@@ -28,6 +28,8 @@ description: "前端 UI 代码的规则:设计 token、CSS Modules、图标、
|
||||
|
||||
先用 `src/ui/` 里的基础组件,再考虑自己写:`Button`、`BarButton`、`Input`、`Checkbox`、`Select`、`Dialog`、`Popup`、`Menu`、`Tooltip`、`List`、`Tree`、`Tabs`、`Splitter`、`Scrollbar`、`Spinner`、`Kbd`,以及用于翻译文本的 `T`。它们已经处理好焦点、键盘导航、主题和标签翻译。工作台级别的部件(工具窗口、状态栏项、浮层)来自 [contribution](/zh/contribute/architecture/frontend),不要自己写布局。
|
||||
|
||||
工具栏图标操作使用 `IconButton`:悬停时整个点击区域使用 `--bg-toolbar-hover`,按下和选中状态使用对应的工具栏 token。保留图标的语义颜色和键盘焦点环。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 使用真正的 `<button>` 和 `<input>` 元素(或渲染它们的基础组件),不要用可点击的 `<div>`。
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { expect, openFromTree, test } from "./fixtures";
|
||||
|
||||
for (const theme of ["light", "dark"] as const) {
|
||||
test(`${theme}: toolbar icon buttons provide hover feedback without changing their layout or icons`, async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
const gear = page.getByRole("button", { name: "IDE and Project Settings", exact: true });
|
||||
await gear.click();
|
||||
await page.getByRole("menuitem", { name: "Theme", exact: true }).hover();
|
||||
await page
|
||||
.getByRole("menuitemcheckbox", { name: `Islands ${theme === "light" ? "Light" : "Dark"}`, exact: true })
|
||||
.click();
|
||||
await expect(page.locator("html")).toHaveAttribute("data-theme", theme);
|
||||
|
||||
const toolbar = page.locator("header").first();
|
||||
const disabledRun = toolbar.getByRole("button", { name: "Run", exact: true });
|
||||
await expect(disabledRun).toBeDisabled();
|
||||
await disabledRun.hover();
|
||||
await expect(disabledRun).toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
|
||||
|
||||
await openFromTree(page, "App.tsx");
|
||||
await page.locator("[data-run-chooser]").click();
|
||||
await page.getByRole("option", { name: "Current File", exact: true }).click();
|
||||
const project = page.getByRole("region", { name: "Project", exact: true });
|
||||
const buttons = [
|
||||
...["Select Opened File", "Expand All", "Collapse All", "Options", "Hide"].map((name) =>
|
||||
project.getByRole("button", { name, exact: true }),
|
||||
),
|
||||
...[
|
||||
"Run Current File",
|
||||
"Debug Current File",
|
||||
"More Actions",
|
||||
"Search Everywhere",
|
||||
"IDE and Project Settings",
|
||||
].map((name) => toolbar.getByRole("button", { name, exact: true })),
|
||||
];
|
||||
for (const button of buttons) {
|
||||
await page.mouse.move(700, 500);
|
||||
const bounds = await button.boundingBox();
|
||||
const iconColors = await button.locator("svg [fill], svg [stroke]").evaluateAll((nodes) =>
|
||||
nodes.map((node) => {
|
||||
const style = getComputedStyle(node);
|
||||
return { fill: style.fill, stroke: style.stroke };
|
||||
}),
|
||||
);
|
||||
await expect(button).toBeEnabled();
|
||||
// Hover inside the hit target but outside its centred icon.
|
||||
await button.hover({ position: { x: bounds!.width / 2, y: 1 } });
|
||||
await expect(button).not.toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
|
||||
expect(await button.boundingBox()).toEqual(bounds);
|
||||
if (/^(Run|Debug) Current File$/.test((await button.getAttribute("aria-label")) ?? "")) {
|
||||
expect(
|
||||
await button.locator("svg [fill], svg [stroke]").evaluateAll((nodes) =>
|
||||
nodes.map((node) => {
|
||||
const style = getComputedStyle(node);
|
||||
return { fill: style.fill, stroke: style.stroke };
|
||||
}),
|
||||
),
|
||||
).toEqual(iconColors);
|
||||
}
|
||||
await button.focus();
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await page.keyboard.press("Tab");
|
||||
await expect(button).toBeFocused();
|
||||
await expect(button).toHaveCSS("outline-style", "solid");
|
||||
await expect(button).toHaveCSS("outline-width", "2px");
|
||||
}
|
||||
|
||||
const expand = project.getByRole("button", { name: "Expand All", exact: true });
|
||||
await expand.hover();
|
||||
const hover = await expand.evaluate((button) => getComputedStyle(button).backgroundColor);
|
||||
await page.mouse.down();
|
||||
await expect(expand).not.toHaveCSS("background-color", hover);
|
||||
await page.mouse.up();
|
||||
await expect(project.getByRole("treeitem", { name: "src", exact: true })).toHaveAttribute("aria-expanded", "true");
|
||||
await project.getByRole("button", { name: "Collapse All", exact: true }).click();
|
||||
await expect(project.getByRole("treeitem", { name: "src", exact: true })).toHaveAttribute("aria-expanded", "false");
|
||||
|
||||
await project.getByRole("button", { name: "Options", exact: true }).click();
|
||||
await expect(page.getByRole("menu", { name: "Project options", exact: true })).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await toolbar.getByRole("button", { name: "More Actions", exact: true }).click();
|
||||
await expect(page.getByRole("menuitem", { name: /^Edit Configurations…/ })).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await toolbar.getByRole("button", { name: "Search Everywhere", exact: true }).click();
|
||||
await expect(page.getByRole("dialog", { name: "Search Everywhere", exact: true })).toBeVisible();
|
||||
await page.keyboard.press("Escape");
|
||||
await project.getByRole("button", { name: "Hide", exact: true }).click();
|
||||
await expect(project).toBeHidden();
|
||||
});
|
||||
}
|
||||
@@ -72,7 +72,7 @@
|
||||
color: var(--fg-faint);
|
||||
}
|
||||
|
||||
/* Toolbar / action buttons: transparent on hover, filled when pressed or selected. */
|
||||
/* Toolbar / action buttons share the toolbar hover, pressed and selected tokens. */
|
||||
.iconButton {
|
||||
flex: none;
|
||||
display: inline-flex;
|
||||
@@ -89,6 +89,7 @@
|
||||
outline-offset: -2px;
|
||||
}
|
||||
.iconButton:not(:disabled):hover {
|
||||
background: var(--bg-toolbar-hover);
|
||||
color: var(--fg-strong);
|
||||
}
|
||||
.iconButton:not(:disabled):active {
|
||||
|
||||
Reference in New Issue
Block a user