asp.netblazortextselectiononmousedown

Blazor - turning off text selection when moving with mouse after mousedown event


I'm working on table in Blazor. I want to use mousedown and mouseup event to add posibility for selecting more cells in the table. When user holds mouse button, he can move and select cells until he release mouse button. Everything works fine, there is just one problem: together with selecting cells, I'm selecting every text, even outside of cells, which doesn't look good.

Is there any easy way in Blazor how to turn off the text selection after holding mouse button?

Thank you!


Solution

  • If you only want the text to be un-selectable while dragging the mouse (so the only way to select text if you do this would be with the keyboard)...

    In the onmousedown handler, change the CSS style of the table to user-select: none; and then remove that style in onmouseup.