Remove node on click? #3093
-
Hello, I'm loving the project I just had one question which I have not been able to find an answer to. I have created a new ElementNode based on the quote block node from the rich text package. It will contain predetermined messages suggesting/hinting the user on which type of content would be suitable in this area of the document. For specification / documentation purposes. I don't want the user to be able to edit the text content and when the node is clicked, I would like it to be removed / persistently hidden and for the cursor focus to be taken by the sibling node. Do you have any idea how to do this? Here is the current implementation which seems to result in the following error.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yea, you won't be able to do that. The canonical way to add event listeners to nodes is to use a Mutation Listener: https://lexical.dev/docs/concepts/listeners#registermutationlistener When the node is created, use getElementByKey to get the underlying DOM node and add a listener. Remove it when the node is destroyed. |
Beta Was this translation helpful? Give feedback.
Yea, you won't be able to do that.
The canonical way to add event listeners to nodes is to use a Mutation Listener: https://lexical.dev/docs/concepts/listeners#registermutationlistener
When the node is created, use getElementByKey to get the underlying DOM node and add a listener. Remove it when the node is destroyed.