Skip to content

Commit

Permalink
fix(menu): submenus will open correctly on click
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 523796693
  • Loading branch information
material-web-copybara authored and copybara-github committed Apr 12, 2023
1 parent 9c202f5 commit 9d7b291
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions list/lib/listitem/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class ListItemEl extends LitElement implements ListItem {
* so that we have control over focus on specific variants such as disabling
* focus on <md-autocomplete-item> but enabling it for <md-menu-item>.
*/
protected focusOnSelection = true;
protected focusOnActivation = true;

protected getRipple = () => {
this.showRipple = true;
Expand All @@ -119,7 +119,7 @@ export class ListItemEl extends LitElement implements ListItem {
if (this.active) {
this.itemTabIndex = 0;

if (this.focusOnSelection) {
if (this.focusOnActivation) {
this.showFocusRing = shouldShowStrongFocus();
}

Expand Down Expand Up @@ -274,7 +274,7 @@ export class ListItemEl extends LitElement implements ListItem {
// will focus the list item root if it is selected but not on the first
// update or else it may cause the page to jump on first load.
if (changed.has('active') && !this.isFirstUpdate && this.active &&
this.focusOnSelection) {
this.focusOnActivation) {
this.focus();
}

Expand Down
3 changes: 2 additions & 1 deletion menu/lib/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export abstract class Menu extends LitElement {
*/
@ariaProperty
@property({attribute: 'data-role', noAccessor: true})
override role: ARIARole = 'list';
override role: ARIARole = 'menu';
/**
* The max time between the keystrokes of the typeahead menu behavior before
* it clears the typeahead buffer.
Expand Down Expand Up @@ -664,6 +664,7 @@ export abstract class Menu extends LitElement {
const items = this.items;
for (const item of items) {
item.active = false;
item.selected = false;
}
}

Expand Down
8 changes: 6 additions & 2 deletions menu/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ interface MenuItemSelf {
*/
headline: string;
/**
* Whether or not the item is in the selected visual state (focuses on
* selection).
* Whether or not the item is the currently active item of interest (focuses
* upon activation).
*/
active: boolean;
/**
* Whether or not the item is in the selected visual state.
*/
selected?: boolean;
/**
* If it is a sub-menu-item, a method that can close the submenu.
*/
Expand Down
1 change: 0 additions & 1 deletion menu/lib/submenuitem/sub-menu-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export class SubMenuItem extends MenuItemEl {
// around the menu and then mouses over an md-sub-menu.
this.dispatchEvent(new DeactivateItemsEvent());
this.dispatchEvent(new DeactivateTypeaheadEvent());
this.active = true;
this.selected = true;

// This is the case of mouse hovering when already opened via keyboard or
Expand Down
4 changes: 2 additions & 2 deletions select/lib/selectoption/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SelectOptionEl extends MenuItemEl implements SelectOption {
// By default active = true focuses the element. We want to prevent that
// in this case because we set active = this.selected and that may mess
// around with menu's restore focus function once the menu closes.
this.focusOnSelection = false;
this.focusOnActivation = false;
}

super.willUpdate(changed);
Expand All @@ -52,7 +52,7 @@ export class SelectOptionEl extends MenuItemEl implements SelectOption {
super.updated(changed);
// Restore the active = true focusing behavior which happens in
// super.updated() if it was turned off.
this.focusOnSelection = true;
this.focusOnActivation = true;

// Do not dispatch event on first update / boot-up.
if (changed.has('selected') && changed.get('selected') !== undefined) {
Expand Down

0 comments on commit 9d7b291

Please sign in to comment.