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

[Bug 1885504] Improve automatic click events for nested elements #1895

Merged
merged 5 commits into from
Mar 20, 2024

Conversation

abhi-agg
Copy link
Contributor

@abhi-agg abhi-agg commented Mar 18, 2024

Fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1885504

Pull Request checklist

  • Quality: Make sure this PR builds and runs cleanly.
    • Inside the glean/ folder, run:
      • npm run test Runs all tests
      • npm run lint Runs all linters
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry to CHANGELOG.md or an explanation of why it does not need one
  • Documentation: This PR includes documentation changes, an explanation of why it does not need that or a follow-up bug has been filed to do that work

@auto-assign auto-assign bot requested a review from travis79 March 18, 2024 13:43
@abhi-agg abhi-agg marked this pull request as draft March 18, 2024 13:44
@abhi-agg abhi-agg changed the title Improve automatic click events for nested elements [Bug 1885504] Improve automatic click events for nested elements Mar 18, 2024
@abhi-agg abhi-agg marked this pull request as ready for review March 18, 2024 17:20
@auto-assign auto-assign bot requested a review from Dexterp37 March 18, 2024 17:20
@Dexterp37 Dexterp37 removed their request for review March 18, 2024 17:25
abhi-agg added a commit to abhi-agg/glean-dictionary that referenced this pull request Mar 18, 2024
abhi-agg added a commit to abhi-agg/debug-ping-view that referenced this pull request Mar 18, 2024
 - Glean click events: Remove pointer-events:none for nested elements
abhi-agg added a commit to abhi-agg/debug-ping-view that referenced this pull request Mar 18, 2024
 - Glean click events: Remove pointer-events:none for nested elements
@abhi-agg
Copy link
Contributor Author

Tested this change in following apps:

  1. Glean Debug Ping View: Please see Test https://github.com/mozilla/glean.js/pull/1895 debug-ping-view#164 for details
  2. Glean Dictionary: Please see Test https://github.com/mozilla/glean.js/pull/1895 glean-dictionary#2157 for details

With the approach proposed in this PR, I was able to remove pointer-events:none from all places in both these apps except one which is theme toggle button in Debug Ping View.

As per my understanding, the theme toggle button in Debug Ping View is a special case. As per the theme toggler code:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    {isDarkMode ? <SunIcon /> : <MoonIcon />}
</button>

This means, when the current theme is "dark", the document is:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    <SunIcon />
</button>

When user clicks the button to toggle the theme from "dark" to "light", the target of the click event becomes SunIcon and the document changes to:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    <MoonIcon />
</button>

As SunIcon detaches from the document, there is no ancestor of the SunIcon that has any of the data-glean-* attributes set.

Copy link
Contributor

@rosahbruno rosahbruno left a comment

Choose a reason for hiding this comment

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

I left a few comments here. Nothing too major, just a few callouts and different ways to do stuff.

glean/src/core/glean_metrics.ts Outdated Show resolved Hide resolved
glean/src/core/glean_metrics.ts Outdated Show resolved Hide resolved
glean/src/core/glean_metrics.ts Outdated Show resolved Hide resolved
glean/src/core/glean_metrics.ts Outdated Show resolved Hide resolved
glean/src/core/glean_metrics.ts Outdated Show resolved Hide resolved
 - Removed log statements
 - More concise constructClickEventContextForElement
@abhi-agg
Copy link
Contributor Author

Hey @rosahbruno Thanks a lot for review. I submitted new commits to address your comments 👍🏾

Btw, do you have any opinion on this 👇🏾 ?

With the approach proposed in this PR, I was able to remove pointer-events:none from all places in both these apps except one which is theme toggle button in Debug Ping View.

As per my understanding, the theme toggle button in Debug Ping View is a special case. As per the theme toggler code:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    {isDarkMode ? <SunIcon /> : <MoonIcon />}
</button>

This means, when the current theme is "dark", the document is:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    <SunIcon />
</button>

When user clicks the button to toggle the theme from "dark" to "light", the target of the click event becomes SunIcon and the document changes to:

<button style={{ all: 'unset', cursor: 'pointer' }} data-glean-label='Theme' onClick={toggleTheme}>
    <MoonIcon />
</button>

As SunIcon detaches from the document, there is no ancestor of the SunIcon that has any of the data-glean-* attributes set.

@rosahbruno
Copy link
Contributor

@abhi-agg

With the approach proposed in this PR, I was able to remove pointer-events:none from all places in both these apps except one which is theme toggle button in Debug Ping View.

I think this is fine. The theme toggle is a bit of an odd set up since it toggles between two separate components. I think having to use a small workaround for something like that still, as long as these changes fix other things, then it should be ok

@abhi-agg
Copy link
Contributor Author

Great. As I mentioned above, this change enables us to remove pointer-events:none from all places in both these apps except from theme toggle button in Debug Ping View. So, we are good to go.

Copy link
Contributor

@rosahbruno rosahbruno left a comment

Choose a reason for hiding this comment

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

LGTM, nice job

I tested this on the Glean samples/browser/web app and it is working as expected. I think we should add this by default to this sample project. I will make a bug and a PR for this since I already have it done.

@rosahbruno rosahbruno merged commit fc89e7f into mozilla:main Mar 20, 2024
5 of 6 checks passed
@abhi-agg
Copy link
Contributor Author

Thanks @rosahbruno 👍🏾

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants