feat: add editorContainerProps to EditorProvider (#5661)

This commit is contained in:
Kartikeya Choudhary 2024-09-26 15:17:19 +05:30 committed by GitHub
parent e8e4df38d5
commit 26056aa0c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/react": patch
---
Add editorContainerProps to EditorProvider. This allows for any HTML attributes to be added to the EditorContent when using EditorProvider

View File

@ -1,5 +1,7 @@
import { Editor } from '@tiptap/core' import { Editor } from '@tiptap/core'
import React, { createContext, ReactNode, useContext } from 'react' import React, {
createContext, HTMLAttributes, ReactNode, useContext,
} from 'react'
import { EditorContent } from './EditorContent.js' import { EditorContent } from './EditorContent.js'
import { useEditor, UseEditorOptions } from './useEditor.js' import { useEditor, UseEditorOptions } from './useEditor.js'
@ -23,6 +25,7 @@ export type EditorProviderProps = {
children?: ReactNode; children?: ReactNode;
slotBefore?: ReactNode; slotBefore?: ReactNode;
slotAfter?: ReactNode; slotAfter?: ReactNode;
editorContainerProps?: HTMLAttributes<HTMLDivElement>;
} & UseEditorOptions } & UseEditorOptions
/** /**
@ -31,7 +34,7 @@ export type EditorProviderProps = {
* with `useCurrentEditor`. * with `useCurrentEditor`.
*/ */
export function EditorProvider({ export function EditorProvider({
children, slotAfter, slotBefore, ...editorOptions children, slotAfter, slotBefore, editorContainerProps = {}, ...editorOptions
}: EditorProviderProps) { }: EditorProviderProps) {
const editor = useEditor(editorOptions) const editor = useEditor(editorOptions)
@ -44,7 +47,7 @@ export function EditorProvider({
{slotBefore} {slotBefore}
<EditorConsumer> <EditorConsumer>
{({ editor: currentEditor }) => ( {({ editor: currentEditor }) => (
<EditorContent editor={currentEditor} /> <EditorContent editor={currentEditor} {...editorContainerProps} />
)} )}
</EditorConsumer> </EditorConsumer>
{children} {children}