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.

When Draggable unmounts, if a textbox is focused, the textbox loses focus inexplicably

See original GitHub issue

My app renders some Items depending on the content of several text input.

The Items each contain a Draggable.

I’m coming across this very strange behavior:

  • I type a valid value into a textbox, causing some Items to render
  • Without leaving the textbox, I delete or add a few characters to make the value invalid
  • The Items disappear (unmount)
  • My textbox suddenly loses focus. However, no onBlur handlers are called, and if I switch tabs / windows and then switch back, focus is restored
  • I can prevent this issue by deleting the Draggable component

Here’s a codesandbox showing the issue: https://codesandbox.io/s/32x3voojm5

I can consistently reproduce this.

Browser is Chrome 64.0.3282.119 (Official Build) (64-bit) on Mac OSX.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
skvalecommented, Feb 26, 2018

Looks like it is an issue in the enableUserSelectHack prop

enableUserSelectHack causes this to be called

export function removeUserSelectStyles(doc: ?Document) {
  try {
    if (doc && doc.body) removeClassName(doc.body, 'react-draggable-transparent-selection');
    window.getSelection().removeAllRanges();  // remove selection caused by scroll
  } catch (e) {
    // probably IE
  }
}

You could try

<Draggable enableUserSelectHack={false}>

But I didn’t look into what consequence not calling removeUserSelectStyles would have.

Working: https://codesandbox.io/s/944j9x101o

6reactions
lc-stevenzhangcommented, Mar 21, 2018

Thank you guys! I have encounter the same problem, my filter lose focus cause the Draggable. And enableUserSelectHack={false} fixed my problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When Draggable unmounts, if a textbox is focused ... - GitHub
My textbox suddenly loses focus. However, no onBlur handlers are called, and if I switch tabs / windows and then switch back, focus...
Read more >
jQuery-focused textbox loses focus after one character of input ...
After the first character of input is typed, the input box loses focus and further typing doesn't work unless it's manually clicked for...
Read more >
TextBox.LostFocus event (Access) - Microsoft Learn
In this article​​ The LostFocus event occurs when the specified object loses the focus.
Read more >
TextBox loses focus after typing a letter in UI for Blazor - Telerik
The TelerikTextBox losing focus after each keystroke appears to be a side-effect of the implementation. This is probably happening because the ...
Read more >
https://public.ukp.informatik.tu-darmstadt.de/emnl...
If I am in the terminal and then decide I want to open a web page, I switch to Space 2, where the...
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