-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When Draggable unmounts, if a textbox is focused, the textbox loses focus inexplicably #315
Comments
Temporary workaround is to only render the Draggable when the component I care about is hovered, or only when the textbox is not focused. But both of those have flaws. BTW this happens so consistently in our application that, without this workaround, we would not be able to use React Draggable in our application. |
Looks like it is an issue in the 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 Working: https://codesandbox.io/s/944j9x101o |
Hmm. The user-select hack is necessary to ensure we don't start dragging text all over the page when using the draggable, but calling it on |
I resolved it by adding :
on and
in style.css. Thanks for your comment about enableUserSelectHack, it helped ! |
Thank you guys! |
Not directly related to the focus issue, but I have had a rare selection bug: Should we somehow improve current |
Fixed in v3.3.2. |
@STRML Is it possible that this problem still exists in v.4.0.3? Use case: I have a list of draggable items and I want to search in this list. When the list rerenders, the search field loses focus. |
When react-draggable's Draggable component unmounts, it causes text inputs to lose focus. These changes add a workaround for this problem: react-grid-layout/react-draggable#315
I'm also still having related issues using the latest release. Adding |
Yeah, I'm not sure how the change in 3.3.2 is supposed to fix this issue. The de-focusing is caused by the Modifying react-draggable to check selection.type would fix it: const selection = window.getSelection();
if (selection && selection.type !== 'Caret') {
selection.removeAllRanges();
} Tested this change locally with
|
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:
onBlur
handlers are called, and if I switch tabs / windows and then switch back, focus is restoredHere'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.
The text was updated successfully, but these errors were encountered: