Andarist / react-textarea-autosize

<textarea /> component for React which grows with content
http://andarist.github.io/react-textarea-autosize/
MIT License
2.22k stars 246 forks source link

textarea-autosize conflict with custom key bind #380

Open joeylin opened 1 year ago

joeylin commented 1 year ago

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

longlostnick commented 12 months ago

@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();
    }
  }}
/>