Skip to content

Commit eeda50b

Browse files
Small changes to ReactAlert and added as prop to InlineContent component (#245)
1 parent 476b3eb commit eeda50b

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

packages/react/src/ReactBlockSpec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
NodeViewWrapper,
1717
ReactNodeViewRenderer,
1818
} from "@tiptap/react";
19-
import { FC, HTMLAttributes } from "react";
19+
import { ElementType, FC, HTMLProps } from "react";
2020

2121
// extend BlockConfig but use a react render function
2222
export type ReactBlockConfig<
@@ -38,7 +38,9 @@ export type ReactBlockConfig<
3838
}>;
3939
};
4040

41-
export const InlineContent = (props: HTMLAttributes<HTMLDivElement>) => (
41+
export const InlineContent = <Tag extends ElementType>(
42+
props: { as?: Tag } & HTMLProps<Tag>
43+
) => (
4244
<NodeViewContent
4345
{...props}
4446
className={`${props.className ? props.className + " " : ""}${

packages/website/docs/docs/block-types.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ For our custom image block, we use a parent `div` which contains the image and c
308308

309309
But what's this `InlineContent` component? Since we set `containsInlineContent` to `true`, it means we want to include an editable rich-text field somewhere in the image block. You should use the `InlineContent` component to represent this field in your `render` component. Since we're using it to create our caption, we add it below the `img` element.
310310

311+
In the DOM, the `InlineContent` component is rendered as a `div` by default, but you can make it use a different element by passing `as={"elementTag"}` as a prop. For example, `as={"p"}` will make the `InlineContent` component get rendered to a paragraph.
312+
311313
While the `InlineContent` component can be put anywhere inside the component you pass to `render`, you should make sure to only have one. If `containsInlineContent` is set to false, `render` shouldn't contain any.
312314

313315
### Adding Custom Blocks to the Editor

tests/utils/customblocks/ReactAlert.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
InlineContent,
55
ReactSlashMenuItem,
66
} from "@blocknote/react";
7-
import React, { useState } from "react";
7+
import { useEffect, useState } from "react";
88
import { RiAlertFill } from "react-icons/ri";
99

1010
const values = {
@@ -40,7 +40,7 @@ export const ReactAlert = createReactBlockSpec({
4040
render: (props) => {
4141
const [type, setType] = useState(props.block.props.type);
4242

43-
React.useEffect(() => {
43+
useEffect(() => {
4444
console.log("ReactAlert initialize");
4545
return () => {
4646
console.log(" ReactAlert cleanup");

0 commit comments

Comments
 (0)