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} selected={isVisible}
className={`bg-select-display ${isVisible ? 'is-visible' : ''}`} className={`bg-select-display ${isVisible ? 'is-visible' : ''}`}
onClick={toggleVisibility} onClick={toggleVisibility}
background="white"
hoverBackground="white"
> >
<div className="bg-color-alpha" /> <div className="bg-color-alpha" />
<div className="bg-color" /> <div className="bg-color" />

@ -15,6 +15,20 @@ export const managePopout = WrappedComponent => {
handleClickOutside = () => this.setState({ isVisible: false }) 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() { render() {
return ( return (
<WrappedComponent <WrappedComponent

Loading…
Cancel
Save