| 61 | |
| 62 | useEffect(() => { |
| 63 | let onKeyDown = e => { |
| 64 | if (ref && ref.current) { |
| 65 | // Escape after clicking something can give it keyboard focus |
| 66 | // dismiss tooltip on esc key press |
| 67 | if (e.key === 'Escape') { |
| 68 | e.stopPropagation(); |
| 69 | state.close(true); |
| 70 | } |
| 71 | } |
| 72 | }; |
| 73 | if (state.isOpen) { |
| 74 | document.addEventListener('keydown', onKeyDown, true); |
| 75 | return () => { |