1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-24 07:06:34 +09:00

Prevent scrolling main frame when navigating in image gallery with arrow keys (#8073)

This commit is contained in:
ThibG 2018-07-26 04:50:50 +02:00 committed by Eugen Rochko
parent c9739ca86b
commit d199806969

View File

@ -54,19 +54,23 @@ export default class MediaModal extends ImmutablePureComponent {
this.setState({ index: index % this.props.media.size });
}
handleKeyUp = (e) => {
handleKeyDown = (e) => {
switch(e.key) {
case 'ArrowLeft':
this.handlePrevClick();
e.preventDefault();
e.stopPropagation();
break;
case 'ArrowRight':
this.handleNextClick();
e.preventDefault();
e.stopPropagation();
break;
}
}
componentDidMount () {
window.addEventListener('keyup', this.handleKeyUp, false);
window.addEventListener('keydown', this.handleKeyDown, false);
if (this.context.router) {
const history = this.context.router.history;
history.push(history.location.pathname, previewState);
@ -77,7 +81,7 @@ export default class MediaModal extends ImmutablePureComponent {
}
componentWillUnmount () {
window.removeEventListener('keyup', this.handleKeyUp);
window.removeEventListener('keydown', this.handleKeyDown);
if (this.context.router) {
this.unlistenHistory();