react-dnd: Problems with inputs and textareas inside of draggable component

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

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 24 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@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 😉

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;
}

This is not documented very well, but if you add the class name nodrag this works to not allow dragging by the text input field, meaning you can select and highlight text with your cursor.

No other solutions solved my issue.

      <>
        <Input
          disabled={isDisabled}
          value={value}
          onChange={handleChange}
          className={'nodrag'}
          placeholder={placeholder}
          multiline
          error={error_message}
        />
      </>

@trevorsmith This is still not fixing the Firefox’s behaviour. Do you know any workaround for Firefox?