From 418cf3439b88a6318210bb1c819d55f6aa8513ee Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza Date: Sat, 14 Nov 2026 20:29:58 -0300 Subject: [PATCH] fix(dashboard): show a disabled button's title in a tooltip (#20220) * fix(dashboard): show a disabled button's title in a tooltip The kit gives a disabled or loading button `pointer-events: none`, so the native `title` of ~93 dashboard buttons whose title is their own name (icon-only Refresh, Move up, Test all...) never showed while they were disabled. The Button adapter now wraps a titled button whose call site passes `disabled` or `loading` in the Tooltip adapter, once and in every state, so toggling never remounts the button or drops its focus. The tooltip opens only while the button is inactive; while enabled the native title keeps working, so there is one tooltip at a time and the accessible name/description are unchanged. The Tooltip adapter gains a controlled `open`/`onOpenChange` passthrough for that. QuotaCardExpanded's refresh button relied on its own `ml-auto` to sit at the end of the row; the row now ends at the button (`justify-end`) and the label takes the free space (`mr-auto`). Refs #19620 * fix(dashboard): keep ActionBar's grow reaching a titled button The outer tooltip span was `display: contents`, so ActionBar's direct-child `[&>*]:grow` (phones) hit no box and titled, disableable buttons stopped filling the row. Both wrappers are now boxes that take the parent's rule and pass the growth down (`[&>*]:grow`) to the button. Also give the new tooltip assertions a 5 s wait so a loaded runner does not miss the 300 ms open delay. Refs #19620 --- .../parts/QuotaCardExpanded.tsx | 6 +- src/shared/components/Button.tsx | 76 ++++++++++- src/shared/components/Tooltip.tsx | 12 +- .../guarded-action-disabled-title.test.ts | 23 ++-- ...ota-card-expanded-footer-flex-wrap.test.ts | 15 ++- .../button-disabled-title-tooltip.test.tsx | 118 ++++++++++++++++++ .../ui/playground-compare-column.test.tsx | 5 +- 7 files changed, 235 insertions(+), 20 deletions(-) create mode 100644 tests/unit/ui/adapters/button-disabled-title-tooltip.test.tsx diff --git a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/parts/QuotaCardExpanded.tsx b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/parts/QuotaCardExpanded.tsx index bb725fdd31a..c9403a9aac6 100644 --- a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/parts/QuotaCardExpanded.tsx +++ b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/parts/QuotaCardExpanded.tsx @@ -496,10 +496,10 @@ export default function QuotaCardExpanded({ )}
-
+
{refreshedLabel && ( {loading ? : } diff --git a/src/shared/components/Button.tsx b/src/shared/components/Button.tsx index 22d19506cda..e7fc205d23d 100644 --- a/src/shared/components/Button.tsx +++ b/src/shared/components/Button.tsx @@ -1,6 +1,6 @@ "use client"; -import { forwardRef } from "react"; +import { forwardRef, useState } from "react"; import { Button as KitButton, type ButtonSize as KitSize, @@ -8,6 +8,7 @@ import { } from "@omniroute/ui-kit/button"; import { cn } from "@/shared/utils/cn"; import Icon from "./Icon"; +import Tooltip from "./Tooltip"; /** Legacy variant vocabulary — kept because 150+ call sites and Modal.tsx type against it. */ export type ButtonVariant = @@ -69,7 +70,52 @@ export function resolveKitButton(variant: ButtonVariant, size: ButtonSize) { }; } -const Button = forwardRef(function Button( +/** + * A titled Button whose call site passes `disabled` or `loading` can go inactive, and the kit + * gives an inactive button `pointer-events: none`: its native `title` (often the only visible + * name of an icon button) would never show then. Such a button is wrapped once in the Tooltip + * adapter — always, so toggling `disabled` never remounts the button or drops its focus — and + * the tooltip opens only while the button is inactive. While enabled, the native title keeps + * working as before (one tooltip at a time, same accessible name/description). A reason for + * being disabled is not a title: use GuardedAction `reason` for that. + */ +function InactiveTitleTooltip({ + title, + inactive, + fullWidth, + children, +}: { + title: string; + inactive: boolean; + fullWidth: boolean; + children: React.ReactNode; +}) { + const [open, setOpen] = useState(false); + // Both wrappers are boxes that hand a parent's stretch down to the button: the outer + // `.ci-tooltip` span is the parent's flex item (it takes ActionBar's `[&>*]:grow` on phones) + // and `[&>*]:grow` passes that growth to the trigger, then to the button. `fullWidth` keeps + // the whole chain full width. + const chain = cn("max-w-full [&>*]:grow", fullWidth && "flex w-full"); + return ( + + {/* The trigger: it takes the hover while the button ignores pointer events and is the + keyboard stop while the button cannot be focused. `multiline`: a long title (a hint + rather than a short name) wraps instead of running off the viewport. */} + + {children} + + + ); +} + +/** The legacy props → kit Button mapping (unchanged); Button below only decides the wrapper. */ +const LegacyKitButton = forwardRef(function LegacyKitButton( { children, variant = "primary", @@ -105,4 +151,30 @@ const Button = forwardRef(function Button( ); }); +/** + * The title to keep visible while the button is inactive, or null when there is none or the + * button can never go inactive. Checked on the raw props: a call site that writes `disabled` + * or `loading` (even `disabled={false}`) has a button that can be disabled. + */ +function inactiveTitleOf(props: ButtonProps): string | null { + const canGoInactive = "disabled" in props || "loading" in props; + const { title } = props; + return canGoInactive && typeof title === "string" && title.trim() !== "" ? title : null; +} + +const Button = forwardRef(function Button(props, ref) { + const button = ; + const title = inactiveTitleOf(props); + if (title === null) return button; + return ( + + {button} + + ); +}); + export default Button; diff --git a/src/shared/components/Tooltip.tsx b/src/shared/components/Tooltip.tsx index 079500d5670..83c24da5af1 100644 --- a/src/shared/components/Tooltip.tsx +++ b/src/shared/components/Tooltip.tsx @@ -32,6 +32,9 @@ interface TooltipProps { * single-line `whitespace-nowrap` layout. Use when the label is long. */ multiline?: boolean; + /** Controlled open state (Radix). Omit both to let hover/focus drive the tooltip. */ + open?: boolean; + onOpenChange?: (open: boolean) => void; } function isInactiveControl(props: unknown): boolean { @@ -49,6 +52,8 @@ export default function Tooltip({ tooltipClassName, delayMs = 300, multiline = false, + open, + onOpenChange, }: TooltipProps) { if (content == null || content === "") return <>{children}; // A non-element child (text, numbers) gets a focusable span so keyboard users reach it. @@ -71,7 +76,12 @@ export default function Tooltip({ ); return ( - + {trigger} (src/shared/components/GuardedAction.tsx), which keeps the button -// focusable and shows the reason. +// `pointer-events: none`, so a native `title` on it never shows. Two kinds of titles, two fixes: +// +// - A title that explains WHY the button is disabled is a reason. Those buttons use +// (src/shared/components/GuardedAction.tsx), which keeps the button +// focusable, swallows the click and shows the reason. +// - A title that is the button's NAME (Refresh, Move up, Test all…) stays a title. The Button +// adapter (src/shared/components/Button.tsx) now shows it through the Tooltip adapter while +// the button is disabled or loading, and keeps the native title while it is enabled +// (tests/unit/ui/adapters/button-disabled-title-tooltip.test.tsx). // // The guard: a ); + const button = screen.getByRole("button", { name: "Copy" }); + expect(button.getAttribute("title")).toBe("Copy"); + expect(button.closest("[data-slot=tooltip-trigger]")).toBeNull(); + expect(button.closest(".ci-tooltip")).toBeNull(); + }); + + // CodeRabbit on #20220: ActionBar grows its direct children on phones (`[&>*]:grow`). The + // wrapper must stay a box that takes that rule and hand the growth down to the button; a + // `display: contents` wrapper would let the rule miss every box in the chain. + it("keeps ActionBar's direct-child grow reaching the button through the wrapper", () => { + render( + + + + ); + const button = screen.getByRole("button", { name: "Test all" }); + const trigger = button.parentElement!; + const outer = trigger.parentElement!; + expect(trigger.getAttribute("data-slot")).toBe("tooltip-trigger"); + expect(outer.classList.contains("ci-tooltip")).toBe(true); + // The ActionBar's flex item is the outer wrapper, and it is a real box. + expect(outer.parentElement!.className).toContain("[&>*]:grow"); + expect(outer.classList.contains("contents")).toBe(false); + // Each wrapper passes the growth to its only child, down to the button. + expect(outer.className).toContain("[&>*]:grow"); + expect(trigger.className).toContain("[&>*]:grow"); + }); + + it("does not wrap a disabled button without a title", () => { + render(); + expect(screen.getByRole("button", { name: "Save" }).closest(".ci-tooltip")).toBeNull(); + }); +}); diff --git a/tests/unit/ui/playground-compare-column.test.tsx b/tests/unit/ui/playground-compare-column.test.tsx index 36b999e8e13..962083965e1 100644 --- a/tests/unit/ui/playground-compare-column.test.tsx +++ b/tests/unit/ui/playground-compare-column.test.tsx @@ -159,7 +159,10 @@ describe("CompareColumn", () => { ) as HTMLButtonElement; expect(copyBtn).not.toBeNull(); - expect(copyBtn.nextElementSibling).toBe(removeBtn); + // The copy button can be disabled and has a title, so the Button adapter wraps it in its + // tooltip trigger (the title stays visible while disabled): compare the whole control. + const copyControl = copyBtn.closest(".ci-tooltip") ?? copyBtn; + expect(copyControl.nextElementSibling).toBe(removeBtn); await act(async () => { copyBtn.click();