Skip to content

Commit 1e7e03f

Browse files
committed
fix(studio): error toasts stay up on a click so their text can be copied
1 parent 863f18a commit 1e7e03f

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎packages/studio/src/components/StudioToast.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ describe("StudioToast", () => {
2727
expect(dismissed).toEqual(["info"]);
2828
});
2929

30+
it("keeps an error toast up on a click on it, so its text can be selected and copied", () => {
31+
const dismissed = mount("error");
32+
act(() => document.querySelector<HTMLElement>("[role=alert]")?.click());
33+
expect(dismissed).toEqual([]);
34+
});
35+
3036
it("gives a persisting error toast a Dismiss button that dismisses it once", () => {
3137
const dismissed = mount("error");
3238
act(() => document.querySelector<HTMLElement>("[aria-label=Dismiss]")?.click());

‎packages/studio/src/components/StudioToast.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,22 @@ interface StudioToastProps {
77
onDismiss: () => void;
88
}
99

10-
/** An inverted pill: a click or Escape dismisses it, and one that persists also gets a Dismiss button. */
1110
export function StudioToast({ message, tone, onDismiss }: StudioToastProps) {
11+
const persists = toastPersists(tone);
1212
return (
1313
<div
1414
role={tone === "error" ? "alert" : "status"}
15-
onClick={onDismiss}
15+
onClick={persists ? undefined : onDismiss}
1616
onKeyDown={(event) => {
1717
if (event.key === "Escape") onDismiss();
1818
}}
19-
className="hf-notice-in flex min-h-12 w-fit max-w-[min(680px,100%)] cursor-pointer items-center gap-1.5 rounded-3xl bg-text-0 py-1.5 pr-1.5 pl-5 text-[14px] leading-5 font-medium wrap-anywhere text-bg-0 shadow-notice not-has-[button]:pr-5"
19+
className={`hf-notice-in flex min-h-12 w-fit max-w-[min(680px,100%)] items-center gap-1.5 rounded-3xl bg-text-0 py-1.5 pr-1.5 pl-5 text-[14px] leading-5 font-medium wrap-anywhere text-bg-0 shadow-notice not-has-[button]:pr-5 ${persists ? "" : "cursor-pointer"}`}
2020
>
2121
<span className="min-w-0 flex-1 text-pretty">{message}</span>
22-
{toastPersists(tone) && (
22+
{persists && (
2323
<button
2424
type="button"
25-
onClick={(event) => {
26-
// The pill's own click would dismiss it a second time.
27-
event.stopPropagation();
28-
onDismiss();
29-
}}
25+
onClick={onDismiss}
3026
className="relative ml-2 grid h-9 w-9 shrink-0 place-items-center rounded-full text-bg-0/72 transition-[background-color,color,scale] duration-hover ease-out hover:bg-bg-0/16 hover:text-bg-0 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-bg-0 active:scale-[0.96]"
3127
aria-label="Dismiss"
3228
>

0 commit comments

Comments
 (0)