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

Inverse Selection in Responsive Mode #68

Open
skh- opened this issue Jan 25, 2020 · 6 comments
Open

Inverse Selection in Responsive Mode #68

skh- opened this issue Jan 25, 2020 · 6 comments

Comments

@skh-
Copy link

skh- commented Jan 25, 2020

Thanks for this nice library!

react-selectable-fast seems to select the inverse items when in responsive design mode in chrome. I am not sure if this is an effect of a setting or something else I'm unaware of, but it seems like strange behaviour.

https://i.gyazo.com/c78f555aa8dee2b26e0c1e2125f3fa4d

@bpmct
Copy link

bpmct commented Jul 2, 2020

@skh- were you able to fix this? I am experiencing the same thing on mobile (touch) devices occasionally?

@skh-
Copy link
Author

skh- commented Jul 2, 2020

sorry, no. i ended up building something custom for my specific requirements.

@shaaandi
Copy link

@bpmct Hi Ben, So are you able to resolve this with some tricks?

@bpmct
Copy link

bpmct commented Jul 28, 2020 via email

@meth0xy
Copy link

meth0xy commented Apr 14, 2021

Found a Workarround: mapping TouchEvents to MouseEvents and it works.

const touchHandler = (event: TouchEvent) => {
    var touches = event.changedTouches,
        first = touches[0],
        type = '';
    switch (event.type) {
        case 'touchstart':
            type = 'mousedown';
            break;
        case 'touchmove':
            type = 'mousemove';
            break;
        case 'touchend':
            type = 'mouseup';
            break;
        default:
            return;
    }

    const simulatedEvent = document.createEvent('MouseEvent');
    simulatedEvent.initMouseEvent(
        type,
        true,
        true,
        window,
        1,
        first.screenX,
        first.screenY,
        first.clientX,
        first.clientY,
        false,
        false,
        false,
        false,
        0 /*left*/,
        null,
    );

    first.target.dispatchEvent(simulatedEvent);
    event.preventDefault();
};

const addTouchListener = (): void => {
    document.addEventListener('touchstart', touchHandler, true);
    document.addEventListener('touchmove', touchHandler, true);
    document.addEventListener('touchend', touchHandler, true);
    document.addEventListener('touchcancel', touchHandler, true);
};

const removeTouchListener = (): void => {
    document.removeEventListener('touchstart', touchHandler, true);
    document.removeEventListener('touchmove', touchHandler, true);
    document.removeEventListener('touchend', touchHandler, true);
    document.removeEventListener('touchcancel', touchHandler, true);
};

export {removeTouchListener, addTouchListener};

@wdjennings
Copy link

Hi all! I investigated this a bit, seems like these lines in SelectableGroup lead to pageX and pageY being undefined:

const evt: any = castTouchToMouseEvent(event)    
const { pageX, pageY } = evt

This in turn causes the handleClick(evt, pageY, pageX) event to be called with undefined values for pageX and pageY:

handleClick(evt, top, left) {
   ...
}

Since top and left are undefined, seems like ALL items get selected. Should be easy to fix with a simple check. Please do anyone feel free to make a PR for this -- although might be quicker for anyone who wants it to do it locally themselves.

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

5 participants