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

Click events within selectable component #54

Open
SamesJeabrook opened this issue Jul 19, 2018 · 5 comments
Open

Click events within selectable component #54

SamesJeabrook opened this issue Jul 19, 2018 · 5 comments

Comments

@SamesJeabrook
Copy link

Love this library, thanks so much for the hard work in it. I have a question around click events within a selectable component, in that unless you have a really steady hand it won't register the click event but instead will start drawing the bounding box.

I have previously got round this with JqueryUI by adding a "distance" attribute - one that I saw you had removed from version 1 - but not sure if its the same in that it would be the distance in pixels from when the mouse down event took place before it began drawing the bounding box. This enabled other events on the selectable item to fire.

Or have I missed something else in the docs or options that will enable the events?

@drkdelaney
Copy link

I'm running into this same issue. Im hoping there is a fix.

@drkdelaney
Copy link

drkdelaney commented Jul 23, 2018

I was able to determine that sometimes the mousemove event was getting called by the browser even though my mouse didn't move. I think adding a distance or drag tolerance prop would help. Temporarily I created my own NewSelectableGroup that extends SelectableGroup with my fix.

import { SelectableGroup } from 'react-selectable';

const DRAG_TOLERANCE = 5;

export default class NewSelectableGroup extends SelectableGroup {
    _openSelector(e) {
        const width = Math.abs(this._mouseDownData.initialW - e.pageX + this._rect.x);
        const height = Math.abs(this._mouseDownData.initialH - e.pageY + this._rect.y);

        if (width < DRAG_TOLERANCE && height < DRAG_TOLERANCE) return;

        this.setState({
            isBoxSelecting: true,
            boxWidth: width,
            boxHeight: height,
            boxLeft: Math.min(e.pageX - this._rect.x, this._mouseDownData.initialW),
            boxTop: Math.min(e.pageY - this._rect.y, this._mouseDownData.initialH),
        });

        if (this.props.selectOnMouseMove) this._throttledSelect(e);
    }
}

Then I just use <NewSelectableGroup>

Im happy to create a PR with this change if @unclecheese feels its a good solution.

@SamesJeabrook
Copy link
Author

Finally had chance to put this into practice and it works really well, click events are now operating without issue, but for me I had to include a clear of selection as when dragging under the tolerance I found that it highlighted elements on the page.

if(width < DRAG_TOLERANCE && height < DRAG_TOLERANCE){
	if(window.getSelection){
		window.getSelection().removeAllRanges();
	}else{
		document.selection.empty();
	}
	return;
}

@drkdelaney
Copy link

drkdelaney commented Jul 25, 2018

I used the css property user-select: none;on my SelectableComponent items that can be selected. That prevented highlighting for me.

@SamesJeabrook
Copy link
Author

Much better solution, should have thought of that first.

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

2 participants