Skip to content

Commit 7374024

Browse files
fix(web): align multiline error alert controls
1 parent 6f04a5c commit 7374024

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { renderToStaticMarkup } from "react-dom/server";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { ThreadErrorBanner } from "./ThreadErrorBanner";
5+
6+
describe("ThreadErrorBanner", () => {
7+
it("aligns the warning and dismiss icons with the first line of a multi-line error", () => {
8+
const markup = renderToStaticMarkup(
9+
<ThreadErrorBanner
10+
error={"The first error line\ncontinues on a second line"}
11+
onDismiss={() => {}}
12+
/>,
13+
);
14+
15+
expect(markup).toContain('role="alert"');
16+
expect(markup).toContain('aria-label="Dismiss error"');
17+
expect(markup).not.toContain("controlAlignment");
18+
expect(markup).toContain("flex gap-2 items-start");
19+
expect(markup).toContain("min-h-7 pt-1 sm:min-h-6 sm:pt-0.5");
20+
expect(markup).toContain("h-lh w-4");
21+
expect(markup).toContain("h-lh self-start");
22+
});
23+
});

‎apps/web/src/components/chat/ThreadErrorBanner.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const ThreadErrorBanner = memo(function ThreadErrorBanner({
1414
if (!error) return null;
1515
return (
1616
<div className="mx-auto w-fit max-w-[min(48rem,calc(100%-2rem))] pt-3">
17-
<Alert variant="error">
17+
<Alert variant="error" controlAlignment="first-line">
1818
<CircleAlertIcon />
1919
<AlertDescription>
2020
<Tooltip>

‎apps/web/src/components/ui/alert.tsx‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ function alertChildSlot(child: React.ReactElement): string | undefined {
4242
function Alert({
4343
className,
4444
variant,
45+
controlAlignment = "center",
4546
children,
4647
...props
47-
}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {
48+
}: React.ComponentProps<"div"> &
49+
VariantProps<typeof alertVariants> & {
50+
controlAlignment?: "center" | "first-line";
51+
}) {
4852
const icon: React.ReactNode[] = [];
4953
const content: React.ReactNode[] = [];
5054
const action: React.ReactNode[] = [];
@@ -71,17 +75,39 @@ function Alert({
7175
role="alert"
7276
{...props}
7377
>
74-
<div className="flex items-center gap-2">
78+
<div
79+
className={cn(
80+
"flex gap-2",
81+
controlAlignment === "first-line" ? "items-start" : "items-center",
82+
controlAlignment === "first-line" &&
83+
action.length > 0 &&
84+
"min-h-7 pt-1 sm:min-h-6 sm:pt-0.5",
85+
)}
86+
>
7587
{icon.length > 0 && (
76-
<div className="flex size-4 shrink-0 items-center justify-center [&>svg]:size-full">
88+
<div
89+
className={cn(
90+
"flex shrink-0 items-center justify-center",
91+
controlAlignment === "first-line"
92+
? "h-lh w-4 [&>svg]:size-4"
93+
: "size-4 [&>svg]:size-full",
94+
)}
95+
>
7796
{icon}
7897
</div>
7998
)}
8099
{content.length > 0 && (
81100
<div className="flex min-w-0 flex-1 flex-col gap-0.5">{content}</div>
82101
)}
83102
{action.length > 0 && (
84-
<div className="flex shrink-0 items-center self-center">{action}</div>
103+
<div
104+
className={cn(
105+
"flex shrink-0 items-center",
106+
controlAlignment === "first-line" ? "h-lh self-start" : "self-center",
107+
)}
108+
>
109+
{action}
110+
</div>
85111
)}
86112
</div>
87113
</div>

0 commit comments

Comments
 (0)