mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-16 17:09:09 +00:00
Merge release/v3.8.54 into merge train 3
This commit is contained in:
@@ -496,10 +496,10 @@ export default function QuotaCardExpanded({
|
||||
)}
|
||||
|
||||
<div className="min-w-0 space-y-1.5 pt-1.5 border-t border-border/40">
|
||||
<div className="flex min-w-0 items-center justify-between gap-2">
|
||||
<div className="flex min-w-0 items-center justify-end gap-2">
|
||||
{refreshedLabel && (
|
||||
<span
|
||||
className={`text-[10px] tabular-nums ${
|
||||
className={`mr-auto text-[10px] tabular-nums ${
|
||||
hasStaleData ? "text-warning" : "text-text-muted"
|
||||
}`}
|
||||
title={
|
||||
@@ -521,7 +521,7 @@ export default function QuotaCardExpanded({
|
||||
e.stopPropagation();
|
||||
onRefresh();
|
||||
}}
|
||||
className="ml-auto inline-flex size-7 shrink-0 min-h-7"
|
||||
className="inline-flex size-7 shrink-0 min-h-7"
|
||||
>
|
||||
{loading ? <Spinner decorative size="xs" /> : <Icon name="refresh" size={12} />}
|
||||
</Button>
|
||||
|
||||
@@ -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<HTMLButtonElement, ButtonProps>(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 (
|
||||
<Tooltip
|
||||
content={title}
|
||||
multiline
|
||||
className={chain}
|
||||
open={inactive && open}
|
||||
onOpenChange={setOpen}
|
||||
>
|
||||
{/* 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. */}
|
||||
<span tabIndex={inactive ? 0 : undefined} className={cn("inline-flex", chain)}>
|
||||
{children}
|
||||
</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
/** The legacy props → kit Button mapping (unchanged); Button below only decides the wrapper. */
|
||||
const LegacyKitButton = forwardRef<HTMLButtonElement, ButtonProps>(function LegacyKitButton(
|
||||
{
|
||||
children,
|
||||
variant = "primary",
|
||||
@@ -105,4 +151,30 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(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<HTMLButtonElement, ButtonProps>(function Button(props, ref) {
|
||||
const button = <LegacyKitButton ref={ref} {...props} />;
|
||||
const title = inactiveTitleOf(props);
|
||||
if (title === null) return button;
|
||||
return (
|
||||
<InactiveTitleTooltip
|
||||
title={title}
|
||||
inactive={Boolean(props.disabled || props.loading)}
|
||||
fullWidth={Boolean(props.fullWidth)}
|
||||
>
|
||||
{button}
|
||||
</InactiveTitleTooltip>
|
||||
);
|
||||
});
|
||||
|
||||
export default Button;
|
||||
|
||||
@@ -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({
|
||||
</span>
|
||||
);
|
||||
return (
|
||||
<KitTooltip delayDuration={delayMs} className={className}>
|
||||
<KitTooltip
|
||||
delayDuration={delayMs}
|
||||
className={className}
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
>
|
||||
<TooltipTrigger asChild>{trigger}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side={position}
|
||||
|
||||
@@ -5,15 +5,21 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
// Owner decision 4 (2026-11-14, follow-up of #19620): the kit gives a disabled button
|
||||
// `pointer-events: none`, so a `title` on it never shows. A title that explains WHY the button
|
||||
// is disabled was therefore invisible exactly when it mattered. Those buttons now use
|
||||
// <GuardedAction reason={…}> (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
|
||||
// <GuardedAction reason={…}> (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 <Button> that is `disabled` and carries a `title` fails when the title can only
|
||||
// be a reason — the button is always disabled, or the title changes with state (ternary, `&&`,
|
||||
// `||`, `undefined`). A constant title is the button's label/hint (visible while it is enabled;
|
||||
// `aria-label` carries it for assistive tech) and passes. Every kept exception says why.
|
||||
// `||`, `undefined`). A constant title is the button's name and passes: it now shows in both
|
||||
// states. A state-dependent title that is still a name (a label that follows the state) is
|
||||
// listed in LABEL_TITLES, each with why; the adapter shows it while disabled too.
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
|
||||
@@ -80,7 +86,8 @@ function attr(tag: string, name: string): string | null {
|
||||
return tag.slice(i, j + 1);
|
||||
}
|
||||
|
||||
// Disabled buttons whose state-dependent title is still a label, not a reason.
|
||||
// Disabled buttons whose state-dependent title is still a name, not a reason. The Button
|
||||
// adapter shows it in a tooltip while the button is disabled, so it stays visible.
|
||||
const LABEL_TITLES: Array<{ file: string; marker: string; reason: string }> = [
|
||||
{
|
||||
file: "src/app/(dashboard)/dashboard/models/ModelCatalogTable.tsx",
|
||||
@@ -163,7 +170,7 @@ test("a disabled Button never carries a reason-only title (use GuardedAction rea
|
||||
assert.deepEqual(
|
||||
offenders,
|
||||
[],
|
||||
"a disabled button hides its title; move the explanation to <GuardedAction reason={…}>"
|
||||
"a disabled Button's title is its name (shown in a tooltip while disabled); move a reason to <GuardedAction reason={…}>"
|
||||
);
|
||||
const stale = LABEL_TITLES.filter((_, i) => !used.has(i)).map((e) => `${e.file} (${e.marker})`);
|
||||
assert.deepEqual(stale, [], "stale LABEL_TITLES entries: remove them");
|
||||
|
||||
@@ -13,8 +13,8 @@ test("QuotaCardExpanded footer enables flex-wrap to prevent action button clippi
|
||||
const content = fs.readFileSync(COMPONENT_PATH, "utf8");
|
||||
|
||||
// contract changed by #15138: the footer was redesigned for narrow cards — the
|
||||
// "Refresh now" action became a fixed-size icon button on its own row (shrink-0 +
|
||||
// ml-auto, so it can never be pushed off-screen) and the remaining actions moved
|
||||
// "Refresh now" action became a fixed-size icon button on its own row (shrink-0, at the
|
||||
// end of the row, so it can never be pushed off-screen) and the remaining actions moved
|
||||
// into an auto-fit grid that wraps instead of a flex-wrap row. The #11464 invariant
|
||||
// (no action button is clipped on narrow cards) is kept below; the real-browser
|
||||
// layout check lives in tests/helpers/assertQuotaCardLayout.cjs.
|
||||
@@ -33,10 +33,15 @@ test("QuotaCardExpanded footer enables flex-wrap to prevent action button clippi
|
||||
"Action buttons container must wrap (auto-fit grid) to prevent clipping on narrow cards"
|
||||
);
|
||||
|
||||
// Refresh now button is never compressed or pushed off-screen
|
||||
// Refresh now button is never compressed or pushed off-screen. Since the Button adapter wraps
|
||||
// a titled, disableable button in its tooltip trigger, a margin on the button no longer
|
||||
// reaches the row: the row itself ends at the button (justify-end) and the "Updated" label
|
||||
// takes the free space (mr-auto), with or without that label.
|
||||
assert.ok(
|
||||
/className="ml-auto inline-flex size-7 shrink-0 /.test(content) &&
|
||||
/className="flex min-w-0 items-center justify-end gap-2"/.test(content) &&
|
||||
/className=\{`mr-auto text-\[10px\] tabular-nums /.test(content) &&
|
||||
/className="inline-flex size-7 shrink-0 /.test(content) &&
|
||||
content.includes('aria-label={tr("forceRefresh", "Refresh now")}'),
|
||||
"Refresh now button must be a shrink-0 ml-auto icon button with an accessible label"
|
||||
"Refresh now button must be a shrink-0 icon button at the end of its row, with an accessible label"
|
||||
);
|
||||
});
|
||||
|
||||
118
tests/unit/ui/adapters/button-disabled-title-tooltip.test.tsx
Normal file
118
tests/unit/ui/adapters/button-disabled-title-tooltip.test.tsx
Normal file
@@ -0,0 +1,118 @@
|
||||
// @vitest-environment jsdom
|
||||
import React from "react";
|
||||
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
// Owner decision (2026-11-14, follow-up of #19620): ~93 dashboard buttons carry their own
|
||||
// NAME as `title` (icon-only Refresh, Move up, Test all…). The kit gives a disabled button
|
||||
// `pointer-events: none`, so that native title never shows while the button is disabled.
|
||||
// The Button adapter now routes the title through the Tooltip adapter whenever the button is
|
||||
// inactive, keeping the native title while it is enabled (one tooltip at a time).
|
||||
|
||||
const { default: Button } = await import("@/shared/components/Button");
|
||||
const { default: ActionBar } = await import("@/shared/components/ActionBar");
|
||||
|
||||
afterEach(() => cleanup());
|
||||
|
||||
const tooltips = () => screen.queryAllByRole("tooltip");
|
||||
// The tooltip opens after the adapter's 300 ms delay; leave room for a loaded CI runner.
|
||||
const findTooltip = () => screen.findByRole("tooltip", {}, { timeout: 5000 });
|
||||
|
||||
describe("Button adapter: the title stays visible when the button is disabled", () => {
|
||||
it("shows the title in a tooltip when a disabled button's wrapper is hovered", async () => {
|
||||
render(<Button size="icon-sm" icon="refresh" disabled title="Refresh" aria-label="Refresh" />);
|
||||
const button = screen.getByRole("button", { name: "Refresh" });
|
||||
const trigger = button.closest("[data-slot=tooltip-trigger]") as HTMLElement | null;
|
||||
expect(trigger, "the disabled button needs a tooltip trigger around it").not.toBeNull();
|
||||
expect(trigger).not.toBe(button);
|
||||
fireEvent.pointerMove(trigger!, { pointerType: "mouse" });
|
||||
await act(async () => {});
|
||||
const tip = await findTooltip();
|
||||
expect(tip.textContent).toContain("Refresh");
|
||||
});
|
||||
|
||||
it("opens the tooltip on keyboard focus of a disabled button (the wrapper is focusable)", async () => {
|
||||
render(<Button disabled title="Move up" aria-label="Move up" icon="arrow_upward" />);
|
||||
const trigger = screen
|
||||
.getByRole("button", { name: "Move up" })
|
||||
.closest("[data-slot=tooltip-trigger]") as HTMLElement;
|
||||
expect(trigger.getAttribute("tabindex")).toBe("0");
|
||||
fireEvent.focus(trigger);
|
||||
await act(async () => {});
|
||||
expect((await findTooltip()).textContent).toContain("Move up");
|
||||
});
|
||||
|
||||
it("keeps a single (native) tooltip while the same button is enabled", async () => {
|
||||
render(<Button disabled={false} title="Test all" icon="play_arrow" />);
|
||||
const button = screen.getByRole("button", { name: "Test all" });
|
||||
// Native title kept: accessible name/description and the browser tooltip are unchanged.
|
||||
expect(button.getAttribute("title")).toBe("Test all");
|
||||
const trigger = button.closest("[data-slot=tooltip-trigger]") as HTMLElement;
|
||||
// No extra tab stop next to an enabled button.
|
||||
expect(trigger.hasAttribute("tabindex")).toBe(false);
|
||||
fireEvent.pointerMove(trigger, { pointerType: "mouse" });
|
||||
fireEvent.focus(button);
|
||||
await act(async () => {});
|
||||
expect(tooltips()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("keeps the same button node (and focus) when disabled toggles", () => {
|
||||
const { rerender } = render(
|
||||
<Button disabled={false} title="Refresh" aria-label="Refresh" icon="refresh" />
|
||||
);
|
||||
const before = screen.getByRole("button", { name: "Refresh" });
|
||||
before.focus();
|
||||
expect(document.activeElement).toBe(before);
|
||||
rerender(<Button disabled title="Refresh" aria-label="Refresh" icon="refresh" />);
|
||||
rerender(<Button disabled={false} title="Refresh" aria-label="Refresh" icon="refresh" />);
|
||||
expect(screen.getByRole("button", { name: "Refresh" })).toBe(before);
|
||||
expect(document.activeElement).toBe(before);
|
||||
});
|
||||
|
||||
it("shows the title while a loading button is inactive", async () => {
|
||||
render(<Button loading title="Ping now" aria-label="Ping now" />);
|
||||
const trigger = screen
|
||||
.getByRole("button", { name: "Ping now" })
|
||||
.closest("[data-slot=tooltip-trigger]") as HTMLElement;
|
||||
fireEvent.pointerMove(trigger, { pointerType: "mouse" });
|
||||
await act(async () => {});
|
||||
expect((await findTooltip()).textContent).toContain("Ping now");
|
||||
});
|
||||
|
||||
it("leaves a button that can never be disabled untouched (native title, no wrapper)", () => {
|
||||
render(<Button title="Copy">Copy</Button>);
|
||||
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(
|
||||
<ActionBar>
|
||||
<Button disabled={false} title="Test all">
|
||||
Test all
|
||||
</Button>
|
||||
</ActionBar>
|
||||
);
|
||||
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(<Button disabled>Save</Button>);
|
||||
expect(screen.getByRole("button", { name: "Save" }).closest(".ci-tooltip")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user