react-contenteditable icon indicating copy to clipboard operation
react-contenteditable copied to clipboard

Disable multiline Input

Open LazerJesus opened this issue 5 years ago • 3 comments

Is it possible to disable mulitline Input? Meaning, no breaks. And when the user presses return while typing, nothing happens.

LazerJesus avatar Feb 20 '19 18:02 LazerJesus

You can just add onKeyDown={e => e.keyCode === 13 && e.preventDefault()} to your ContentEditable component.

ericmurphyxyz avatar Mar 12 '19 10:03 ericmurphyxyz

@ericnmurphy but this doesn't prevent someone pasting in line breaks, or does it?

zomars avatar Mar 20 '19 23:03 zomars

I use this code to keep single line

onChange={e => {
  // strip html
  const node = document.createElement('div')
  node.innerHTML = e.target.value
  const value = node.innerText.replace(/(?:\r\n|\r|\n)/g, ' ')
  this.onChange(value)
}}

iamandrewluca avatar Jul 01 '19 12:07 iamandrewluca