table icon indicating copy to clipboard operation
table copied to clipboard

Prevent text selection on column resize

Open therahl opened this issue 9 years ago • 6 comments

Problem Description

When resizing columns, if the mouse is dragged away from the column name, the cursor changes and text is selectable. Once the text is selected, resizing is broken.

Steps to Reproduce

  1. Resize a column by dragging
  2. While dragging, move mouse downward
  3. Observe text being selected
  4. Release drag, and then attempt to resize again.

http://g.recordit.co/UEPT2gLvwl.gif

Ideally, the cursor would remain as col-resize throughout the resizing action and the text should not be selected.

therahl avatar Apr 26 '17 19:04 therahl

Noted. Will be fixed in next version. Unfortunately there is not much of a workaround right now without overriding almost all of the resize handling. The next version will also add a class to the entire table when resizing which could then be used to address other styling needs when the table is resizing columns.

aaronschwartz avatar Apr 26 '17 20:04 aaronschwartz

Hi @aaronschwartz, I notice that this issue is present in v7.7.0.

Kapture 2021-05-11 at 00 03 12

Is there a workaround to prevent this from happening?

archit-p avatar May 10 '21 18:05 archit-p

@archit-p Unfortunately this issue and resolution is over 4 years old and applied to version 6 of react-table. Version 7 is a completely new library and anything that is v6 related is irrelevant to the new headless approach. Luckily, the headless approach allows much more flexibility with controlling the styling yourself.

I don't have an exact answer for you, but the approach would be to check if the table isResizing and to apply some css user-select: none so that the user cannot select text while resizing the table.

This is likely solvable as-is with v7.7.0, but if you're still having trouble you would have to open a new issue for the current version of react-table or I can help with some more details when I have time.

aaronschwartz avatar May 10 '21 19:05 aaronschwartz

Thanks for the tip @aaronschwartz!

I ended up using a function to check whether any of the table's columns were resizing.

function isTableResizing() {
    for (let headerGroup of headerGroups) {
      for (let column of headerGroup.headers) {
        if (column.isResizing) {
          return true;
        }
      }
    }
 
    return false;
  }

This is working flawlessly!

archit-p avatar May 11 '21 12:05 archit-p

Thanks for the tip @aaronschwartz!

I ended up using a function to check whether any of the table's columns were resizing.

function isTableResizing() {
    for (let headerGroup of headerGroups) {
      for (let column of headerGroup.headers) {
        if (column.isResizing) {
          return true;
        }
      }
    }
 
    return false;
  }

This is working flawlessly!

Nice! For me adding user-select: none directly to the ths seems to stop the selection from happening, even for rows below, example:

{headerGroup.headers.map((column) => {
  return (
    <div  {...column.getHeaderProps()} className={`th ${column.isResizing ? "--resizing" : ""}`}>
      {column.render("Header")}
      <div  {...column.getResizerProps()} className="column-resizer" />
    </div>
  );
})}
.resizing { user-select: none }

PabloCorso avatar Aug 13 '21 14:08 PabloCorso

Thanks for the tip @aaronschwartz! I ended up using a function to check whether any of the table's columns were resizing.

function isTableResizing() {
    for (let headerGroup of headerGroups) {
      for (let column of headerGroup.headers) {
        if (column.isResizing) {
          return true;
        }
      }
    }
 
    return false;
  }

This is working flawlessly!

Nice! For me adding user-select: none directly to the ths seems to stop the selection from happening, even for rows below, example:

{headerGroup.headers.map((column) => {
  return (
    <div  {...column.getHeaderProps()} className={`th ${column.isResizing ? "--resizing" : ""}`}>
      {column.render("Header")}
      <div  {...column.getResizerProps()} className="column-resizer" />
    </div>
  );
})}
.resizing { user-select: none }

This is actually simpler than what I did. But I wanted to stop selection on the entire table, if any of the columns were resizing. Hence went with the function to check and apply classes directly to the table.

archit-p avatar Sep 01 '21 00:09 archit-p