Skip to content
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

Request: prevent dragging on custom handle #36

Closed
NeXTs opened this issue Jul 26, 2016 · 4 comments
Closed

Request: prevent dragging on custom handle #36

NeXTs opened this issue Jul 26, 2016 · 4 comments

Comments

@NeXTs
Copy link

NeXTs commented Jul 26, 2016

I need to implement table with column sorting and in addition to that - table headers should be sortable horizontally

For horizontal headers sorting I've used your great library
Now I need to handle column sorting by clicking arrows (you know, up|down arrows) inside every header row to sort ASC/DESC specific column.

To do this I need somehow cancel event propogation by clicking arrows so that react-sortable-hoc doesn't begin dragging. I've tried

<SortIcon onClick={(e) => {
    e.stopPropagation()
    e.preventDefault()
    onSortColumn(value.alias, users)
    return false
}}/>

but it does not prevent dragging :(

Is it possible?

@NeXTs
Copy link
Author

NeXTs commented Jul 26, 2016

Something like cancel from jQuery UI Draggable

@NeXTs NeXTs closed this as completed Jul 26, 2016
@NeXTs NeXTs reopened this Jul 26, 2016
@bvaughn
Copy link
Contributor

bvaughn commented Jul 27, 2016

One thing you could try would be to limit the draggable region in your table headers (useDragHandle == true) so that users could only drag when they click on a drag-handle (SortableHandle). Then you could treat a click-on-header-text as a vertical-sort action, and a click-on-drag-handle as a horizontal-sort action.

clauderic pushed a commit that referenced this issue Sep 5, 2016
… Prevent right click from causing sort start (#46)
@clauderic
Copy link
Owner

Just published 0.0.8 to npm with support for shouldCancelStart, which should solve most use cases. The implementation is up to you, though by default it will prevent sorting on text / select inputs. Alternatively, you could add a custom data-attribute to the elements you want to prevent from being sorted.

Here's the default implementation:

function shouldCancelStart(e) {
    // Cancel sorting if the event target is an `input`, `textarea`, `select` or `option`
    if (['input', 'textarea', 'select', 'option'].indexOf(e.target.tagName.toLowerCase()) !== -1) {
        return true; // Return true to cancel sorting
    }
}

@NeXTs
Copy link
Author

NeXTs commented Sep 5, 2016

thanks!

DimitarNestorov pushed a commit to codemotionapps/react-sortable-hoc that referenced this issue Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants