Help, date picker and account hover state background
On all the menu items such as Help, date picker, and accounts: Mouse hover grey bg needs to be kept active as long as the dropdown is open. Currently if the user clicks one of these menu items and then move the mouse outside these controls, the grey bg disappears like this:
It should be like as shown below in the image, even if the mouse pointer is moved away. This grey BG should be active as long as the dropdown options are open.
This applies to all the header menu items.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When opening any of the three available menus in the Site Kit header bar (user, date picker, help menu, from right to left), the respective button that toggles the menu should remain in its grey background color as long as its menu is open.
- In other words, in this scenario each toggle button should look the same way it does when hovering over it.
Implementation Brief
- Using
assets/sass/config/_variables.scss- Add a new variable for
#f0f0f0
- Add a new variable for
- Using
assets/sass/components/global/_googlesitekit-dropdown-menu.scss,- Add new selector for
mdc-button--dropdown[aria-expanded="true"]havingbackground-colorset to#f0f0f0using the variable added in bullet point 1.colorset torgba(0, 0, 0, 0.87)
- Add new selector for
Test Coverage
- N/A
Visual Regression Changes
- The background color of the dropdowns in the header will change when they are expanded.
QA Brief
- View the Site Kit Dashboard
- Click any of the items in the menu
- Assert that the menu item maintains the hover state styling when open (like the second image in the description)
Changelog entry
- Update the background color of open menu buttons in the Site Kit header.
IB ✅
QA ⚠️
Question testing this ticket, when testing using tab and enter keys on the keyboard. Should we retain the hover state after selecting the drop down for the date picker? Currently if you tab to the date picker and press the enter key, if you tab again the hover state is removed.

~The "hover" state is also the "focus" state, which should be preserved after selection because it's where the keyboard focus is after selection. Until the user tabs away from that item, it should remain in the "focus"/"hover" state, so yes, that's correct.~
EDIT: I noticed the actual issue here after chatting with @cole10up further: if you tab away after activating the dropdown but don’t select anything, its styles stay semi-“focused”:

That's incorrect; once the menu item is tabbed away from it should have no focus/hover state styles. So this needs further iteration to fix that.
Ok there are a few things going on here.
We have state in React for all these menus to say if they're open but we don't actually listen to the tab key event. So when tab is pressed, the browser is moving focus to the next element but we're not setting the state to false. So the CSS rule that I added in my previous PR is still active because the aria-expanded attribute is still "true"
.mdc-button--dropdown[aria-expanded="true"] {
background-color: $c-gallery;
color: rgba(0, 0, 0, 0.87);
}
Notice that to open any menu again after tabbing away you need to click twice (first click sets the menu open state to false, the second click sets it to true which opens it again)
The reason the above bug wasn't spotted and the menu stayed open is because the menu /assets/js/components/Menu.js is built with a non-React library @material/menu
This is passed a ref to the menu const menuComponent = new MDCMenu( menuRef.current ); and @material/menu has its own state for opening/closing the menu
In React we are toggling it imperatively with a useEffect
useEffect( () => {
if ( menu ) {
menu.open = menuOpen;
menu.setDefaultFocusState( 1 );
}
}, [ menu, menuOpen ] );
but it is also responding to key events, such as the Tab key, but also the Enter key
and there's another bug which haven't spotted and @material/menu has covered up!
There is a bug in the three menus' logic. The handleMenuClose mixes a click outside handler with a keypress one so it disregards all Escape key presses (because the event.target is the button)
if (
( ( 'keyup' === event.type && ESCAPE === event.keyCode ) || 'mouseup' === event.type ) &&
! menuButtonRef.current.contains( event.target ) &&
! menuRef.current.contains( event.target )
) {
setMenuOpen( false );
}
https://github.com/google/site-kit-wp/blob/main/assets/js/components/DateRangeSelector.js#L52
This looks like a bug and there should be extra parenthesis after the ||
This means that if you open the menu pressing enter, then close pressing escape, you have to hit enter twice to open it again (same bug as above with the first keypress resetting the state)
I managed to fix the weirdness with the menu taking two clicks to open but when I tab when @material/menu is focused it doesn't play well with React and the tabbing breaks.
Here you can see the problem on a branch I've done where I tried to fix the key press and click outside handling with react-use hooks
https://github.com/google/site-kit-wp/compare/enhancement/3069-help-date-picker-key-event-bug-fix
@tofumatt Can you review #3279 (since it's a11y-related)?
QA Update: Engineer clarification ⚠️
@tofumatt this is looking good other than an observation when you use tab to move around the navigation. This is only an issue when you press enter for the dropdown list to appear. When I tab to account, the date picker navigation is still highlighted. This screencast below highlights the issue better than I can explain it.
Is this an issue? Possibly not linked to this ticket, but thought I would highlight.
https://user-images.githubusercontent.com/73545194/117163816-f07ac780-adbb-11eb-9647-d885e5330c83.mp4
Hmmm, that's not the right effect, I'll take a look and see if it's a regression or if that's a separate bug.
@wpdarren I think the issue was that the fix wasn't in develop, but should be there now. Can you try again on the develop branch—we just merged the fix over 👍🏻
QA Update: Pass ✅
- Verified that the menu item maintains the hover state styling when open. This was tested on Chrome, Firefox and Safari. I also ran this through mobile devices and smaller screens to make sure that the behaviour was the same.
- Verified that the navigation can be used without a mouse, so keyboard (tab, enter, arrow keys) to make sure that the behaviour was the same on the hover state.