improve keyboard navigation with escape to close

main
Mike Fix 6 years ago committed by Michael Fix
parent 357dbe5942
commit f7a73b568a

@ -38,6 +38,8 @@ class BackgroundSelect extends React.PureComponent {
selected={isVisible}
className={`bg-select-display ${isVisible ? 'is-visible' : ''}`}
onClick={toggleVisibility}
background="white"
hoverBackground="white"
>
<div className="bg-color-alpha" />
<div className="bg-color" />

@ -15,6 +15,20 @@ export const managePopout = WrappedComponent => {
handleClickOutside = () => this.setState({ isVisible: false })
handleKeyDown = e => {
if (e.key === 'Escape') {
this.handleClickOutside()
}
}
componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown)
}
componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeyDown)
}
render() {
return (
<WrappedComponent

Loading…
Cancel
Save