hotkeys-js icon indicating copy to clipboard operation
hotkeys-js copied to clipboard

After upgrading to 3.5.0 propagating event is broken

Open RohovDmytro opened this issue 5 years ago • 6 comments

I have an HTML element handler from which I am stopping event from bubbling up. Depsite of that hotkeys stills catches up the event handling and executes its callback.

3.4.4 does not have this issue.

Some code.

<Editor
          autoCorrect={false}
          autoFocus={false}
          id={key}
          onChange={onChangeWithKey}
          onDrop={onDrop}
          onKeyDown={onKeyDown}
          renderNode={renderNode}
          spellCheck={false}
          value={editor}
        />
const onKeyDown = (event, editor, next) => {
      // key down + shift
      if (
        event.keyCode === 40 &&
        hotkeys.isPressed('shift')
      ) {
        editor.deselect();
        console.log('PREVENTING');
        event.preventDefault();
        event.stopPropagation();
        onSelectionInitDown({ key });
        return false;
      }
      return next();
    };
useHotkeys('shift+down', (evn, handler) => {
   
    dispatch({
      type: 'SELECTION_MOVE_DOWN'
    });
  });

RohovDmytro avatar Mar 22 '19 08:03 RohovDmytro

https://github.com/jaywcjlove/hotkeys/blob/c48a2d4a23a8b8e95188952f5e0486eb69c5fcc2/src/main.js#L197-L203

event.type === 'keydown' || (event.type === 'keyup' && asterisk[i].keyup)

Callback execution I added the judgment condition.

@rogovdm

jaywcjlove avatar Mar 22 '19 11:03 jaywcjlove

@rogovdm Give me an example? E.g. https://codepen.io/jaywcjlove/pen/eXjPdO

jaywcjlove avatar Mar 22 '19 11:03 jaywcjlove

Maybe it has something todo with the new keyup option that didn't work. I had to rollback to 3.4.4. otherwise you have double trigger (@jaywcjlove you can take your code pen and add a console log on. with 3.4.4 it's good with 3.5.0 it will log twice)

peernohell avatar Mar 22 '19 16:03 peernohell

@peernohell This is a new feature. https://github.com/jaywcjlove/hotkeys/issues/57

jaywcjlove avatar Mar 22 '19 16:03 jaywcjlove

@peernohell This is a new feature. #57

Nice try! But, except if I didn't understand your code here https://github.com/jaywcjlove/hotkeys/blob/master/src/main.js#L247, it's default to false so if you just change the version of hotkeys in the exemple it should have the default behevior and should not send keydown and keyup. Also, if you try to change the binding to add the option { keyup: false } it's didn't change anything and continue to send both event keyup and keydown. In doubt I have also try to set it to true but it didn't change anything. You can take a look to this codepen https://codepen.io/peernohell/pen/BbMegQ?editors=1111

peernohell avatar Mar 24 '19 21:03 peernohell

@peernohell thx! problem solved. Please to [email protected] to gitve it a try.

https://codepen.io/jaywcjlove/pen/XGGWzQ

jaywcjlove avatar Mar 25 '19 02:03 jaywcjlove