Commit 84f3f0db authored by Aditya Kolla's avatar Aditya Kolla Committed by Tasso Evangelista

[IMPROVE] Dismiss Popover with escape key (#169)

parent dd39dc33
No preview for this file type
......@@ -41,7 +41,7 @@ export class PopoverContainer extends Component {
this.setState({ renderer: null, overlayBounds: null, triggerBounds: null });
}
handleDismiss = ({ currentTarget, target }) => {
handleOverlayGesture = ({ currentTarget, target }) => {
if (currentTarget !== target) {
return;
}
......@@ -49,18 +49,36 @@ export class PopoverContainer extends Component {
this.dismiss();
}
handleKeyDown = ({ key }) => {
if (key !== 'Escape') {
return;
}
this.dismiss();
}
handleOverlayRef = (ref) => {
this.overlayRef = ref;
}
componentDidMount() {
this.mounted = true;
window.addEventListener('keydown', this.handleKeyDown, false);
}
componentWillUnmount() {
this.mounted = false;
window.removeEventListener('keydown', this.handleKeyDown, false);
}
render = ({ children }, { renderer, overlayProps, overlayBounds, triggerBounds }) => (
<PopoverContext.Provider value={{ open: this.open }}>
<div className={createClassName(styles, 'popover__container')}>
{children}
<PopoverOverlay
ref={this.handleOverlayRef}
onMouseDown={this.handleDismiss}
onTouchStart={this.handleDismiss}
onMouseDown={this.handleOverlayGesture}
onTouchStart={this.handleOverlayGesture}
visible={!!renderer}
{...overlayProps}
>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment