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

report: close drop down menu when focus is lost #10208

Merged
merged 3 commits into from
Jan 14, 2020
Merged

report: close drop down menu when focus is lost #10208

merged 3 commits into from
Jan 14, 2020

Conversation

johnemau
Copy link
Contributor

@johnemau johnemau commented Jan 10, 2020

Summary

Problem

The report drop down menu does not close when the escape key
is pressed in the devtools.

Gif of bug: menu does not close when escape key is pressed and console opens
devtools-menu-console-esc-bug

This creates a challenge for customer relying on the keyboard that wish
to dismiss the drop down.

This also does not align with the experience of the WAI ARIA practice
navigation menu button example 1.

Root cause

The escape key event is captured and not propagated by the
devtools to toggle the console drawer.

Solution

Close the menu when focus moves out of the menu.

This better aligns the menu with the Navigation menu button example for
which its interaction design is based on 1.

Code Change

  • Add a menu focus out handler to close the drop down menu
  • Unfortunately JSDOM does not support focusout events so JSDOM integration tests
    are not possible 2, instead I have added unit test for the onMenuFocusOut handler.
  • A TypeScript upgrade is needed to better support the focusout event 3.

Gif of bug fixed: menu does close when escape key is pressed and console opens
devtools-menu-console-esc-bug-fixed

Gif of menu escape key closing the menu
devtools-menu-console-esc-bug-fixed-demo-esc

Gif of menu tabbing closing the menu
devtools-menu-console-esc-bug-fixed-demo-tabbing

Related Issues/PRs
#9433

Summary
Problem: The report drop down menu does not close when the escape key
is pressed in the devtools.

This creates a challenge for customer relying on the keyboard that wish
to dismiss the drop down.

This also does not align with the experience of the WAI ARIA practice
navigation menu button example [1].

Root cause: The escape key event is captured and not propagated by the
devtools to toggle the console drawer.

Solution: Close the menu when focus moves out of the menu.

This better aligns the menu with the Navigation menu button example for
which its interaction design is based on [1].

Code Change
* Add a menu focus out handler to close the drop down menu
* Unfortunetly JSDOM does not support focusout events so unit tests
  are not possible at this time [2].

[1]: https://www.w3.org/TR/2019/NOTE-wai-aria-practices-1.1-20190207/examples/menu-button/menu-button-links.html
[2]: jsdom/jsdom#2708

Related PR
9433
Comment on lines 755 to 757
// The focusout event is not supported in our current version of typescript (3.5.3)
// https://github.com/microsoft/TypeScript/issues/30716
const focusEvent = /** @type {FocusEvent} */ (e);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there appetite to upgrade typescript?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always up for upgrading TS, but we may not be at critical mass yet ... @patrickhulce what do you think?

@johnemau
Copy link
Contributor Author

I am going to look into adding a unit test for onMenuFocusOut to improve code coverage per codecov results.

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

Instead of a unit yet, what about a UX test? Could piggy back on the viewer's puppeteer tests.

I'm curious if this fixes the issue this tool menu is shown in the Print preview. Does it?

Comment on lines 755 to 757
// The focusout event is not supported in our current version of typescript (3.5.3)
// https://github.com/microsoft/TypeScript/issues/30716
const focusEvent = /** @type {FocusEvent} */ (e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm always up for upgrading TS, but we may not be at critical mass yet ... @patrickhulce what do you think?

Copy link
Contributor Author

@johnemau johnemau left a comment

Choose a reason for hiding this comment

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

Instead of a unit yet, what about a UX test? Could piggy back on the viewer's puppeteer tests.

I have just finished writing a few unit tests and will add this to this PR but I am happy to follow up with UX tests if you think they would be valuable.

I'm curious if this fixes the issue this tool menu is shown in the Print preview. Does it?

I do not know about the Print preview issue, do you have a link to the issue or repro steps? I will take a look.

@connorjclark
Copy link
Collaborator

I have just finished writing a few unit tests and will add this to this PR but I am happy to follow up with UX tests if you think they would be valuable.

If you feel that covers the new behavior well enough that is fine. Was just suggesting an alternative in case unit tests weren't possible.

I do not know about the Print preview issue, do you have a link to the issue or repro steps? I will take a look.

no crbug, just something I noticed. Printing doesn't seem to be a feature anyone uses so no big deal, was just curious. If you choose the Print option from the tool menu and don't see this tool menu in the Print results, then you've fixed it :)

@johnemau
Copy link
Contributor Author

If you feel that covers the new behavior well enough that is fine. Was just suggesting an alternative in case unit tests weren't possible.

I gotcha, the unit tests I added are good enough coverage.

no crbug, just something I noticed. Printing doesn't seem to be a feature anyone uses so no big deal, was just curious. If you choose the Print option from the tool menu and don't see this tool menu in the Print results, then you've fixed it :)

Unfortunately this change did not fix Print preview :(

image

But this looks like a CSS issue, the menu is hidden by visibility:hidden and so I fixed it locally by adding:

@media print { 
 .lh-tools__dropdown { 
     /* the drop down is not supported on paper ;) */
     display: none; 
 }

I will get a PR out with that fix shortly.

@johnemau
Copy link
Contributor Author

I will get a PR out with that fix shortly.

Done: #10216

@connorjclark connorjclark changed the title report(drop-down-menu): close menu when focus is lost report: close drop down menu when focus is lost Jan 14, 2020
Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

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

Successfully merging this pull request may close these issues.

4 participants