Closed fridaystreet closed 4 years ago
Update: I found this issue #246 which is related to draft-js-plugins. It references a fix over in this is in the draft-js-plgin repo https://github.com/draft-js-plugins/draft-js-plugins/issues/1117
I've followed that to try and create a plugin but, the keybinding function never fires in the plugin.
So I've tried passing the keybing fn directly to the editor, but this doesn't seem to fire either. Thinking this would be the way with some additional logic to detect shift key on how to block the enter key on it's own?
const sendOnReturn = (event) => {
console.log('test', event.keyCode, event);
return undefined;
};
<Editor
keyBindingFn={sendOnReturn}
handleKeyCommand={command => ('not-handled')}
...
looks like as per the issues mentioned, keyBindingFn isn't hooked up in draftail.
Managed to solve the problem with handleReturn hook in a plugin
const createHandleReturnPlugin = (onReturn) => ({
handleReturn: (e) => {
if (e.keyCode === 13 && e.shiftKey) return;
if (isFunction(onReturn)) {
onReturn(e);
}
return 'handled';
}
});
Hi,
Have a chat app requirement. I would like to only allow the creation of a newline if shift + return is pressed. And capture the return only keypress to be used for sending the message.
Is this possible with Draftail?
Any assistance or direction greatly appreciated