Andarist / react-textarea-autosize

<textarea /> component for React which grows with content

Home Page:http://andarist.github.io/react-textarea-autosize/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

textarea-autosize conflict with custom key bind

joeylin opened this issue · comments

commented

I want to a function like this: when I use shift + enter, I can wrap lines, and the textarea can autoheight,
when I use enter key, I can send the message,
BUT, when I bind the enter key to textarea(with this plugin), I found enter key was used to wrapping lines default,
Does the plugin support this feature? I understand this is a more general scenario.

thanks very much

@joeylin in case it helps I think I figured this out. You can just do an e.preventDefault(). My resulting code looks something like this:

<textarea
  onKeyDown={(e) => {
    if (!e.shiftKey && e.key === 'Enter') {
      e.preventDefault();
      handleSendMessage();
    }
  }}
/>