Skip to content

Commit

Permalink
feat(tooltip): Close tooltip on keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanoglesby08 committed Oct 5, 2017
1 parent 49ede6b commit cd7916e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/Tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ class Tooltip extends React.Component {

componentDidUpdate() {
if (this.state.open) {
document.addEventListener('click', this.toggleBubble)
document.addEventListener('click', this.toggleBubbleOutsideOfTrigger)
document.addEventListener('keypress', this.toggleBubbleOutsideOfTrigger)
} else {
document.removeEventListener('click', this.toggleBubble)
document.removeEventListener('click', this.toggleBubbleOutsideOfTrigger)
document.removeEventListener('keypress', this.toggleBubbleOutsideOfTrigger)
}
}

toggleBubbleOutsideOfTrigger = event => {
if (event.target !== this.trigger) {
this.toggleBubble()
}
}

Expand Down Expand Up @@ -88,6 +96,9 @@ class Tooltip extends React.Component {
aria-controls={id}
aria-haspopup="true"
aria-expanded={this.state.open ? 'true' : 'false'}
ref={trigger => {
this.trigger = trigger
}}
>
<StandaloneIcon
symbol="questionMarkCircle"
Expand Down

0 comments on commit cd7916e

Please sign in to comment.