Skip to content

Commit

Permalink
Don't scroll when pressing space on a focused canvas
Browse files Browse the repository at this point in the history
After reaching keypress, we should prevent further propagation.

Relates to #1741
  • Loading branch information
tronical committed Oct 28, 2020
1 parent f26c879 commit 4f1e7bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/platform_impl/web/stdweb/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ impl Canvas {
// viable/compatible alternative as of now. `beforeinput` is still widely
// unsupported.
self.on_received_character = Some(self.add_user_event(move |event: KeyPressEvent| {
// Supress further handling to stop keys like the space key from scrolling the page.
event.prevent_default();
handler(event::codepoint(&event));
}));
}
Expand Down
2 changes: 2 additions & 0 deletions src/platform_impl/web/web_sys/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ impl Canvas {
self.on_received_character = Some(self.common.add_user_event(
"keypress",
move |event: KeyboardEvent| {
// Supress further handling to stop keys like the space key from scrolling the page.
event.prevent_default();
handler(event::codepoint(&event));
},
));
Expand Down

0 comments on commit 4f1e7bd

Please sign in to comment.