Skip to content

Commit

Permalink
refactor(TooltipIcon): place keydown handler in useEffect block
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Jan 27, 2020
1 parent ef0ec93 commit 40443b1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/react/src/components/TooltipIcon/TooltipIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const TooltipIcon = ({
}
);
const handleFocus = () => setAllowTooltipVisibility(true);
const handleEscKeyDown = event => {
if (matches(event, [keys.Escape])) {
setAllowTooltipVisibility(false);
}
};
const handleMouseEnter = () => setAllowTooltipVisibility(true);
useEffect(() => {
const handleEscKeyDown = event => {
if (matches(event, [keys.Escape])) {
setAllowTooltipVisibility(false);
}
};
document.addEventListener('keydown', handleEscKeyDown);
return () => document.removeEventListener('keydown', handleEscKeyDown);
}, []);
Expand Down

0 comments on commit 40443b1

Please sign in to comment.