Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ESC and clicking background to close full screen dialog #8697

Merged
merged 9 commits into from
Feb 1, 2018
42 changes: 31 additions & 11 deletions _inc/client/components/jetpack-dialogue/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,53 @@ import onKeyDownCallback from 'utils/onkeydown-callback';
import { imagePath } from 'constants/urls';

class JetpackDialogue extends Component {
maybeDismiss = ( e ) => {
if ( this.props.showDismiss && ( ! e.keyCode || e.keyCode === 27 ) ) {
this.props.dismiss( e );
}
}

// capture the ESC key globally
componentDidMount() {
document.addEventListener( 'keydown', this.maybeDismiss.bind( this ), false );
}

componentWillUnmount() {
document.removeEventListener( 'keydown', this.maybeDismiss.bind( this ), false );
}

// prevent foreground clicks going through to the background
clickForeground( e ) {
e.stopPropagation();
}

render() {
const classes = classNames(
this.props.className,
'jp-dialogue'
);
return (
<div className="jp-dialogue-full__container">
<div className="jp-dialogue-full__container" role="dialog" onClick={ this.maybeDismiss } onKeyDown={ onKeyDownCallback( this.maybeDismiss ) }>
<img src={ imagePath + 'stars-full.svg' } width="60" height="60" alt={ __( 'Stars' ) } className="jp-jumpstart-full__svg-stars" />
<img src={ imagePath + 'jupiter.svg' } width="50" height="100" alt={ __( 'Jupiter' ) } className="jp-jumpstart-full__svg-jupiter" />
{
this.props.showDismiss && <Gridicon
icon="cross-small"
className="jp-dialogue-full__dismiss"
tabIndex="0"
onKeyDown={ onKeyDownCallback( this.props.dismiss ) }
onClick={ this.props.dismiss }
/>
}

<div className={ classes }>
<div className={ classes } role="dialog" onClick={ this.clickForeground } onKeyDown={ onKeyDownCallback( this.clickForeground ) }>
{ this.props.svg }

<h1 className="jp-dialogue__title">
{ this.props.title }
</h1>

<Card>
{
this.props.showDismiss && <Gridicon
icon="cross-small"
className="jp-dialogue-full__dismiss"
tabIndex="0"
onKeyDown={ onKeyDownCallback( this.props.dismiss ) }
onClick={ this.props.dismiss }
/>
}
{ this.props.content }
</Card>
<div>
Expand Down
4 changes: 2 additions & 2 deletions _inc/client/components/jetpack-dialogue/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
.jp-dialogue-full__dismiss {
cursor: pointer;
position: absolute;
right: 0;
top: 0;
right: -10px;
top: -10px;
fill: $gray;
padding: rem( 16px );
height: rem( 24px );
Expand Down