Skip to content

Commit

Permalink
fix(RichTextContent): remove contenteditable attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmacknz committed Sep 3, 2024
1 parent 1054201 commit 6ccd895
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-lamps-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": patch
---

RichTextContent: remove contenteditable attribute instead of contenteditable=false
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, HTMLAttributes } from "react"
import React, { useState, HTMLAttributes, useId, useEffect } from "react"
import classnames from "classnames"
import { OverrideClassName } from "~components/types/OverrideClassName"
import { createSchemaWithAll } from "../RichTextEditor/schema"
Expand All @@ -14,6 +14,13 @@ export type RichTextContentProps = {
export const RichTextContent = (props: RichTextContentProps): JSX.Element => {
const { content, classNameOverride, ...restProps } = props
const [schema] = useState<ProseMirrorModel.Schema>(createSchemaWithAll())
const editorId = useId()

useEffect(() => {
// prosemirror only allows us to set this to false (which has caused a strange bug in the platform)
// so we have to hack a bit to remove the attribute completely
document.getElementById(editorId)?.removeAttribute("contenteditable")
}, [])

const [editorRef] = useRichTextEditor(
ProseMirrorState.EditorState.create({
Expand All @@ -23,7 +30,9 @@ export const RichTextContent = (props: RichTextContentProps): JSX.Element => {
}),
schema,
}),
undefined,
{
id: editorId,
},
{
editable: false,
}
Expand Down

0 comments on commit 6ccd895

Please sign in to comment.