Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: allow to customize the tag of the contentDOMElement #3984

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface NodeViewRendererOptions {
ignoreMutation:
| ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean)
| null
contentDOMElementTag: string
}

export type NodeViewRendererProps = {
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/ReactNodeViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ class ReactNodeView extends NodeView<

ReactNodeViewProvider.displayName = 'ReactNodeView'

this.contentDOMElement = this.node.isLeaf
? null
: document.createElement(this.node.isInline ? 'span' : 'div')
if (this.node.isLeaf) {
this.contentDOMElement = null
} else if (this.options.contentDOMElementTag) {
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag)
} else {
this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div')
}

if (this.contentDOMElement) {
// For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
Expand Down