-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[DataGridPro] Prevent text selection when reordering rows #16568
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
Conversation
Thanks for the contribution @jyash97 Also, can you use the approach used in cell selection to disable the selection? |
Hey @arminmeh Thanks for the review, give me sometime will apply the changes |
Hey @arminmeh I didnt get chance to look into these yet, I will try to get to these by Wednesday. |
@arminmeh after making the requested changes, I see the issue happening again, I can confirm that the root class is being applied properly. Didnt get chance to look further into these yet |
@jyash97 thanks for the update. I will take a quick look and check what is different from your initial solution. |
Awesome, looking forward to know what caused the regression. Looking forward to contribute more once I get some bandwidth |
83a0d8f
to
0385855
Compare
Deploy preview: https://deploy-preview-16568--material-ui-x.netlify.app/ |
The root cause for this behavior is that, when the text is selected, event happens on the I have tried other ways to prevent event on happening on the From the last update from @jyash97 I have only moved the class append/remove logic into the same file, and tweaked the styles to apply on all elements once appended (before it was only on the regular cells) |
[`&.${c['root--disableUserSelection']} .${c.cell}`]: { | ||
[`&.${c['root--disableUserSelection']}`]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a class for this? It feels more verbose than it needs to be, we could just set style.userSelect = '...'
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but since we already have this class, I don't mind using it in this scenario too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how did we handle this in the past. Can we remove a class in the minor release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have stopped applying styles to classes internally, but not removed. Perhaps we can add to #17846
Hi @jyash97 |
Hey @cherniavskii Can you check again? I might have missed it, I just filled the form |
@jyash97 can you please complete the step 3? - Forward the “form submission confirmation” email (check also your spam folder) to [email protected] to confirm your identity. Also, include the link to the pull request it corresponds to. Thanks. |
@cherniavskii CLA signed, thanks. |
packages/x-data-grid-pro/src/hooks/features/rowReorder/useGridRowReorder.tsx
Outdated
Show resolved
Hide resolved
const onMouseDown = React.useCallback(() => { | ||
// Prevent text selection as it will block all the drag events. More context: https://github.com/mui/mui-x/issues/16303 | ||
apiRef.current.rootElementRef?.current?.classList.add( | ||
gridClasses['root--disableUserSelection'], | ||
); | ||
}, [apiRef]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we remove this class on onMouseUp
?
onDragEnd
doesn't necessarily get fired after each onMouseDown
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
I did some testing and depending on the interaction, sometimes only onDragEnd
is called, sometimes only onMouseUp
and sometimes I see both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised onMouseUp
only sometimes fires 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember adding mouse up event to clear user selection, but was facing issue, don't remember the exact reason at the moment, but had to resort back to drag end event to clear it
718048d
to
4ad6412
Compare
[`&.${c['root--disableUserSelection']} .${c.cell}`]: { | ||
[`&.${c['root--disableUserSelection']}`]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but since we already have this class, I don't mind using it in this scenario too.
const onMouseDown = React.useCallback(() => { | ||
// Prevent text selection as it will block all the drag events. More context: https://github.com/mui/mui-x/issues/16303 | ||
apiRef.current.rootElementRef?.current?.classList.add( | ||
gridClasses['root--disableUserSelection'], | ||
); | ||
}, [apiRef]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised onMouseUp
only sometimes fires 🤔
Cherry-pick PRs will be created targeting branches: v7.x |
Co-authored-by: Armin Mehinovic <[email protected]>
Closes #16303
Debug Info on the same