Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Fix #256: Change popup width in overflow menu #271

Merged
merged 3 commits into from
Nov 21, 2018

Conversation

biancadanforth
Copy link
Collaborator

@biancadanforth biancadanforth commented Nov 15, 2018

With CustomizableUI.jsm (via the experimental browser.customizableUI API added in #157), it is possible to detect when the browserAction toolbar button is and is not in the Overflow menu.

Because the overflow menu width varies by OS (for example, it is 377px wide on my Mac 10.13 and 425px wide on a Linux 14.04 (see screenshots below for confirmation)), this patch will detect whether or not the toolbar button is in the Overflow menu and adjust the width accordingly.

This fix has the added benefit of allowing us to constrain the non-Overflow menu popup width (which is hopefully the vast majority use case) to the UX spec of 320px where previously we had set it to a max-width of 400px to try to accommodate Overflow menu issues.

Verified issue on Linux 14.04 (v11.0.0 prior to this patch!) in Firefox Nightly 65 and Release 63 shows that the popup width exceeds our CSS specified max-width of 400px
256-overflow-menu
256-overflow-menu-2

@biancadanforth
Copy link
Collaborator Author

@Osmose Ready for your review!

I confirmed that the issue was that the overflow menu on Linux exceeds 400px. It was 425px, so our previous max-width of 400px was too small.

Copy link
Contributor

@Osmose Osmose left a comment

Choose a reason for hiding this comment

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

screen shot 2018-11-15 at 5 01 41 pm

The fix doesn't seem to work for me locally on Nightly. The overflow class isn't being applied, presumably because the API call isn't returning true when the icon is in the overflow menu.

@@ -5,6 +5,7 @@

this.customizableUI = class extends ExtensionAPI {
getAPI(context) {
const {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not need to pass an empty object as the second argument like the other import?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope; I will remove the second argument from the other one. Good catch.

@@ -5,6 +5,7 @@

this.customizableUI = class extends ExtensionAPI {
getAPI(context) {
const {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
ChromeUtils.import('resource://gre/modules/ExtensionCommon.jsm');
const {EventManager} = ExtensionCommon;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not part of this PR, but this seems weirdly formatted compared to the other imports here.

{
"name": "isWidgetInOverflow",
"type": "function",
"description": "Returns a boolean for whether or not the provided widget in the provided window is in the overflow menu or not.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be more succinct if we avoid specifying that arguments are provided to the function:

"Determine whether or not a widget is in the overflow menu."

@biancadanforth
Copy link
Collaborator Author

biancadanforth commented Nov 16, 2018

@Osmose Ready for another look!

I had to add another check for the overflow menu in the case of pinning/unpinning (a "fixed" overflow menu), as it was only working on window resize (an "unfixed" overflow menu) which are apparently in two different (though proximate) areas of the chrome per jaws.

Edit: Even if this gets your approval, we probably don't want to merge until after #274 lands, I'm guessing, as a precaution?

Copy link
Contributor

@Osmose Osmose left a comment

Choose a reason for hiding this comment

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

Works great, nice job!

@@ -20,6 +20,12 @@ if (extractedProductJSON) {
appProps.extractedProduct = JSON.parse(extractedProductJSON);
}

(async function checkOverflow() {
if (await browser.customizableUI.isWidgetInOverflow('shopping-testpilot_mozilla_org-browser-action')) {
document.getElementById('browser-action-app').classList.add('overflow');
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, maybe we could put this into one of the React components, like in the state for BrowserActionApp? Not sure if that adds much to this.

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 tried to do this just now, but <BrowserActionApp /> currently returns a <React.Fragment>, which doesn't accept a class name. Wrapping the whole thing in a <div> instead and adding the class to that is possible, but then the CSS also needs another layer instead of applying the overflow class directly to #browser-action-app:

#browser-action-app > div {
  width: 320px;
}

#browser-action-app > div.overflow {
  width: 100%;
}

Also with the new Study Invitation screen (#274 ), I'd need that wrapper div in two places in BrowserActionApp instead of just one.

I also tried putting the class name directly on <BrowserActionApp /> in index.jsx, but ReactDOM.render didn't like the await keyword needed for browser.customizableUI.isWidgetInOverflow.

I think for simplicity, I'll just leave this as is for now. Perhaps we can refactor this later if we ever implement the view router pattern you suggested here... The options I can think of/try right now seem more confusing and more prone to bugs.

// First check is for the non-fixed overflow menu (e.g. widget moved by resizing window)
// Second is for fixed overflow menu (e.g. widget moved by (un)pinning button to overflow)
return (CustomizableUI.getWidget(widgetId).forWindow(browserWindow).overflowed
|| area === 'widget-overflow-fixed-list');
Copy link
Contributor

Choose a reason for hiding this comment

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

This becomes slightly more readable IMO if we format this like this:

return (
  CustomizableUI.getWidget(widgetId).forWindow(browserWindow).overflowed
  || area === 'widget-overflow-fixed-list'
);

With CustomizableUI.jsm (via the experimental `browser.customizableUI` API added in mozilla#157), it is possible to detect when the browserAction toolbar button is and is not in the Overflow menu.

Because the overflow menu width varies by OS (for example, it is 377px wide on my Mac 10.13 and 425px wide on a Linux 14.04), this patch will detect whether or not the toolbar button is in the Overflow menu and adjust the width accordingly.

This fix has the added benefit of allowing us to constrain the non-Overflow menu popup width (which is hopefully the vast majority use case) to the UX spec of 320px where previously we had set it to a max-width of 400px to try to accomodate Overflow menu issues.
…w menu

Detect toolbar button in fixed overflow menu:
- Add a call to `getPlacementOfWidget`
- This check covers the case when the toolbar button is explicitly pinned/unpinned to the Overflow menu by the user.

Context:
- The original patch only detected the toolbar button in the non-fixed overflow menu, which only covered the case when the toolbar button was moved into and out of the overflow menu by a window resize.
- Per jaws, the fixed versus non-fixed Overflow menus live in two different areas of the browser chrome, where "the non-fixed overflow panel is the area that is basically an extension of the navigation-toolbar."
- With both checks together, we cover both of the cases in which the toolbar button can be moved into and out of the Overflow menu.
@biancadanforth biancadanforth merged commit 5867e5e into mozilla:master Nov 21, 2018
@biancadanforth biancadanforth deleted the 256-overflow-width branch November 21, 2018 01:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants