Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(ui): open a tooltip on keyboard focus, not on any focus
EtienneLescot2ac20cfdafaf
diff --git a/src/components/ai-edition/LeftPanel.tooltips.test.tsx b/src/components/ai-edition/LeftPanel.tooltips.test.tsxindex 9796e9b64..edd0ccdf2 100644--- a/src/components/ai-edition/LeftPanel.tooltips.test.tsx+++ b/src/components/ai-edition/LeftPanel.tooltips.test.tsx@@ -115,6 +115,8 @@ function renderPanel() {/** Opens a control's tooltip the way the keyboard does (focus opens it at once) and returns what* it says and whether it shows a shortcut chip. */async function tooltipOn(control: HTMLElement) {+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => control.focus());const text = (await screen.findByRole("tooltip")).textContent;const chip = document.querySelector('[data-slot="tooltip-content"] kbd')?.textContent ?? null;diff --git a/src/components/ai-edition/v4/EditorTopBar.test.tsx b/src/components/ai-edition/v4/EditorTopBar.test.tsxindex afcb7d719..9377d994c 100644--- a/src/components/ai-edition/v4/EditorTopBar.test.tsx+++ b/src/components/ai-edition/v4/EditorTopBar.test.tsx@@ -437,6 +437,8 @@ describe("EditorTopBar responsive affordances and tooltips", () => {// Every icon-only control names itself in a tooltip; undo and redo also show the key.async function tooltipOn(name: string) {const control = screen.getByRole("button", { name });+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => control.focus());const tooltip = await screen.findByRole("tooltip");const visible = document.querySelector('[data-slot="tooltip-content"]');diff --git a/src/components/ai-edition/v4/FloatingInspector.test.tsx b/src/components/ai-edition/v4/FloatingInspector.test.tsxindex 204cf21b2..2bbe078bb 100644--- a/src/components/ai-edition/v4/FloatingInspector.test.tsx+++ b/src/components/ai-edition/v4/FloatingInspector.test.tsx@@ -112,6 +112,8 @@ describe("FloatingInspector", () => {async function tooltipOf(name: string) {const button = screen.getByRole("button", { name });+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => button.focus());await screen.findByRole("tooltip");const visible = document.querySelector<HTMLElement>('[data-slot="tooltip-content"]');@@ -159,6 +161,34 @@ describe("FloatingInspector", () => {expect(buttons.length).toBeGreaterThanOrEqual(5);for (const button of buttons) expect(button).not.toHaveAttribute("title");});++ it("names a rail button on hover, and Escape closes it", async () => {+ render(<FloatingInspector {...defaultProps} clips={oneClip} />);+ fireEvent.pointerMove(screen.getByRole("button", { name: "settings.audio.title" }));+ expect((await screen.findByRole("tooltip")).textContent).toBe("settings.facets.tips.audio");++ fireEvent.keyDown(document.body, { key: "Escape" });+ await waitFor(() => expect(screen.queryByRole("tooltip")).toBeNull());+ });++ // Issue #1016: the focus comes back to the clicked button when the window is switched back+ // to, and its tooltip opened then, over the panel and the next buttons, until a blur.+ it("leaves no tooltip on a clicked rail button when the focus comes back to it", () => {+ render(<FloatingInspector {...defaultProps} clips={oneClip} />);+ const audio = screen.getByRole("button", { name: "settings.audio.title" });+ fireEvent.pointerDown(audio);+ fireEvent.mouseDown(audio);+ act(() => audio.focus());+ fireEvent.pointerUp(audio);+ fireEvent.mouseUp(audio);+ fireEvent.click(audio);+ act(() => {+ audio.blur();+ audio.focus();+ });+ expect(audio).toHaveFocus();+ expect(screen.queryByRole("tooltip")).toBeNull();+ });});// Issue #1006: drawn inside the stage, the list was clipped by the stage's edge and its last@@ -575,6 +605,8 @@ describe("FloatingInspector", () => {openProject(3);render(<FloatingInspector {...defaultProps} />);const facet = await screen.findByRole("button", { name: "settings.cursor.title" });+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => facet.focus());expect((await screen.findByRole("tooltip")).textContent).toBe("settings.facets.tips.cursor");expect(facet).not.toHaveAttribute("title");diff --git a/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx b/src/components/ai-edition/v4/MediaStage.regenerate.test.tsxindex 35ed417ef..b57e4d550 100644--- a/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx+++ b/src/components/ai-edition/v4/MediaStage.regenerate.test.tsx@@ -77,6 +77,8 @@ describe("MediaStage Regenerate button", () => {it("asks for a new transcription, and says what it redoes in its tooltip", async () => {const regenerate = await openDetail();expect(regenerate).not.toHaveAttribute("title");+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => regenerate.focus());expect((await screen.findByRole("tooltip")).textContent).toBe("mediaStage.regenerateTip");fireEvent.click(regenerate);@@ -93,6 +95,8 @@ describe("MediaStage Regenerate button", () => {expect(regenerate).toHaveStyle({ opacity: "0.6", cursor: "not-allowed" });expect(regenerate.querySelector("svg")).toHaveClass("animate-spin");+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => regenerate.focus());expect(regenerate).toHaveFocus();expect((await screen.findByRole("tooltip")).textContent).toBe("mediaStage.regenerateTip");diff --git a/src/components/ai-edition/v4/RecStage.test.tsx b/src/components/ai-edition/v4/RecStage.test.tsxindex caee37c8e..47ac87e05 100644--- a/src/components/ai-edition/v4/RecStage.test.tsx+++ b/src/components/ai-edition/v4/RecStage.test.tsx@@ -139,6 +139,8 @@ function pill(rowLabelKey: string) {/** Opens a pill's tooltip the way the keyboard does (focus opens it at once) and returns what* it says, or null when it opens nothing. */async function tooltipOn(control: HTMLElement) {+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => control.focus());try {const text = (await screen.findByRole("tooltip", {}, { timeout: 150 })).textContent;@@ -675,6 +677,8 @@ describe("RecStage names and tooltips", () => {await screen.findByText("rec.hideDesktopIcons");for (const row of ["rec.systemAudio", "rec.editableCursor", "rec.hideDesktopIcons"]) {const control = pill(row);+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => control.focus());await screen.findByRole("tooltip");expect(diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsxindex c3f98ca09..7fdd1aeef 100644--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx@@ -943,6 +943,8 @@ describe("V4Timeline toolbar tooltips", () => {* returns the text and the chip of the visible copy. */async function tooltipOn(name: string) {const control = screen.getByLabelText(name);+ // A keyboard focus: one the mouse gave opens no tooltip.+ fireEvent.keyDown(window, { key: "Tab" });act(() => control.focus());await screen.findByRole("tooltip");const visible = document.querySelector('[data-slot="tooltip-content"]');@@ -963,6 +965,8 @@ describe("V4Timeline toolbar tooltips", () => {"buttons.addSpeed","buttons.addAnnotation","buttons.addCameraFullscreen",+ // Its menu also records a voiceover, but the key, like the lane's "Press M", adds audio.+ "toolbar.addAudioTooltip",]) {chips[name] = (await tooltipOn(name)).chip;// The name is the string alone: a "(Z)" in it would be a second, stale copy of the key.@@ -974,14 +978,16 @@ describe("V4Timeline toolbar tooltips", () => {"buttons.addSpeed": "S","buttons.addAnnotation": "A","buttons.addCameraFullscreen": "C",+ "toolbar.addAudioTooltip": "M",});});- // The five creators are remappable, so the chip must follow the saved binding, not the default.+ // The creators are remappable, so the chip must follow the saved binding, not the default.it("shows the key the user remapped, not the default", async () => {const getShortcuts = vi.fn(async () => ({addZoom: { key: "q" },addTrim: { key: "t", ctrl: true, shift: true },+ addAudio: { key: "b" },}));(window as unknown as { electronAPI?: unknown }).electronAPI = { getShortcuts };renderTimeline();@@ -989,6 +995,7 @@ describe("V4Timeline toolbar tooltips", () => {await act(() => Promise.resolve());expect((await tooltipOn("buttons.addZoom")).chip).toBe("Q");expect((await tooltipOn("buttons.addTrim")).chip).toBe("Ctrl + Shift + T");+ expect((await tooltipOn("toolbar.addAudioTooltip")).chip).toBe("B");// Unset actions keep their default.expect((await tooltipOn("buttons.addSpeed")).chip).toBe("S");});diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsxindex a29b9c239..0d9d7f537 100644--- a/src/components/ai-edition/v4/V4Timeline.tsx+++ b/src/components/ai-edition/v4/V4Timeline.tsx@@ -1918,7 +1918,10 @@ export function V4Timeline({button's menu right next to it. */}{tool.id === "comment" ? (<Popover open={audioMenuOpen} onOpenChange={setAudioMenuOpen}>- <Tooltip content={t("toolbar.addAudioTooltip")}>+ <Tooltip+ content={t("toolbar.addAudioTooltip")}+ shortcut={formatBinding(shortcuts.addAudio, isMac)}+ ><PopoverTrigger asChild><buttontype="button"diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsxindex eea0580eb..9036bf774 100644--- a/src/components/launch/LaunchWindow.test.tsx+++ b/src/components/launch/LaunchWindow.test.tsx@@ -236,6 +236,13 @@ function renderLaunchWindow() {);}+/** Focus as the keyboard gives it: after a Tab, so the control is `:focus-visible` and its+ * tooltip opens (a focus the mouse gave opens none). */+function focusByKeyboard(control: HTMLElement) {+ fireEvent.keyDown(window, { key: "Tab" });+ act(() => control.focus());+}+/*** Opens a control's tooltip the way the keyboard does (focus opens it at once, without the* hover delay) and returns its text. Radix draws a visually hidden `role="tooltip"` copy for@@ -243,7 +250,7 @@ function renderLaunchWindow() {*/async function tooltipOn(testId: string): Promise<string | null> {const control = screen.getByTestId(testId);- act(() => control.focus());+ focusByKeyboard(control);const text = (await screen.findByRole("tooltip")).textContent;act(() => control.blur());await waitFor(() => expect(screen.queryByRole("tooltip")).toBeNull());@@ -616,7 +623,7 @@ describe("LaunchWindow record button", () => {const recordButton = await screen.findByTestId("launch-record-button");await waitFor(() => expect(recordButton).toHaveAttribute("aria-label", "Start recording"));- act(() => recordButton.focus());+ focusByKeyboard(recordButton);await screen.findByRole("tooltip");// One Radix tooltip and no native title stacked on it, and not the source's name.@@ -658,7 +665,7 @@ describe("LaunchWindow record button", () => {renderLaunchWindow();const audio = await screen.findByTestId("launch-system-audio-button");- act(() => audio.focus());+ focusByKeyboard(audio);await screen.findByRole("tooltip");expect(document.querySelector("[data-slot='tooltip-content']")).toHaveAttribute("data-side",@@ -668,7 +675,7 @@ describe("LaunchWindow record button", () => {// A tooltip above a vertical bar would cover the controls above the pointer.fireEvent.click(screen.getByTestId("launch-tray-layout-button"));- act(() => screen.getByTestId("launch-system-audio-button").focus());+ focusByKeyboard(screen.getByTestId("launch-system-audio-button"));await waitFor(() =>expect(document.querySelector("[data-slot='tooltip-content']")).toHaveAttribute("data-side",@@ -708,7 +715,7 @@ describe("LaunchWindow record button", () => {Object.defineProperty(root, "clientHeight", { value: 800, configurable: true });try {- act(() => pause.focus());+ focusByKeyboard(pause);await screen.findByRole("tooltip");// Trigger's right edge 72 + the primitive's 8px gap + the 28px to the bar's edge.@@ -801,7 +808,7 @@ describe("LaunchWindow record button", () => {renderLaunchWindow();const hide = await screen.findByRole("button", { name: "Hide HUD" });- act(() => hide.focus());+ focusByKeyboard(hide);expect(await screen.findByRole("tooltip")).toHaveTextContent("Hide the recording bar. Show it again from the tray icon.",diff --git a/src/components/ui/tooltip.test.tsx b/src/components/ui/tooltip.test.tsxindex e2dc233c0..4c7cd86b5 100644--- a/src/components/ui/tooltip.test.tsx+++ b/src/components/ui/tooltip.test.tsx@@ -47,10 +47,27 @@ function popperWrapper() {return document.querySelector<HTMLElement>("[data-radix-popper-content-wrapper]");}+/** Focus the way the keyboard gives it: after a Tab, so the trigger is `:focus-visible`. jsdom+ * reads that from the last key, and ignores one sent to the element that had the focus. */+function focusByKeyboard(element: HTMLElement) {+ fireEvent.keyDown(window, { key: "Tab" });+ act(() => element.focus());+}++/** A mouse click: the pointer goes down, the browser focuses the button, the pointer comes up. */+function clickWithMouse(element: HTMLElement) {+ fireEvent.pointerDown(element);+ fireEvent.mouseDown(element);+ act(() => element.focus());+ fireEvent.pointerUp(element);+ fireEvent.mouseUp(element);+ fireEvent.click(element);+}+describe("Tooltip", () => {it("wraps long text and follows the text's own direction", () => {const button = renderTooltip();- act(() => button.focus());+ focusByKeyboard(button);const content = visibleTooltip();expect(content).toHaveAttribute("dir", "auto");@@ -62,7 +79,7 @@ describe("Tooltip", () => {it("renders a shortcut as its own left-to-right chip after the text", () => {const button = renderTooltip({ shortcut: "Ctrl + Z" });- act(() => button.focus());+ focusByKeyboard(button);const chip = visibleTooltip()?.querySelector("kbd");expect(chip).toHaveTextContent("Ctrl + Z");@@ -73,7 +90,7 @@ describe("Tooltip", () => {it("draws no chip when there is no shortcut", () => {const button = renderTooltip();- act(() => button.focus());+ focusByKeyboard(button);expect(visibleTooltip()?.querySelector("kbd")).toBeNull();});@@ -83,14 +100,14 @@ describe("Tooltip", () => {it("keeps a real gap between the trigger and the tooltip", async () => {expect(TOOLTIP_GAP_PX).toBe(8);const button = renderTooltip();- act(() => button.focus());+ focusByKeyboard(button);await waitFor(() => expect(popperWrapper()?.style.transform).toBe("translate(0px, -8px)"));});it("lets a trigger that sits inside a padded surface ask for a larger gap", async () => {const button = renderTooltip({ sideOffset: 8 + 28 });- act(() => button.focus());+ focusByKeyboard(button);await waitFor(() => expect(popperWrapper()?.style.transform).toBe("translate(0px, -36px)"));});@@ -113,9 +130,38 @@ describe("Tooltip", () => {it("opens at once on keyboard focus and describes the trigger", () => {const button = renderTooltip();- act(() => button.focus());+ focusByKeyboard(button);expect(visibleTooltip()).not.toBeNull();expect(button).toHaveAccessibleDescription("Add a zoom at the playhead");});++ it("closes on Escape", () => {+ vi.useFakeTimers();+ const button = renderTooltip();+ fireEvent.pointerMove(button);+ act(() => {+ vi.advanceTimersByTime(400);+ });+ expect(visibleTooltip()).not.toBeNull();++ fireEvent.keyDown(button, { key: "Escape" });+ expect(visibleTooltip()).toBeNull();+ });++ // Issue #1016. Focus comes back to a clicked control without a click: the window is switched+ // back to, a dialog returns it to its opener. Radix opened the tooltip then, and only a blur+ // closed it, so it stayed over the controls beside it.+ it("leaves no tooltip after a click, even when the focus comes back to it", () => {+ const button = renderTooltip();+ clickWithMouse(button);+ expect(visibleTooltip()).toBeNull();++ act(() => {+ button.blur();+ button.focus();+ });+ expect(button).toHaveFocus();+ expect(visibleTooltip()).toBeNull();+ });});diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsxindex 01b06c55e..6defa0101 100644--- a/src/components/ui/tooltip.tsx+++ b/src/components/ui/tooltip.tsx@@ -36,8 +36,20 @@ function TooltipRoot({ ...props }: React.ComponentProps<typeof TooltipPrimitive.const TooltipTrigger = React.forwardRef<React.ComponentRef<typeof TooltipPrimitive.Trigger>,React.ComponentProps<typeof TooltipPrimitive.Trigger>->(({ ...props }, ref) => (- <TooltipPrimitive.Trigger ref={ref} data-slot="tooltip-trigger" {...props} />+>(({ onFocus, ...props }, ref) => (+ <TooltipPrimitive.Trigger+ ref={ref}+ data-slot="tooltip-trigger"+ onFocus={(event) => {+ onFocus?.(event);+ // Radix opens on every focus, and focus also comes back to a control the mouse clicked:+ // the window is switched back to, a dialog returns it to its opener. That tooltip stayed+ // open until the next blur, over the controls beside it. Only the keyboard's focus opens+ // it, the one `:focus-visible` marks (Radix skips a prevented event).+ if (!event.currentTarget.matches(":focus-visible")) event.preventDefault();+ }}+ {...props}+ />));TooltipTrigger.displayName = "TooltipTrigger";