diff --git a/packages/react/src/ReactNodeViewRenderer.tsx b/packages/react/src/ReactNodeViewRenderer.tsx index a48b79d2fa9..514cb9b3f67 100644 --- a/packages/react/src/ReactNodeViewRenderer.tsx +++ b/packages/react/src/ReactNodeViewRenderer.tsx @@ -26,6 +26,7 @@ export interface ReactNodeViewRendererOptions extends NodeViewRendererOptions { | null as?: string className?: string + attrs?: Record } class ReactNodeView extends NodeView< @@ -103,6 +104,7 @@ class ReactNodeView extends NodeView< props, as, className: `node-${this.node.type.name} ${className}`.trim(), + attrs: this.options.attrs, }) } diff --git a/packages/react/src/ReactRenderer.tsx b/packages/react/src/ReactRenderer.tsx index 493baa3b045..a47a93dea56 100644 --- a/packages/react/src/ReactRenderer.tsx +++ b/packages/react/src/ReactRenderer.tsx @@ -23,6 +23,7 @@ export interface ReactRendererOptions { props?: Record, as?: string, className?: string, + attrs?: Record, } type ComponentType = @@ -50,6 +51,7 @@ export class ReactRenderer { props = {}, as = 'div', className = '', + attrs, }: ReactRendererOptions) { this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString() this.component = component @@ -62,6 +64,12 @@ export class ReactRenderer { this.element.classList.add(...className.split(' ')) } + if (attrs) { + Object.keys(attrs).forEach(key => { + this.element.setAttribute(key, attrs[key]) + }) + } + this.render() }