Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): name the inspector's icon controls in the shared tooltip

EtienneLescoted320b273837
diff --git a/src/components/ai-edition/CaptionsPane.tsx b/src/components/ai-edition/CaptionsPane.tsx
index 772a4ca43..ba8710b7d 100644
--- a/src/components/ai-edition/CaptionsPane.tsx
+++ b/src/components/ai-edition/CaptionsPane.tsx
@@ -11,6 +11,7 @@
import { Captions as CaptionsIcon, Languages, Loader2, Trash2, X } from "lucide-react";
import { useMemo, useState } from "react";
+import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
import { useScopedT } from "@/contexts/I18nContext";
import type {
CaptionAnchorH,
@@ -245,17 +246,22 @@ export function CaptionsPane({ onClose }: { onClose?: () => void } = {}) {
<CaptionsIcon size={14} />
</span>
<h2>{t("facets.captions")}</h2>
+ {/* Its own provider, like `Toggle`: the pane renders without the app's root one in the
+ tests. */}
{onClose ? (
- <button
- type="button"
- className={styles.iconBtn}
- style={{ marginLeft: "auto" }}
- title={tc("actions.close")}
- aria-label={tc("actions.close")}
- onClick={onClose}
- >
- <X size={14} />
- </button>
+ <TooltipProvider>
+ <Tooltip content={tc("actions.close")}>
+ <button
+ type="button"
+ className={styles.iconBtn}
+ style={{ marginLeft: "auto" }}
+ aria-label={tc("actions.close")}
+ onClick={onClose}
+ >
+ <X size={14} />
+ </button>
+ </Tooltip>
+ </TooltipProvider>
) : null}
</header>
<div
diff --git a/src/components/ai-edition/ChoiceRow.test.tsx b/src/components/ai-edition/ChoiceRow.test.tsx
index bce82d900..6fdd86145 100644
--- a/src/components/ai-edition/ChoiceRow.test.tsx
+++ b/src/components/ai-edition/ChoiceRow.test.tsx
@@ -3,8 +3,8 @@
// option past them stays reachable from the keyboard.
import "@testing-library/jest-dom";
-import { fireEvent, render, screen } from "@testing-library/react";
-import { describe, expect, it, vi } from "vitest";
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("sonner", () => ({ toast: { error: vi.fn(), success: vi.fn(), info: vi.fn() } }));
@@ -46,9 +46,41 @@ describe("ChoiceRow keyboard", () => {
// A tooltip that says what the button already says is noise (tooltips.md, rule 3). A button with
// no visible label is the one that needs it: it is named for a screen reader and for the mouse.
+// Always the shared `Tooltip`, never the browser's `title`, which looks and waits unlike every
+// other tooltip in the editor (#1016).
describe("ChoiceRow tooltips", () => {
const icon = <svg aria-hidden="true" />;
+ // jsdom has none, and a Radix tooltip measures its trigger when it opens.
+ beforeEach(() => {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe = () => undefined;
+ unobserve = () => undefined;
+ disconnect = () => undefined;
+ },
+ );
+ });
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ /** What a keyboard focus on the option shows, or null when it opens no tooltip. */
+ function tooltipOf(name: string) {
+ const button = screen.getByRole("button", { name });
+ expect(button).not.toHaveAttribute("title");
+ // A keyboard focus: one the mouse gave opens no tooltip.
+ fireEvent.keyDown(window, { key: "Tab" });
+ act(() => button.focus());
+ // Radix copies the text into a visually hidden `role="tooltip"` node, read by assistive
+ // technology: the one copy that holds nothing else.
+ const shown = screen.queryByRole("tooltip")?.textContent ?? null;
+ if (shown !== null) expect(button).toHaveAccessibleDescription(shown);
+ act(() => button.blur());
+ return shown;
+ }
+
it("draws no tooltip on an option whose label is visible", () => {
render(
<ChoiceRow<string>
@@ -61,9 +93,7 @@ describe("ChoiceRow tooltips", () => {
]}
/>,
);
- for (const name of ["Alpha", "Beta"]) {
- expect(screen.getByRole("button", { name })).not.toHaveAttribute("title");
- }
+ for (const name of ["Alpha", "Beta"]) expect(tooltipOf(name)).toBeNull();
});
it("names an icon-only option in its tooltip", () => {
@@ -78,8 +108,8 @@ describe("ChoiceRow tooltips", () => {
]}
/>,
);
- expect(screen.getByRole("button", { name: "Alpha" })).toHaveAttribute("title", "Alpha");
- expect(screen.getByRole("button", { name: "Beta" })).toHaveAttribute("title", "Beta");
+ expect(tooltipOf("Alpha")).toBe("Alpha");
+ expect(tooltipOf("Beta")).toBe("Beta");
});
it("draws no tooltip on an option that shows its icon and its label", () => {
@@ -92,7 +122,7 @@ describe("ChoiceRow tooltips", () => {
options={[{ value: "a", label: "Alpha", icon }]}
/>,
);
- expect(screen.getByRole("button", { name: "Alpha" })).not.toHaveAttribute("title");
+ expect(tooltipOf("Alpha")).toBeNull();
});
it("draws none on an icon that already spells the label, when the caller says so", () => {
@@ -104,7 +134,7 @@ describe("ChoiceRow tooltips", () => {
options={[{ value: "a", label: "Lora", icon: <span>Lora</span>, title: null }]}
/>,
);
- expect(screen.getByRole("button", { name: "Lora" })).not.toHaveAttribute("title");
+ expect(tooltipOf("Lora")).toBeNull();
});
it("keeps the tooltip a caller passes, even beside a visible label", () => {
@@ -119,10 +149,7 @@ describe("ChoiceRow tooltips", () => {
]}
/>,
);
- expect(screen.getByRole("button", { name: "Alpha" })).toHaveAttribute(
- "title",
- "Alpha · 2 clips",
- );
- expect(screen.getByRole("button", { name: "Beta" })).not.toHaveAttribute("title");
+ expect(tooltipOf("Alpha")).toBe("Alpha · 2 clips");
+ expect(tooltipOf("Beta")).toBeNull();
});
});
diff --git a/src/components/ai-edition/ColorField.tsx b/src/components/ai-edition/ColorField.tsx
index 12f433010..4b00e6290 100644
--- a/src/components/ai-edition/ColorField.tsx
+++ b/src/components/ai-edition/ColorField.tsx
@@ -1,6 +1,7 @@
import * as Popover from "@radix-ui/react-popover";
import Colorful from "@uiw/react-color-colorful";
import { useEffect, useState } from "react";
+import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
import { useScopedT } from "@/contexts/I18nContext";
import styles from "./NewEditorShell.module.css";
@@ -168,26 +169,29 @@ export function ColorField({
aria-label={ts("annotation.colorPalette")}
style={{ display: "grid", gridTemplateColumns: "repeat(8, 1fr)", gap: 5 }}
>
- {presets.map((preset) => (
- <button
- key={preset}
- type="button"
- title={preset}
- aria-label={te("inspector.setColor", { color: preset })}
- aria-pressed={value.toLowerCase() === preset.toLowerCase()}
- onClick={() => pick(preset)}
- style={{
- height: 20,
- borderRadius: 6,
- background: preset,
- border:
- value.toLowerCase() === preset.toLowerCase()
- ? "2px solid var(--accent)"
- : "1px solid var(--border-hi)",
- cursor: "pointer",
- }}
- />
- ))}
+ {/* Its own provider, like `Toggle`: the field is also drawn outside a pane. */}
+ <TooltipProvider>
+ {presets.map((preset) => (
+ <Tooltip key={preset} content={preset}>
+ <button
+ type="button"
+ aria-label={te("inspector.setColor", { color: preset })}
+ aria-pressed={value.toLowerCase() === preset.toLowerCase()}
+ onClick={() => pick(preset)}
+ style={{
+ height: 20,
+ borderRadius: 6,
+ background: preset,
+ border:
+ value.toLowerCase() === preset.toLowerCase()
+ ? "2px solid var(--accent)"
+ : "1px solid var(--border-hi)",
+ cursor: "pointer",
+ }}
+ />
+ </Tooltip>
+ ))}
+ </TooltipProvider>
</div>
</Popover.Content>
</Popover.Portal>
diff --git a/src/components/ai-edition/RightPanes.composition.test.tsx b/src/components/ai-edition/RightPanes.composition.test.tsx
index a5a78473e..ad627d814 100644
--- a/src/components/ai-edition/RightPanes.composition.test.tsx
+++ b/src/components/ai-edition/RightPanes.composition.test.tsx
@@ -3,7 +3,7 @@
// pixel shapes: the Original row and Auto only exist, or only die, under those conditions.
import "@testing-library/jest-dom";
-import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { I18nProvider } from "@/contexts/I18nContext";
import { LOCALE_STORAGE_KEY } from "@/i18n/config";
@@ -79,10 +79,20 @@ function frameSettings() {
beforeEach(() => {
localStorage.clear();
useProjectStore.setState({ document: null });
+ // jsdom has none, and a Radix tooltip measures its trigger when it opens.
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe = () => undefined;
+ unobserve = () => undefined;
+ disconnect = () => undefined;
+ },
+ );
});
afterEach(() => {
cleanup();
localStorage.clear();
+ vi.unstubAllGlobals();
});
describe("the frame row persists the pick", () => {
@@ -179,9 +189,16 @@ describe("the format row", () => {
]),
locale,
);
- const read = ["16:9 · 1920×1080", "9:16 · 1080×1920"].map((name) =>
- screen.getByRole("button", { name }).getAttribute("title"),
- );
+ // The shared tooltip, opened by a keyboard focus: the count is its accessible description.
+ const read = ["16:9 · 1920×1080", "9:16 · 1080×1920"].map((name) => {
+ const button = screen.getByRole("button", { name });
+ fireEvent.keyDown(window, { key: "Tab" });
+ act(() => button.focus());
+ const description = button.getAttribute("aria-describedby");
+ const text = description ? document.getElementById(description)?.textContent : null;
+ act(() => button.blur());
+ return text;
+ });
cleanup();
return read;
};
diff --git a/src/components/ai-edition/RightPanes.tooltips.test.tsx b/src/components/ai-edition/RightPanes.tooltips.test.tsx
index 46795a985..a6ead8120 100644
--- a/src/components/ai-edition/RightPanes.tooltips.test.tsx
+++ b/src/components/ai-edition/RightPanes.tooltips.test.tsx
@@ -6,7 +6,7 @@
// label, where a keyboard or screen-reader user cannot reach it (rule 10).
import "@testing-library/jest-dom";
-import { act, cleanup, render, screen } from "@testing-library/react";
+import { act, cleanup, render, screen, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { I18nProvider } from "@/contexts/I18nContext";
import { LOCALE_STORAGE_KEY } from "@/i18n/config";
@@ -146,6 +146,38 @@ describe("inspector switch tooltips", () => {
});
});
+// Issue #1016: the camera's preset and position icons, and the frame tiles, named themselves
+// through the browser's `title`, which looks and waits unlike every other tooltip here.
+describe("inspector icon choices", () => {
+ it.each([
+ ["Preset", <LayoutPane key="l" />],
+ ["Position", <LayoutPane key="p" />],
+ ["Style", <VideoEffectsPane key="e" />],
+ ])("%s: each icon names itself in the shared tooltip", (row, pane) => {
+ mount(pane);
+ const buttons = within(screen.getByRole("group", { name: row })).getAllByRole("button");
+ expect(buttons.length).toBeGreaterThan(1);
+
+ for (const button of buttons) {
+ const name = button.getAttribute("aria-label") ?? "";
+ expect(name).not.toBe("");
+ expect(button).not.toHaveAttribute("title");
+ act(() => button.focus());
+ expect(visibleTooltip()).toHaveTextContent(name);
+ expect(button).toHaveAccessibleDescription(name);
+ act(() => button.blur());
+ }
+ });
+
+ it("names the pane's help button in the shared tooltip", () => {
+ mount(<LayoutPane />);
+ const help = screen.getByRole("button", { name: "Help" });
+ expect(help).not.toHaveAttribute("title");
+ act(() => help.focus());
+ expect(help).toHaveAccessibleDescription("Help");
+ });
+});
+
describe("inspector labels", () => {
// Every choice row, tile and label in these panes, with a frame on so the theme row shows.
it.each([
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 4ff04c60f..73c1fcd83 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -174,70 +174,78 @@ function Pane({ title, icon, helpText, actions, onClose, children }: PaneProps)
const tc = useScopedT("common");
const helpLabel = ts("panes.help");
const [helpOpen, setHelpOpen] = useState(false);
+ // Its own provider, like `Toggle`: a pane renders without the app's root one in the tests,
+ // and every icon-only control inside it has a tooltip.
return (
- <div className={`${styles.pane} ${styles.isActive}`}>
- <header
- className={styles.paneHead}
- style={{
- position: "relative",
- ...(onClose ? { paddingRight: "var(--sp-4)" } : {}),
- }}
- >
- {icon ? (
- <span style={{ display: "inline-flex", alignItems: "center", color: "var(--muted)" }}>
- {icon}
- </span>
- ) : null}
- <h2>{title}</h2>
- <span style={{ marginLeft: "auto", display: "inline-flex", gap: 4, alignItems: "center" }}>
- {actions}
- <button
- type="button"
- className={styles.iconBtn}
- title={helpLabel}
- aria-label={helpLabel}
- aria-expanded={helpOpen}
- onClick={() => setHelpOpen((v) => !v)}
+ <TooltipProvider>
+ <div className={`${styles.pane} ${styles.isActive}`}>
+ <header
+ className={styles.paneHead}
+ style={{
+ position: "relative",
+ ...(onClose ? { paddingRight: "var(--sp-4)" } : {}),
+ }}
+ >
+ {icon ? (
+ <span style={{ display: "inline-flex", alignItems: "center", color: "var(--muted)" }}>
+ {icon}
+ </span>
+ ) : null}
+ <h2>{title}</h2>
+ <span
+ style={{ marginLeft: "auto", display: "inline-flex", gap: 4, alignItems: "center" }}
>
- <HelpCircle size={16} />
- </button>
- {onClose ? (
- <button
- type="button"
- className={styles.iconBtn}
- title={tc("actions.close")}
- aria-label={tc("actions.close")}
- onClick={onClose}
+ {actions}
+ <Tooltip content={helpLabel}>
+ <button
+ type="button"
+ className={styles.iconBtn}
+ aria-label={helpLabel}
+ aria-expanded={helpOpen}
+ onClick={() => setHelpOpen((v) => !v)}
+ >
+ <HelpCircle size={16} />
+ </button>
+ </Tooltip>
+ {onClose ? (
+ <Tooltip content={tc("actions.close")}>
+ <button
+ type="button"
+ className={styles.iconBtn}
+ aria-label={tc("actions.close")}
+ onClick={onClose}
+ >
+ <X size={16} />
+ </button>
+ </Tooltip>
+ ) : null}
+ </span>
+ {helpOpen ? (
+ <div
+ role="note"
+ style={{
+ position: "absolute",
+ top: "calc(100% + 4px)",
+ right: 8,
+ zIndex: 60,
+ maxWidth: 240,
+ padding: "10px 12px",
+ background: "var(--surface)",
+ border: "1px solid var(--border)",
+ borderRadius: "var(--r-md)",
+ boxShadow: "var(--elev-pop)",
+ color: "var(--fg-2)",
+ font: "400 12px/1.5 var(--font-body)",
+ }}
+ onClick={() => setHelpOpen(false)}
>
- <X size={16} />
- </button>
+ {helpText}
+ </div>
) : null}
- </span>
- {helpOpen ? (
- <div
- role="note"
- style={{
- position: "absolute",
- top: "calc(100% + 4px)",
- right: 8,
- zIndex: 60,
- maxWidth: 240,
- padding: "10px 12px",
- background: "var(--surface)",
- border: "1px solid var(--border)",
- borderRadius: "var(--r-md)",
- boxShadow: "var(--elev-pop)",
- color: "var(--fg-2)",
- font: "400 12px/1.5 var(--font-body)",
- }}
- onClick={() => setHelpOpen(false)}
- >
- {helpText}
- </div>
- ) : null}
- </header>
- <div className={styles.paneBody}>{children}</div>
- </div>
+ </header>
+ <div className={styles.paneBody}>{children}</div>
+ </div>
+ </TooltipProvider>
);
}
@@ -633,16 +641,17 @@ export function WallpaperPicker({
{tab === "image" ? (
<div className={styles.bgGrid}>
{/* First, so it is found without scrolling past the bundled set. */}
- <button
- type="button"
- className={`${styles.bgThumb} ${styles.bgAdd}`}
- aria-label={ts("background.uploadCustom")}
- title={ts("background.uploadCustom")}
- disabled={!hasDocument}
- onClick={onPickFile}
- >
- <ImagePlus size={15} />
- </button>
+ <Tooltip content={ts("background.uploadCustom")}>
+ <button
+ type="button"
+ className={`${styles.bgThumb} ${styles.bgAdd}`}
+ aria-label={ts("background.uploadCustom")}
+ disabled={!hasDocument}
+ onClick={onPickFile}
+ >
+ <ImagePlus size={15} />
+ </button>
+ </Tooltip>
{customUrls.map((url) => (
<button
type="button"
@@ -1967,42 +1976,43 @@ function WordChipButton({
children: ReactNode;
}) {
return (
- <button
- type="button"
- contentEditable={false}
- title={label}
- aria-label={label}
- onClick={(e) => {
- e.stopPropagation();
- onPress();
- }}
- style={{
- position: "absolute",
- left: "100%",
- top: "50%",
- transform: "translateY(-50%)",
- display: "flex",
- padding: "0 0 0 4px",
- border: 0,
- background: "transparent",
- cursor: "pointer",
- }}
- >
- <span
+ <Tooltip content={label}>
+ <button
+ type="button"
+ contentEditable={false}
+ aria-label={label}
+ onClick={(e) => {
+ e.stopPropagation();
+ onPress();
+ }}
style={{
- display: "inline-flex",
- alignItems: "center",
- justifyContent: "center",
- width: 18,
- height: 18,
- borderRadius: 4,
- background: tone,
- color: "white",
+ position: "absolute",
+ left: "100%",
+ top: "50%",
+ transform: "translateY(-50%)",
+ display: "flex",
+ padding: "0 0 0 4px",
+ border: 0,
+ background: "transparent",
+ cursor: "pointer",
}}
>
- {children}
- </span>
- </button>
+ <span
+ style={{
+ display: "inline-flex",
+ alignItems: "center",
+ justifyContent: "center",
+ width: 18,
+ height: 18,
+ borderRadius: 4,
+ background: tone,
+ color: "white",
+ }}
+ >
+ {children}
+ </span>
+ </button>
+ </Tooltip>
);
}
@@ -3756,23 +3766,23 @@ export function CursorPane() {
{cursorThemeOptions.map((option) => {
const isActive = settings.cursorTheme === option.id;
return (
- <button
- type="button"
- key={option.id}
- className={`${styles.cursorCell} ${isActive ? styles.isActive : ""}`}
- title={option.name}
- aria-label={option.name}
- aria-pressed={isActive}
- disabled={!hasDocument}
- onClick={() => void set({ cursor: { theme: option.id } })}
- >
- <img
- src={option.previewUrl}
- alt=""
- className={styles.cursorSprite}
- draggable={false}
- />
- </button>
+ <Tooltip key={option.id} content={option.name}>
+ <button
+ type="button"
+ className={`${styles.cursorCell} ${isActive ? styles.isActive : ""}`}
+ aria-label={option.name}
+ aria-pressed={isActive}
+ disabled={!hasDocument}
+ onClick={() => void set({ cursor: { theme: option.id } })}
+ >
+ <img
+ src={option.previewUrl}
+ alt=""
+ className={styles.cursorSprite}
+ draggable={false}
+ />
+ </button>
+ </Tooltip>
);
})}
</div>
@@ -3828,31 +3838,34 @@ export function CursorPane() {
const shown = !settings.cursor.asArrow.includes(kind);
const label = cursorKindLabels[kind];
return (
- <button
- type="button"
+ <Tooltip
key={kind}
- className={`${styles.cursorCell} ${shown ? styles.isActive : styles.cursorCellOff}`}
- title={shown ? label : ts("cursor.typeAsArrow", { type: label })}
- aria-label={label}
- aria-pressed={shown}
- disabled={!hasDocument}
- onClick={() =>
- void set({
- cursor: {
- asArrow: CURSOR_KIND_IDS.filter((k) =>
- k === kind ? shown : settings.cursor.asArrow.includes(k),
- ),
- },
- })
- }
+ content={shown ? label : ts("cursor.typeAsArrow", { type: label })}
>
- <img
- src={safeAssetUrl(cursorSprites[type].assetPath)}
- alt=""
- className={styles.cursorSprite}
- draggable={false}
- />
- </button>
+ <button
+ type="button"
+ className={`${styles.cursorCell} ${shown ? styles.isActive : styles.cursorCellOff}`}
+ aria-label={label}
+ aria-pressed={shown}
+ disabled={!hasDocument}
+ onClick={() =>
+ void set({
+ cursor: {
+ asArrow: CURSOR_KIND_IDS.filter((k) =>
+ k === kind ? shown : settings.cursor.asArrow.includes(k),
+ ),
+ },
+ })
+ }
+ >
+ <img
+ src={safeAssetUrl(cursorSprites[type].assetPath)}
+ alt=""
+ className={styles.cursorSprite}
+ draggable={false}
+ />
+ </button>
+ </Tooltip>
);
})}
</div>
@@ -4002,8 +4015,8 @@ export function ChoiceRow<T extends string | number>({
}: {
label: string;
/** `null` leaves a hole in the grid: the middle of the camera's position grid. An option
- * can be `disabled` on its own: a disabled button takes no focus, so its `title` is only a
- * mouse hint, and the reason must also be visible text the row points at (`describedBy`).
+ * can be `disabled` on its own: a disabled button takes no focus and opens no tooltip, so
+ * the reason must be visible text the row points at (`describedBy`).
* `title` is a tooltip that adds to the label (a clip count). An icon-only option gets its
* label as its tooltip; one whose label is visible gets none. `null` is for an icon that
* already spells the label, a font drawn in its own face. */
@@ -4029,77 +4042,87 @@ export function ChoiceRow<T extends string | number>({
}) {
const buttonsRef = useRef<Array<HTMLButtonElement | null>>([]);
const mode = display ?? (options.some((o) => o?.icon) ? "icon" : "text");
+ // Its own provider, like `Toggle`: the row is also drawn outside a pane (the selection
+ // panes, the dialogs), and a Radix tooltip throws without any.
return (
- <div
- role="group"
- aria-label={label}
- aria-describedby={describedBy}
- className={`${styles.choiceRow} ${tiles ? styles.choiceRowTiles : ""}`}
- style={{ gridTemplateColumns: `repeat(${columns ?? options.length}, minmax(0, 1fr))` }}
- onKeyDown={(e) => {
- if (e.key === "Enter" || e.key === " ") {
+ <TooltipProvider>
+ <div
+ role="group"
+ aria-label={label}
+ aria-describedby={describedBy}
+ className={`${styles.choiceRow} ${tiles ? styles.choiceRowTiles : ""}`}
+ style={{ gridTemplateColumns: `repeat(${columns ?? options.length}, minmax(0, 1fr))` }}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" || e.key === " ") {
+ e.nativeEvent.stopPropagation();
+ return;
+ }
+ const step =
+ e.key === "ArrowRight" || e.key === "ArrowDown"
+ ? 1
+ : e.key === "ArrowLeft" || e.key === "ArrowUp"
+ ? -1
+ : 0;
+ if (step === 0) return;
+ e.preventDefault();
e.nativeEvent.stopPropagation();
- return;
- }
- const step =
- e.key === "ArrowRight" || e.key === "ArrowDown"
- ? 1
- : e.key === "ArrowLeft" || e.key === "ArrowUp"
- ? -1
- : 0;
- if (step === 0) return;
- e.preventDefault();
- e.nativeEvent.stopPropagation();
- const focused = buttonsRef.current.findIndex((b) => b === document.activeElement);
- const from = focused >= 0 ? focused : options.findIndex((o) => o?.value === value);
- // Holes and disabled options are stepped over, not landed on.
- let to = from + step;
- while (to >= 0 && to < options.length && (options[to] ?? { disabled: true }).disabled) {
- to += step;
- }
- const next = options[to];
- if (!next) return;
- buttonsRef.current[to]?.focus();
- if (next.value !== value) onChange(next.value);
- }}
- >
- {options.map((option, i) => {
- if (option === null) return <span key={`hole-${i}`} aria-hidden="true" />;
- const pressed = option.value === value;
- // A tooltip only where it tells something the button does not: the name of an
- // icon-only option, or the text a caller passes. A visible label is never repeated
- // (technical-documentation/engineering/tooltips.md, rule 3).
- const tip = option.title === undefined && mode === "icon" ? option.label : option.title;
- return (
- <button
- key={String(option.value)}
- ref={(el) => {
- buttonsRef.current[i] = el;
- }}
- type="button"
- className={`${styles.choiceBtn} ${pressed ? styles.isActive : ""}`}
- aria-pressed={pressed}
- aria-label={mode === "icon" ? option.label : undefined}
- title={tip ?? undefined}
- disabled={disabled || option.disabled}
- // Re-choisir la valeur en place n'est pas une modification : ni sauvegarde ni
- // entrée d'annulation.
- onClick={() => {
- if (!pressed) onChange(option.value);
- }}
- >
- {mode === "text" ? option.label : null}
- {mode === "icon" ? option.icon : null}
- {mode === "both" ? (
- <>
- {option.icon}
- <span className={styles.choiceBtnLabel}>{option.label}</span>
- </>
- ) : null}
- </button>
- );
- })}
- </div>
+ const focused = buttonsRef.current.findIndex((b) => b === document.activeElement);
+ const from = focused >= 0 ? focused : options.findIndex((o) => o?.value === value);
+ // Holes and disabled options are stepped over, not landed on.
+ let to = from + step;
+ while (to >= 0 && to < options.length && (options[to] ?? { disabled: true }).disabled) {
+ to += step;
+ }
+ const next = options[to];
+ if (!next) return;
+ buttonsRef.current[to]?.focus();
+ if (next.value !== value) onChange(next.value);
+ }}
+ >
+ {options.map((option, i) => {
+ if (option === null) return <span key={`hole-${i}`} aria-hidden="true" />;
+ const pressed = option.value === value;
+ // A tooltip only where it tells something the button does not: the name of an
+ // icon-only option, or the text a caller passes. A visible label is never repeated
+ // (technical-documentation/engineering/tooltips.md, rule 3).
+ const tip = option.title === undefined && mode === "icon" ? option.label : option.title;
+ const button = (
+ <button
+ key={String(option.value)}
+ ref={(el) => {
+ buttonsRef.current[i] = el;
+ }}
+ type="button"
+ className={`${styles.choiceBtn} ${pressed ? styles.isActive : ""}`}
+ aria-pressed={pressed}
+ aria-label={mode === "icon" ? option.label : undefined}
+ disabled={disabled || option.disabled}
+ // Re-choisir la valeur en place n'est pas une modification : ni sauvegarde ni
+ // entrée d'annulation.
+ onClick={() => {
+ if (!pressed) onChange(option.value);
+ }}
+ >
+ {mode === "text" ? option.label : null}
+ {mode === "icon" ? option.icon : null}
+ {mode === "both" ? (
+ <>
+ {option.icon}
+ <span className={styles.choiceBtnLabel}>{option.label}</span>
+ </>
+ ) : null}
+ </button>
+ );
+ return tip ? (
+ <Tooltip key={String(option.value)} content={tip}>
+ {button}
+ </Tooltip>
+ ) : (
+ button
+ );
+ })}
+ </div>
+ </TooltipProvider>
);
}
@@ -4208,17 +4231,21 @@ export function SliderCell({
</span>
) : null}
{/* Only once the value has moved: at the default there is nothing to go back to. */}
+ {/* Its own provider, like `Toggle`: the slider is also drawn outside a pane. */}
{modified ? (
- <button
- type="button"
- className={styles.sliderReset}
- aria-label={`${tc("actions.resetToDefault")}: ${label}`}
- title={tc("actions.resetToDefault")}
- disabled={disabled}
- onClick={reset}
- >
- <RotateCcw size={12} aria-hidden="true" />
- </button>
+ <TooltipProvider>
+ <Tooltip content={tc("actions.resetToDefault")}>
+ <button
+ type="button"
+ className={styles.sliderReset}
+ aria-label={`${tc("actions.resetToDefault")}: ${label}`}
+ disabled={disabled}
+ onClick={reset}
+ >
+ <RotateCcw size={12} aria-hidden="true" />
+ </button>
+ </Tooltip>
+ </TooltipProvider>
) : null}
</div>
{/* The visible label is a <span>, not a <label htmlFor>, so without this the
diff --git a/src/components/ai-edition/TextColorField.test.tsx b/src/components/ai-edition/TextColorField.test.tsx
index e9119068c..bfe4f50b5 100644
--- a/src/components/ai-edition/TextColorField.test.tsx
+++ b/src/components/ai-edition/TextColorField.test.tsx
@@ -16,7 +16,8 @@ function renderOn(plate: string, onChange = vi.fn()) {
return onChange;
}
-const swatch = (color: string) => screen.queryByTitle(color);
+// By its name: the hex is its tooltip, drawn only on hover.
+const swatch = (color: string) => screen.queryByRole("button", { name: `Set color ${color}` });
describe("TextColorField", () => {
it("offers only the palette colours that read on a dark plate", () => {
diff --git a/src/components/ai-edition/TextColorField.tsx b/src/components/ai-edition/TextColorField.tsx
index fd326fde1..01da252ce 100644
--- a/src/components/ai-edition/TextColorField.tsx
+++ b/src/components/ai-edition/TextColorField.tsx
@@ -1,3 +1,4 @@
+import { Tooltip, TooltipProvider } from "@/components/ui/tooltip";
import { useScopedT } from "@/contexts/I18nContext";
import { paletteFor, readableText } from "@/lib/ai-edition/textContrast";
import { ColorField } from "./ColorField";
@@ -25,43 +26,50 @@ export function TextColorField({
}) {
const te = useScopedT("editor");
const palette = paletteFor(plate);
+ // Its own provider, like `Toggle`: the field is also drawn outside a pane.
return (
- <div role="group" aria-label={label} style={{ display: "flex", alignItems: "center", gap: 6 }}>
- {palette.map((color) => {
- const active = value.toLowerCase() === color;
- return (
- <button
- key={color}
- type="button"
- title={color}
- aria-label={te("inspector.setColor", { color })}
- aria-pressed={active}
- disabled={disabled}
- onClick={() => {
- onChange(color);
- onCommit?.();
- }}
- style={{
- width: 22,
- height: 22,
- padding: 0,
- borderRadius: 999,
- background: color,
- border: active ? "2px solid var(--accent)" : "1px solid var(--border-hi)",
- cursor: disabled ? "default" : "pointer",
- opacity: disabled ? 0.5 : 1,
- }}
- />
- );
- })}
- <ColorField
- label={label}
- value={value}
- disabled={disabled}
- presets={palette}
- onChange={(next) => onChange(readableText(next, plate))}
- onCommit={onCommit}
- />
- </div>
+ <TooltipProvider>
+ <div
+ role="group"
+ aria-label={label}
+ style={{ display: "flex", alignItems: "center", gap: 6 }}
+ >
+ {palette.map((color) => {
+ const active = value.toLowerCase() === color;
+ return (
+ <Tooltip key={color} content={color}>
+ <button
+ type="button"
+ aria-label={te("inspector.setColor", { color })}
+ aria-pressed={active}
+ disabled={disabled}
+ onClick={() => {
+ onChange(color);
+ onCommit?.();
+ }}
+ style={{
+ width: 22,
+ height: 22,
+ padding: 0,
+ borderRadius: 999,
+ background: color,
+ border: active ? "2px solid var(--accent)" : "1px solid var(--border-hi)",
+ cursor: disabled ? "default" : "pointer",
+ opacity: disabled ? 0.5 : 1,
+ }}
+ />
+ </Tooltip>
+ );
+ })}
+ <ColorField
+ label={label}
+ value={value}
+ disabled={disabled}
+ presets={palette}
+ onChange={(next) => onChange(readableText(next, plate))}
+ onCommit={onCommit}
+ />
+ </div>
+ </TooltipProvider>
);
}
diff --git a/src/components/ai-edition/v4/FloatingInspector.tsx b/src/components/ai-edition/v4/FloatingInspector.tsx
index 58bae545b..d8eea283a 100644
--- a/src/components/ai-edition/v4/FloatingInspector.tsx
+++ b/src/components/ai-edition/v4/FloatingInspector.tsx
@@ -323,19 +323,20 @@ function paneHeader(icon: React.ReactNode, title: string, onClose: () => void, c
>
{title}
</h2>
- <button
- type="button"
- className={styles.iconBtn}
- title={closeLabel}
- aria-label={closeLabel}
- onClick={onClose}
- style={{
- width: 30,
- height: 30,
- }}
- >
- <X size={16} />
- </button>
+ <Tooltip content={closeLabel}>
+ <button
+ type="button"
+ className={styles.iconBtn}
+ aria-label={closeLabel}
+ onClick={onClose}
+ style={{
+ width: 30,
+ height: 30,
+ }}
+ >
+ <X size={16} />
+ </button>
+ </Tooltip>
</header>
);
}
@@ -1332,29 +1333,30 @@ function FacetBody({
const te = useScopedT("editor");
// A small collapse affordance floated over the reused pane header.
const collapse = (
- <button
- type="button"
- title={te("inspector.collapseInspector")}
- aria-label={te("inspector.collapseInspector")}
- onClick={onCollapse}
- style={{
- position: "absolute",
- top: 12,
- right: 12,
- width: 30,
- height: 30,
- display: "grid",
- placeItems: "center",
- borderRadius: 10,
- color: "var(--muted)",
- background: "var(--surface-1)",
- border: 0,
- cursor: "pointer",
- zIndex: 5,
- }}
- >
- <ChevronRight size={16} />
- </button>
+ <Tooltip content={te("inspector.collapseInspector")}>
+ <button
+ type="button"
+ aria-label={te("inspector.collapseInspector")}
+ onClick={onCollapse}
+ style={{
+ position: "absolute",
+ top: 12,
+ right: 12,
+ width: 30,
+ height: 30,
+ display: "grid",
+ placeItems: "center",
+ borderRadius: 10,
+ color: "var(--muted)",
+ background: "var(--surface-1)",
+ border: 0,
+ cursor: "pointer",
+ zIndex: 5,
+ }}
+ >
+ <ChevronRight size={16} />
+ </button>
+ </Tooltip>
);
if (facet === "layout") return wrap(collapse, <LayoutPane />);