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.

Problems with inputs and textareas inside of draggable component

See original GitHub issue

I investigate some problems when placing <input> and <textarea> elements inside of draggable component,

  1. cmd+A or Ctrl+A shortcuts doesn’t work for input or textarea (but selecting text with Shift + Arrows still works)
  2. Attempt to select input or textarea content with touchpad/mouse starts dragging parent element

My draggable component looks like,

draggable component

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
megawebmastercommented, Apr 10, 2020

@rahul1995 - I just found out a solution: just store a ref to the draggable DOM node and when user focuses input/textarea set draggable attribute to false:

const Test = () => {
  const ref = useRef(null);
  const [focused, setFocused] = useState(false);
  const [_, drag] = useDrag({ item: { type: 'test' } });

  useEffect(() => {
    if (ref.current) {
      ref.current.setAttribute('draggable', !focused);
    }
  }, [focused]);

  return drag(
    <textarea ref={ref} onFocus={() => setFocused(true)} onBlur={() => setFocused(false)}></textarea>
  );
};

This should do the trick for Firefox 😉

4reactions
trevorsmithcommented, Mar 3, 2016

Elements with contentEditable set inside a draggable parent container wouldn’t allow me to select text or interact with them in any way. After some digging, I found this bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=170139

It appears Chrome has since fixed the issue. Safari’s behavior can be fixed in the meantime with CSS:

.contenteditable-element {
  user-select: text;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

1189486 - draggable element interferes with input elements
I am trying to select the text with the mouse by either double click on word or drag through text. For instance: <div...
Read more >
Can inputs and textareas be draggable? - Stack Overflow
MDN confirms that draggable is a global attribute (i.e. can be applied to any element), but has the following usage note:.
Read more >
How to Use Text Areas (The Java™ Tutorials > Creating a GUI ...
Demonstrates built-in drag-and-drop functionality of several Swing components, including text areas. FocusConceptsDemo · How to Use the Focus Subsystem ...
Read more >
HTML Drag and Drop API - W3Schools
In HTML, any element can be dragged and dropped. Example. W3Schools. Drag the W3Schools image into the rectangle. Drag and Drop. Drag and...
Read more >
Textarea - Lightning Design System
Textarea inputs are used for freeform data entry. * Textarea Label. About Textarea#. You can style the HTML <textarea> element to align with...
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