ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.71k stars 3.24k forks source link

Void nodes not being deleted using removeNodeByKey #659

Closed oyeanuj closed 7 years ago

oyeanuj commented 7 years ago

Hey again! I ran into this issue where I am unable to delete a void block using removeNodeByKey - the same method works for inline nodes. For void block nodes, it doesn’t seem to remove it from the DOM even though it is removed from Slate state.

I am able to remove it by the default backspace behavior though.

Here is a fiddle illustrating that - https://jsfiddle.net/rzwn92np/2/

bunterWolf commented 7 years ago

removeNodeByKey works well ;) The problem is that the click on the button leads to onChange by the editor it self. Wich comes after your clickFunction. It gets overwritte. I stopped the click event and everything works well:

https://jsfiddle.net/bunterWolf/pqb5cehn/

oyeanuj commented 7 years ago

@bunterWolf ah, i see! thank you. I guess it still leaves me with one question - why would the same work for non-void nodes? The click again should be overwritten, right?

bunterWolf commented 7 years ago

yeah strange... :) I thought about contenteditable="false" and therefore editor > blur > onChange. But the editor blures even on non void nodes...

oyeanuj commented 7 years ago

@ianstormtaylor do you have thoughts on why this might be happening for void nodes but not for non-void nodes?

bengotow commented 6 years ago

Hey folks! I just ran into this as well trying to create my first removable void node —I wonder if the docs should mention calling preventDefault from your custom onClick handler? I ran into the problem following this example, which makes a removable img: https://docs.slatejs.org/guides/changes#2.-from-custom-node-components