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

[BUG] keyup events get lost when React app is re-rendered on keydown #187

Closed
greena13 opened this issue Jun 2, 2019 · 1 comment
Closed

Comments

@greena13
Copy link
Owner

greena13 commented Jun 2, 2019

Describe the bug

When an React application has an action bound to the keydown event of a particular key and a handler for that action that causes the React application to re-render in such a way that there are temporarily no <HotKeys /> components mounted when the keyup event occurs, then the keyup event goes unregistered and react-hotkeys continues to act as if that the key is still held down.

This issue has been uncovered by #186: Now submatches are ignored by default, react-hotkeys thinking the first key is still held down prevents any future key combinations being correctly matched.

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc)

import { React }, { Component } from 'react';
import { HotKeys } from 'react-hotkeys';

class MyComponent extends Component {
  constructor(props, context) {
    super(props, context);
    
    this.state = {
      tab: 0
    }
  }

  renderActiveTab() {
    const { tab } = this.state;
    
    if (tab === 0) {
      return (
        <HotKeys 
          keyMap={{ NEXT: 'n' }} 
          handlers={{ NEXT: () => this.setState({tab: tab+1}) }}
          >
          <div>
            Tab 1
          </div>
        </HotKeys>      
      );
    } else {
      return (
        <HotKeys 
          keyMap={{ NEXT: 'n', PREVIOUS: 'p' }} 
          handlers={{
            PREVIOUS: () => this.setState({tab: tab-1}),
          }}
          >
          <div>
            Tab 1
          </div>
        </HotKeys>
      );
    }
  }
  
  render () {
    return (
      <div>
        { this.renderActiveTab() }
      </div>      
    );
  }
}
@greena13
Copy link
Owner Author

greena13 commented Jun 2, 2019

Fix should be available in v2.0.0-pre7.

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

1 participant