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

Change icon: overlaid button to background image #462

Merged
merged 5 commits into from Aug 11, 2023
Merged

Conversation

Vinnl
Copy link
Collaborator

@Vinnl Vinnl commented Jan 27, 2023

This PR fixes #22, #80, #227, #253, #360, #358, #394, #397, #400, #429, #447, #454, #497, #509.

(For anyone coming across this PR: we'll still need to do some extensive testing to make sure this doesn't break commonly-used websites, so please be patient — it may still take a while to land.)

New feature description

This applies a new method of injecting the Relay icon that I prototyped a while ago; a helpful description of this method can be found here, by @czlucius who independently landed on the same approach.

With this method, we don't have to change the stacking order of the website, and thus should avoid a lot of issues where we break the website we're injecting in. It did require some extra work to stay accessible; we still inject a button that is visually hidden, but accessible to screen reader users and people who navigate using the keyboard. I've also modified the hover/focus state styling to make it easier. Scrolling with the menu open is no longer possible; I can probably re-enable that with a re-positioning scroll listener, but I feel like the user experience is probably fine if you dismiss the menu first, and should be better for performance.

Note that I carried over the code in src/js/other-websites/icon.js from the experimental extension I prototyped this in, so the code style might be a little different from the rest of the codebase - the experimental extension had TypeScript and helpers I've to rip out.

Screenshot (if applicable)

image

Screencast.from.2023-01-27.11-26-42.webm

image

image

image

image

image

image

image

image

How to test

Visit websites with the Relay icon, and make sure that everything looks and works OK.

Checklist

  • l10n changes have been submitted to the l10n repository, if any.
  • All acceptance criteria are met.
  • All UI revisions follow the coding standards, and use Protocol tokens where applicable (see /frontend/src/styles/tokens.scss).
  • Commits in this PR are minimal and have descriptive commit messages.

@Vinnl Vinnl added the web-compat This issue involves how the add-on interacts with a specific website label Jan 27, 2023
@Vinnl Vinnl self-assigned this Jan 27, 2023
Comment on lines +188 to +214
// When generating a new mask, `newRelayAddressResponse` contains a mask object
// with the `full_address` property. When selecting an existing mask,
// however, it only has the properties `address` and `currentDomain`, but
// `address` does contain the full address (i.e. including @mozmail.com):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I miss TypeScript :(

@Vinnl
Copy link
Collaborator Author

Vinnl commented Jan 31, 2023

Added two more features based on PM feedback:

  • Scrolling is no longer disabled, and the menu moves along with the icon on scroll: eb2c59c
  • If there's not enough space for the menu below the icon, and there is enough space on top, move the menu to the top: e5cfe23

Edit: also fixed some issues with metrics events being sent twice.

Copy link
Collaborator

@maxxcrawford maxxcrawford left a comment

Choose a reason for hiding this comment

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

This PR has been a long time coming! Thanks, @Vinnl (and @czlucius too!) We'll need to do some extensive testing across sites to confirm there's no major breakage, but this so less invasive from our current approach.

Approving with some nits/suggestions/questions!

One minor UI inconsistency to call-out:
The in-page menu has both rounded corners and a small tooltip pointing towards the input:
image

image

I called out in the code where I believe it would be set, if that helps?

Comment on lines +106 to +112
const detectedInputs = email_detector_ruleset
.against(domRoot)
.get("email")
.filter((node) => node.scoreFor("email") > 0.5)
.map((node) => node.element);

return typeEmailInputs.concat(detectedInputs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: Why this re-write?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was a generator function, where that didn't add much value as far as I could see (checking the commit log), while making it hard to pass around the list of email inputs. And then the rest was to make sure I actually understood what was going on here, and writing it myself was a good way to do so :) But happy to change it back to for loops if you prefer, now that I know what's going on :)

src/js/other-websites/fill_relay_address.js Show resolved Hide resolved
src/js/other-websites/icon.js Outdated Show resolved Hide resolved
Comment on lines 124 to 145
function intersectsRelayIcon(
element,
coords
) {
return element.clientWidth - coords.x <= 25 + 2 * getPaddingRight(element);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Add comment here explaining the math

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good callout. Updated for all such calculations: a628c53.

src/js/other-websites/icon.js Show resolved Hide resolved
src/js/other-websites/icon.js Show resolved Hide resolved
Comment on lines +167 to +186
iframe.src = browser.runtime.getURL("inpage-panel.html");
iframe.style.position = "absolute";
iframe.style.width = `${RELAY_INPAGE_MENU_WIDTH}px`;
iframe.style.maxWidth = `95vw`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Per my comment at the top of this review, I expect how the iframe is being initialized is where we would set the tip/rounded corners.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm crap, in my spike I added this icon inside the iframe. I'll have to do some rework to be able to add it here, since you can't add ::before elements (or other children) to an iframe, so all the positioning will have to be redone to apply to a wrapper div. Hopefully I can find some time for that next week.

(Btw, this PR does already have rounded corners, and as far as I can see they're the same size -4px- as the current implementation?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I've struggled with making this appear properly for a bit now (in particular, getting it to take up the right space and have a consistent size), and I can't seem to make it work. My proposal would be to go without the chevron for now - it's relatively clear that the icon is related to the icon, so I think not having it for now would be better than having the current buggy icon implementation. I'm going to ask QA to test this.

const onUnderlayClick = (_event) => {
closeMenu();
};
underlay.addEventListener("click", onUnderlayClick);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question/thought: Do we need any touchstart support for the Android version of this add-on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, as MDN mentions a bug in old Safari versions for click events, implying that they're supposed to fire, and StackOverflow says so. But I'm not sure how to verify - do you know if there's an easy way to test .xpi files on Firefox mobile?

Comment on lines 360 to 361
`, linear-gradient(to left, #f68fff ${
getPaddingRight(element) * 2 + 25
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Can you move #f68fff to a variable at the top of the file? I feel like this is hidden/buried CSS in this file that we'd want to better surface.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Extra suggestion: Move all/any CSS attributes to the top of the file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved all colors in 3722328. Not sure if there were additional properties you were thinking of? (Note that most styles are dynamically generated based on existing styles for a particular input element, so I can't just move them to the top as hardcoded strings.)

@Vinnl
Copy link
Collaborator Author

Vinnl commented Mar 10, 2023

@maxxcrawford I added cbde420 that fixes an issue where the spinner would never stop in Chrome - the commit message should explain more. Could you review that too, please? With that, I think that this might be ready to go.

Vinnl added 5 commits May 22, 2023 11:08
With this method, we don't have to change the stacking order of the
website, and thus should avoid a lot of issues where we break the
website we're injecting in. It did require some extra work to
stay accessible; we still inject a button that is visually hidden,
but accessible to screen reader users and people who navigate using
the keyboard. I've also modified the hover/focus state styling to
make it easier.

Note that I carried over the code in src/js/other-websites/icon.js
from the experimental extension I prototyped this in, so the code
style might be a little different from the rest of the codebase.
Whereas Firefox appears to unload the iframe when it is hidden,
Chrome seems to preserve it. Unfortunately, our iframe contents
currently assumes that it is unloaded (i.e. it only fetches data
when it gets loaded, and never stops loading animations after
inserting a mask), so when we kept the iframe in the DOM, that
would cause issues in Chrome. Hence, this change ensures that the
injected iframe gets destroyed whenever the menu is closed.
This re-applies 0447dca (from
#499) to the
new method of injecting the icon.
@Vinnl
Copy link
Collaborator Author

Vinnl commented May 22, 2023

Rebased to clean up commits and resolve confilcts - specifically, I reapplied #499 in e06c3ae.

There were also 056a91e#diff-6d657968b51497d6080c30b3704a5e0cbac32a4707fb358dd33955f628c5d192 and 9b31315#diff-59a5db4e9a139708113dc0d0e60807e300b556f19ce611a5ffaa4a764c83f14b, but as far as I could see those were concerned with setting a particular height for the in-page popup, which IIRC should get determined automatically after this PR.

@hecerinc
Copy link

@Vinnl just checking if there's plans to merge this any time soon. Looks like you have this approved? Is there a timeline set for this?

@Vinnl
Copy link
Collaborator Author

Vinnl commented Jul 28, 2023

@hecerinc I moved to work on Monitor and handed this over to other folks, but it looks like they haven't gotten around to releasing it yet. I'll bug some folks again to see if we can get this released :)

@lloan lloan merged commit bcbb044 into main Aug 11, 2023
3 checks passed
@lloan lloan deleted the MPP-2510-icon-refactor branch August 11, 2023 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web-compat This issue involves how the add-on interacts with a specific website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High z-index value for email field wrapper causes stacking issues
4 participants