React-table: Resizing with useResizeColumns can trigger sorting when use with useSortBy

Created on 22 May 2020  路  5Comments  路  Source: tannerlinsley/react-table

Describe the bug (required)
Mouse events on resize objects propagate upwards to the containing elements, meaning they can trigger sort events also attached to header cells.

Provide an example via Codesandbox! (required)
https://codesandbox.io/s/amazing-dream-x4iyw

Steps To Reproduce (required)
Steps to reproduce the behavior:

  1. Resize "First Name" column.
  2. note the column sorting changes

Expected behavior (Recommended)
mouseDown events captured in the resize object props should call stopPropagation so the sorting (and other) props can be attached to the resize parent elements without triggered on resize.

Most helpful comment

Or even: Place the sortBy props on the text, not the entire cell.

All 5 comments

@krashdifferent The getResizerProps() prop getter only returns onMouseDown and onTouchStart. To fix this issue, an onClick would also have to stop the propagation (I know that that's what you probably meant by saying 'mousDown events', just wanted to clarify).

Does anyone know a workaround for this? :)

i moved out the resizer out of the cell as a quick fix. https://codesandbox.io/s/brave-sanne-6o1mg

Another simple work around, add an onClick handler to the resizer that calls stopPropagation:

<div className={classes.resizer} {...column.getResizerProps({onClick(ev){ev.stopPropagation()}})} />

Or even: Place the sortBy props on the text, not the entire cell.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krishna-shenll picture krishna-shenll  路  3Comments

Codar97 picture Codar97  路  3Comments

dwjft picture dwjft  路  3Comments

ocalde picture ocalde  路  3Comments

bdkersey picture bdkersey  路  3Comments