I'm attempting to simulate onKeyDown
events on the Editor
from slate-core
-- as opposed to slate-react
-- to test some plugins I am developing. However, the Editor
is not updating its Value
whatsoever.
I've extensively looked through the SlateJS 0.47.x
documentation and from what I can tell the Editor
component should respond to onKeyDown
events out-of-the-box.
Here is a small codesandbox example that reproduces my problem.
^ Notice that despite me trying to simulate numerous onKeyDown
events -- in the file core-editor-is-not-responding-to-on-key-down-events.js
-- the value of the Editor
never updates; it remains a blank document.
I am concerned about this difference in the behavior because seems like I would need to re-write functionality of inserting text as it gets typed out when said functionality I believe already exists.
Any help would be incredibly appreciated!
So it turns out to be a bug in Slate-Core, as @devinm mentioned. Without Slate-React, it doesn't react properly to onKeyDown
.
I don't know how to bundle this up for other people to use, and also this issue affects a number of Slate versions so I think the best thing really is to explain what needs to be done anyway.
Note that your environment will need to support ES6 imports.
slate-react-dom-plugin
slate-react-dom-plugin/index.js
file - utils
and constants
(again, from slate-react)
import DOMPlugin from './slate-react-dom-plugin'
new Editor({
value: value
plugins: [DOMPlugin({ plugins: [...ANY_OTHER_PLUGINS] })], // Wrap any plugins you use with the DOMPlugin
});
onKeyDown
events as expected nowLet me know if you have any questions!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With