Skip to content

Commit 1eeafb6

Browse files
committed
fix(react): restore file block styling
1 parent d074655 commit 1eeafb6

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { BlockNoteSchema } from "@blocknote/core";
2+
import { describe, expect } from "vite-plus/test";
3+
4+
import { ReactFileBlock } from "./block.js";
5+
6+
describe("File block", () => {
7+
it.for(["core", "React"] as const)(
8+
"lays out the attachment icon next to its filename (%s)",
9+
async (variant, { setupEditor }) => {
10+
const defaultSchema = BlockNoteSchema.create();
11+
const schema =
12+
variant === "React"
13+
? defaultSchema.extend({ blockSpecs: { file: ReactFileBlock() } })
14+
: defaultSchema;
15+
const { rootNode } = await setupEditor({
16+
schema,
17+
initialContent: [
18+
{
19+
type: "file",
20+
props: {
21+
name: "Report.pdf",
22+
url: "https://example.com/report.pdf",
23+
},
24+
},
25+
],
26+
});
27+
28+
const icon = rootNode.querySelector(".bn-file-icon")!;
29+
const filename = rootNode.querySelector(".bn-file-name")!;
30+
const iconBounds = icon.getBoundingClientRect();
31+
const filenameBounds = filename.getBoundingClientRect();
32+
33+
expect(filename).toHaveTextContent("Report.pdf");
34+
expect(filenameBounds.left).toBeGreaterThanOrEqual(iconBounds.right);
35+
expect(filenameBounds.top).toBeLessThan(iconBounds.bottom);
36+
expect(filename.closest('[data-content-type="file"]')).toHaveAttribute(
37+
"data-file-block",
38+
);
39+
},
40+
);
41+
42+
it("styles the React add-file control and opens the file panel", async ({
43+
setupEditor,
44+
page,
45+
}) => {
46+
const { editor } = await setupEditor({
47+
schema: BlockNoteSchema.create().extend({
48+
blockSpecs: { file: ReactFileBlock() },
49+
}),
50+
initialContent: [{ type: "file" }],
51+
});
52+
53+
const addFile = page.getByRole("button", {
54+
name: editor.dictionary.file_blocks.add_button_text.file,
55+
});
56+
await expect.element(addFile).toHaveStyle({ display: "flex" });
57+
await addFile.click();
58+
await expect
59+
.element(
60+
page.getByRole("tab", {
61+
name: editor.dictionary.file_panel.embed.title,
62+
}),
63+
)
64+
.toBeVisible();
65+
});
66+
});

‎packages/react/src/blocks/File/block.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { FileBlockWrapper } from "./helpers/render/FileBlockWrapper.js";
55
import { LinkWithCaption } from "./helpers/toExternalHTML/LinkWithCaption.js";
66

77
export const ReactFileBlock = createReactBlockSpec(createFileBlockConfig, {
8+
meta: {
9+
fileBlockAccept: ["*/*"],
10+
},
811
render: (props) => <FileBlockWrapper {...props} />,
912
parse: fileParse(),
1013
toExternalHTML: (props) => {

‎tests/vite.config.browser.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const LOCAL_BROWSER_FILES = [
7979
"../packages/core/src/editor/managers/EventManager.browser.test.ts",
8080
"../packages/core/src/extensions/FormattingToolbar/FormattingToolbar.browser.test.ts",
8181
"../packages/core/src/extensions/SuggestionMenu/SuggestionMenu.browser.test.ts",
82+
"../packages/react/src/blocks/File/block.browser.test.tsx",
8283
"../packages/react/src/components/FormattingToolbar/DefaultButtons/BasicTextStyleButton.browser.test.tsx",
8384
"../packages/react/src/components/FormattingToolbar/DefaultButtons/ColorStyleButton.browser.test.tsx",
8485
"../packages/react/src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.browser.test.tsx",

0 commit comments

Comments
 (0)