Skip to content

Commit 068acdf

Browse files
committed
Fix fullscreen, fix unit tests
1 parent 72fdc86 commit 068acdf

File tree

4 files changed

+50
-42
lines changed

4 files changed

+50
-42
lines changed

packages/streamdown/__tests__/components.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ describe("Markdown Components", () => {
433433
const table = tableWrapper?.querySelector("table");
434434
expect(table).toBeTruthy();
435435
expect(table?.className).toContain("w-full");
436-
expect(table?.className).toContain("border-collapse");
437-
expect(table?.className).toContain("border");
436+
expect(table?.className).toContain("divide-y");
437+
expect(table?.className).toContain("divide-border");
438438
});
439439

440440
it("should render thead with correct classes", () => {
@@ -470,7 +470,6 @@ describe("Markdown Components", () => {
470470
expect(tbody).toBeTruthy();
471471
expect(tbody?.className).toContain("divide-y");
472472
expect(tbody?.className).toContain("divide-border");
473-
expect(tbody?.className).toContain("bg-muted/40");
474473
});
475474

476475
it("should render tr with correct classes", () => {

packages/streamdown/lib/mermaid/fullscreen-button.tsx

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { MermaidConfig } from "mermaid";
22
import { type ComponentProps, useContext, useEffect, useState } from "react";
3+
import { createPortal } from "react-dom";
34
import { StreamdownContext } from "../../index";
45
import { Maximize2Icon, XIcon } from "../icons";
56
import { cn } from "../utils";
@@ -102,44 +103,47 @@ export const MermaidFullscreenButton = ({
102103
<Maximize2Icon size={14} />
103104
</button>
104105

105-
{isFullscreen ? (
106-
// biome-ignore lint/a11y/useSemanticElements: "div is used as a backdrop overlay, not a button"
107-
<div
108-
className="fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"
109-
onClick={handleToggle}
110-
onKeyDown={(e) => {
111-
if (e.key === "Escape") {
112-
handleToggle();
113-
}
114-
}}
115-
role="button"
116-
tabIndex={0}
117-
>
118-
<button
119-
className="absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"
120-
onClick={handleToggle}
121-
title="Exit fullscreen"
122-
type="button"
123-
>
124-
<XIcon size={20} />
125-
</button>
126-
{/* biome-ignore lint/a11y/noStaticElementInteractions: "div with role=presentation is used for event propagation control" */}
127-
<div
128-
className="flex size-full items-center justify-center p-4"
129-
onClick={(e) => e.stopPropagation()}
130-
onKeyDown={(e) => e.stopPropagation()}
131-
role="presentation"
132-
>
133-
<Mermaid
134-
chart={chart}
135-
className="size-full [&_svg]:h-auto [&_svg]:w-auto"
136-
config={config}
137-
fullscreen={true}
138-
showControls={showPanZoomControls}
139-
/>
140-
</div>
141-
</div>
142-
) : null}
106+
{isFullscreen
107+
? createPortal(
108+
// biome-ignore lint/a11y/useSemanticElements: "div is used as a backdrop overlay, not a button"
109+
<div
110+
className="fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"
111+
onClick={handleToggle}
112+
onKeyDown={(e) => {
113+
if (e.key === "Escape") {
114+
handleToggle();
115+
}
116+
}}
117+
role="button"
118+
tabIndex={0}
119+
>
120+
<button
121+
className="absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"
122+
onClick={handleToggle}
123+
title="Exit fullscreen"
124+
type="button"
125+
>
126+
<XIcon size={20} />
127+
</button>
128+
{/* biome-ignore lint/a11y/noStaticElementInteractions: "div with role=presentation is used for event propagation control" */}
129+
<div
130+
className="flex size-full items-center justify-center p-4"
131+
onClick={(e) => e.stopPropagation()}
132+
onKeyDown={(e) => e.stopPropagation()}
133+
role="presentation"
134+
>
135+
<Mermaid
136+
chart={chart}
137+
className="size-full [&_svg]:h-auto [&_svg]:w-auto"
138+
config={config}
139+
fullscreen={true}
140+
showControls={showPanZoomControls}
141+
/>
142+
</div>
143+
</div>,
144+
document.body
145+
)
146+
: null}
143147
</>
144148
);
145149
};

packages/streamdown/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/hast": "^3.0.4",
4646
"@types/react": "^19.2.7",
4747
"@types/react-dom": "^19.2.3",
48+
"react-dom": "^19.2.3",
4849
"@vitejs/plugin-react": "^5.1.2",
4950
"@vitest/coverage-v8": "^4.0.15",
5051
"jsdom": "^27.3.0",
@@ -57,7 +58,8 @@
5758
"vitest": "^4.0.15"
5859
},
5960
"peerDependencies": {
60-
"react": "^18.0.0 || ^19.0.0"
61+
"react": "^18.0.0 || ^19.0.0",
62+
"react-dom": "^18.0.0 || ^19.0.0"
6163
},
6264
"dependencies": {
6365
"clsx": "^2.1.1",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)