With editable: false, the contenteditable attribute on the document node is removed, which by default makes the browser disable keyboard focus for the element. When the node isn’t focused, it doesn’t even receive keyboard events, so it’s hard to implement any keybindings for it.
You could use the attributes prop to add a tabIndex=0 attribute to your editor to make it focusable. But this might lead to some other key bindings also firing, and if those do change the document, editable: false (which works only on the DOM) level won’t stop them.
I haven’t had success with keymap when the editor is non-editable, even when I set a tabIndex and confirm it’s focused with document.activeElement === document.querySelector('.ProseMirror') returning true.
I’ve had to resort to handleDOMEvents.keydown but this is messy and duplicative.
@marijn I wonder if you’re certain that the approach you outlined should work, or if there might be something more required? If you’re sure then I guess I have some issue I’m overlooking.
Indeed, keymap uses the handleKeyDown prop, which is part of the library’s built-in handling of key events. This is disabled for uneditable editors on the assumption that a lot of keybindings will change the document in ways you don’t want to happen in a read-only editor. “Raw” event handlers registered through handleDOMEventswill fire, and you can tie something like a keymap into them using the keydownHandler helper from prosemirror-keymap. Maybe that’s a workaround that helps here?