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

fix(ButtonDropdown): add close event when Escape key is pressed (#1634) #1635

Merged
merged 3 commits into from Oct 1, 2019
Merged

fix(ButtonDropdown): add close event when Escape key is pressed (#1634) #1635

merged 3 commits into from Oct 1, 2019

Conversation

ftonato
Copy link
Contributor

@ftonato ftonato commented Oct 1, 2019

Hey there,

This pull-request add a small piece of code to close event when Escape key is pressed (#1634)

  • Bug fix
  • New feature
  • Chore
  • Breaking change
  • There is an open issue which this change addresses
  • I have read the CONTRIBUTING document.
  • My commits follow the Git Commit Guidelines
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Fixes #1634

@TheSharpieOne
Copy link
Member

Thanks for the PR.
I think a better place to make this change would be in part of the key down handler which handles when the key is on the button itself:

reactstrap/src/Dropdown.js

Lines 126 to 134 in dc0b8ae

if (this.getMenuCtrl() === e.target) {
if (
!this.props.isOpen
&& ([keyCodes.space, keyCodes.enter, keyCodes.up, keyCodes.down].indexOf(e.which) > -1)
) {
this.toggle(e);
setTimeout(() => this.getMenuItems()[0].focus());
}
}

maybe something like:

   if ( 
     !this.props.isOpen 
     && ([keyCodes.space, keyCodes.enter, keyCodes.up, keyCodes.down].indexOf(e.which) > -1) 
   ) { 
     this.toggle(e); 
     setTimeout(() => this.getMenuItems()[0].focus()); 
   } else if (this.props.isOpen && e.which === keyCodes.esc) {
     this.toggle(e); 
   } 

@TheSharpieOne TheSharpieOne merged commit 911d779 into reactstrap:master Oct 1, 2019
@TheSharpieOne
Copy link
Member

Awesome! Thanks again!

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

Successfully merging this pull request may close these issues.

Button dropdown does not close when Escape key is pressed
2 participants