]> cat aescling's git repositories - mastodon.git/commitdiff
Prevent scrolling main frame when navigating in image gallery with arrow keys (#8073)
authorThibG <thib@sitedethib.com>
Thu, 26 Jul 2018 02:50:50 +0000 (04:50 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 26 Jul 2018 02:50:50 +0000 (04:50 +0200)
app/javascript/mastodon/features/ui/components/media_modal.js

index 6af0a101c9f17a323e7a934dec2ee4e23300a6e6..12db95326264509cf638105e8a4f90b95f74dd39 100644 (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();