question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Up/Down Arrow Keys Not Working on mention-plugin after altering key bindings.

See original GitHub issue

Hi all, I’m quite new to Draft JS /Draft JS Plugins and been trying to figure out what’s causing this. Originally what I wanted to happen is to alter the key-bindings of the editor to make the “Enter” key return a custom “submit-comment” event then assign Shift+Enter key to return a ‘split-block’ of which creates a new line or block. I was able to pull through with this code:

const handkekeyBindings = (e: SyntheticKeyboardEvent) => {
    if (e.key === "Enter") {
      if (e.nativeEvent.shiftKey) {
        return "split-block";
      } else {
        return "submit-comment";
      }
    }
    return getDefaultKeyBinding(e);
  };

I applied the key-bindings handler to my Editor Component:

<Editor
   editorState={editorState}
   onChange={handleEditorStateChange}
    keyBindingFn={handkekeyBindings}
    handleKeyCommand={handleKeyEvent}
    plugins={plugins}
 />

However, after altering the key-bindings of the editor , I can’t seem to use the UP/DOWN Arrow keys anymore to select any of the suggestions that would pop-out on the mentions.

image

Any Ideas on this one? I may perhaps messed up on something. Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

7reactions
Vodzocommented, Nov 18, 2020

Found a workaround for this exact issue I was having. The idea is to remove bindings while the suggestions popup is open and apply it again when closed.

const keyBinding = () => (e: React.KeyboardEvent): string | null => {
  if (e.key === "Enter") {
    if (e.nativeEvent.shiftKey) {
      return "split-block";
    } else {
      return "submit-comment";
    }
  }
  return getDefaultKeyBinding(e);
};

const SomeComponent = () => {
  /* default keyBinding */
  const [stateKeyBinding, setStateKeyBinding] = useState(keyBinding);

  const removeBinding = () => {
    setStateKeyBinding(undefined);
  };

  const applyBinding = () => {
    setStateKeyBinding(keyBinding);
  };

  return (
    <>
    <Editor 
      /* other props */
      keyBindingFn={stateKeyBinding}
    />
    <MentionSuggestions
      /* other props */
      onOpen={removeBinding}
      onClose={applyBinding}
    />
    </>
  )
}

Hope this helps your use case too!

0reactions
upworker00852commented, Dec 7, 2021

Hello. I need to popup a modal when clicking a selected mention. Would you please help me? Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

draft-js-mention-plugins: mentionSuggestions is handling up ...
Use-case/Problem This was initially reported in #856. I'm running the current master of this repo and still running into this issue.
Read more >
up key not working and down arrow key scrolling on its own
Go to settings > update and security > troubleshoot > additional troubleshooters > keyboard > run troubleshooter. Restart the computer and see ...
Read more >
Up, Down, Left and Right arrow keys do not trigger KeyDown ...
I set KeyPreview to true and I am handling the KeyDown event on this form. My problem is that sometimes the arrow key...
Read more >
3 Ways to Fix the Arrow Keys Not Working in Excel - MakeUseOf
With this guide, we'll show you how to fix arrow keys not working in Excel. ... Look out for a light on your...
Read more >
WASD and arrow keys swapped? Here's how to fix it
1. If you can, unplug your keyboard and plug it back in again, preferably into a different port. This is a quick fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found