-
Notifications
You must be signed in to change notification settings - Fork 867
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
Add docs about how to get more fine-grained control of event.preventDefault() calls on web #3451
base: master
Are you sure you want to change the base?
Conversation
…efault() calls on web
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is great!
Let me know if you need any help with anything.
@@ -65,8 +65,76 @@ pub trait WindowExtWebSys { | |||
/// For example, by default using the mouse wheel would cause the page to scroll, enabling this | |||
/// would prevent that. | |||
/// | |||
/// Specifically, this will call `event.preventDefault()` for the following event types: | |||
/// `touchstart`, `wheel`, `contextmenu`, `pointerdown`, `pointermove`, `keyup`, and `keydown`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should mention that Event.preventDefault()
is only called for pointermove
in the case of a chorded button interaction.
I know this is getting even more into the weeds, but it might be important ...
/// This example calls `event.preventDefault()` for all relevant events except for ctrl-c, | ||
/// ctrl-x, and ctrl-v. | ||
/// ``` | ||
/// # fn add_prevent_default_listeners(canvas: HtmlCanvasElement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to actually make a full example with EventLoop::new()
and such.
Will be adding cross-compilation testing for rustdoc into the CI soon.
Doesn't need much, just create a Window
, use WindowBuilder::with_append()
and get the canvas.
/// # use wasm_bindgen::closure::Closure; | ||
/// # use wasm_bindgen::JsCast; | ||
/// let events_types_to_fully_prevent_default = | ||
/// ["touchstart", "wheel", "contextmenu", "pointermove"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we are it, we might want to handle the chorded button interaction for pointermove
.
/// This example calls `event.preventDefault()` for all relevant events except for ctrl-c, | ||
/// ctrl-x, and ctrl-v. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should pick a different example because I consider the whole preventing clipboard interactions a Winit bug.
E.g. ctrl-p
for printing? Maybe also hook up beforeprint
just to make the example complete.
Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
The example is a bit verbose, unfortunately, but I'm hoping it's relatively clear and it's also quite close to being directly useful.
See #2831 for more context.