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

Explain event handlers and capturing #13877

Closed
wants to merge 2 commits into from

Conversation

timeowilliams
Copy link
Contributor

Summary

Added statement about how the capture process within event lifecycles is optional.

Motivation

To allow readers of the documentation get a better grasp of the three stages and what is/not optional.

Supporting details

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#bubbling_and_capturing_explained
#13749

Related issues

Fixes #13749

Metadata

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

@timeowilliams timeowilliams requested a review from a team as a code owner March 15, 2022 04:13
@timeowilliams timeowilliams requested review from sideshowbarker and removed request for a team March 15, 2022 04:13
@github-actions github-actions bot added the Content:Learn Learning area docs label Mar 15, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2022

Preview URLs

Flaws

URL: /en-US/docs/Learn/JavaScript/Building_blocks/Events
Title: Introduction to events
on GitHub
Flaw count: 1

  • broken_links:
    • Can't resolve https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

External URLs

URL: /en-US/docs/Learn/JavaScript/Building_blocks/Events
Title: Introduction to events
on GitHub

(this comment was updated 2022-03-26 07:06:30.971606)

@teoli2003
Copy link
Contributor

@OndeVai, can you review this?

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I think it would be better to have this after

In modern browsers, by default, all event handlers are registered for the bubbling phase.
So in our current example, when you select the video, the event bubbles from the `<video>` element outwards to the `<html>` element.
Along the way:
- It finds the `click` handler on the `video` element and runs it, so the video first starts playing.
- It then finds the `click` handler on the `videoBox` element and runs that, so the video is hidden as well.
, which talks about bubbling being the default.

I think it could also be more precise, something like:

In modern browsers, by default, event handlers are not registered for the capturing phase. To register an event handler for the capturing phase, instead of the bubbling phase, pass the useCapture argument or the capture option to addEventListener().

@sideshowbarker sideshowbarker removed their request for review March 22, 2022 02:39
Copy link
Contributor Author

@timeowilliams timeowilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressing requested changes

@timeowilliams timeowilliams requested a review from wbamberg March 26, 2022 07:05
@wbamberg
Copy link
Collaborator

Thanks for the update!

This section:

In modern browsers, by default, all event handlers are registered for the bubbling phase. So in our current example, when you select the video, the event bubbles from the

  • It finds the click handler on the video element and runs it, so the video first starts playing.
  • It then finds the click handler on the videoBox element and runs that, so the video is hidden as well.

...is talking about the bubbling phase. By splicing stuff about capturing in, it doesn't make sense any more.

I think the part about enabling capturing should go after this, like:

In modern browsers, by default, all event handlers are registered for the bubbling phase. So in our current example, when you select the video, the event bubbles from the

  • It finds the click handler on the video element and runs it, so the video first starts playing.
  • It then finds the click handler on the videoBox element and runs that, so the video is hidden as well.

In modern browsers, by default, event handlers are not registered for the capturing phase. To register an event handler for the capturing phase, instead of the bubbling phase, pass the useCapture argument or the capture option to addEventListener().

Also, when your edit says "*Generally when event handlers are added to HTML code" - what work is "Generally" doing here? Usually when I see this word I think it means "usually but not always", and in documentation this makes me think, "when isn't it?" and if the documentation doesn't go on to explain that case, then I am left confused.

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested in #13877 (comment).

@sideshowbarker
Copy link
Member

@timeowilliams This seems to be waiting on your response to #13877 (comment)

@Josh-Cena Josh-Cena changed the title Resolve #13749 Explain event handlers and capturing Jul 22, 2022
@Josh-Cena Josh-Cena added the awaiting response Awaiting for author to address review/feedback label Aug 9, 2022
@wbamberg
Copy link
Collaborator

Closing in favour of #20013.

@wbamberg wbamberg closed this Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Awaiting for author to address review/feedback Content:Learn Learning area docs
Projects
None yet
5 participants