glennflanagan / react-collapsible

React component to wrap content in Collapsible element with trigger to open and close.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

handleTriggerClick fires twice when triggerTagName set to "button" and space bar is used

erinrep opened this issue · comments

Describe the bug
When using the component while triggerTagName is set to "button", hitting the space bar while the button is in focus results in unexpected behavior. The space bar will fire the onClick event for a button, but since the onKeyPress event is also looking for the space bar, handleTriggerClick gets called twice.

To Reproduce
Steps to reproduce the behavior:

JSFiddle Example

  1. Tab to the trigger button
  2. Press the space bar
  3. The collapsible will open
  4. Press the space bar again
  5. The collapsible will not close

Expected behavior
Pressing the space bar while the button is in focus will open and close the collapsible as expected

Screenshots
spaceBar