Skip to content

Commit

Permalink
No longer tracks Popup state within MenuBar
Browse files Browse the repository at this point in the history
  • Loading branch information
goodguyry committed Apr 21, 2020
1 parent 4e58d45 commit 51ab17c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/MenuBar/MenuBar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ describe('Menu correctly responds to events', () => {
domElements.listFirstItem.focus();
domElements.listFirstItem.dispatchEvent(keydownSpace);
expect(document.activeElement).toEqual(domElements.listFirstItem.popup.firstInteractiveChild);
expect(menuBar.getState().expanded).toBeTruthy();
expect(domElements.listFirstItem.popup.getState().expanded).toBeTruthy();
});

it('Should move focus to the first popup child with return key from Menu bar',
() => {
domElements.listFirstItem.focus();
domElements.listFirstItem.dispatchEvent(keydownReturn);
expect(document.activeElement).toEqual(domElements.listFirstItem.popup.firstInteractiveChild);
expect(menuBar.getState().expanded).toBeTruthy();
expect(domElements.listFirstItem.popup.getState().expanded).toBeTruthy();
});

it('Should close the submenu on right arrow key on a menu item with no submenu', () => {
Expand All @@ -186,7 +186,7 @@ describe('Menu correctly responds to events', () => {
domElements.sublistTwoThirdItem.focus();
domElements.sublistTwoThirdItem.dispatchEvent(keydownRight);
expect(document.activeElement).toEqual(domElements.listFourthItem);
expect(menuBar.getState().expanded).toBeFalsy();
expect(domElements.listThirdItem.popup.getState().expanded).toBeFalsy();
});

it('Should close the submenu on left arrow key on a menu item with no parent menu', () => {
Expand All @@ -196,7 +196,7 @@ describe('Menu correctly responds to events', () => {
domElements.sublistTwoThirdItem.focus();
domElements.sublistTwoThirdItem.dispatchEvent(keydownLeft);
expect(document.activeElement).toEqual(domElements.listSecondItem);
expect(menuBar.getState().expanded).toBeFalsy();
expect(domElements.listThirdItem.popup.getState().expanded).toBeFalsy();
});

it('Should click the submenu item on spacebar or return key', () => {
Expand Down
29 changes: 2 additions & 27 deletions src/MenuBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export default class MenuBar extends AriaComponent {
this.handleMenuBarClick = this.handleMenuBarClick.bind(this);
this.handleMenuItemKeydown = this.handleMenuItemKeydown.bind(this);
this.stateWasUpdated = this.stateWasUpdated.bind(this);
this.trackPopupState = this.trackPopupState.bind(this);
this.destroy = this.destroy.bind(this);

// Only initialize if we passed in a <ul>.
Expand Down Expand Up @@ -211,7 +210,6 @@ export default class MenuBar extends AriaComponent {
controller,
target,
onInit: this.onPopupInit,
onStateChange: this.trackPopupState,
type: 'menu',
});

Expand Down Expand Up @@ -247,27 +245,6 @@ export default class MenuBar extends AriaComponent {
this.onInit.call(this);
}

/**
* Refresh component state when Popup state is updated.
*
* @param {object} state The Popup state.
*/
trackPopupState(state = {}) {
const { menubarItem } = this.state;
const popup = this.constructor.getPopupFromMenubarItem(menubarItem);
/*
* Use the current MenuBar state if there's no popup or if an expanded state
* was passed in, otherwise make sure to use the current popup's state.
*/
const expanded = (
false === popup
|| Object.prototype.hasOwnProperty.call(state, 'expanded')
) ? state.expanded : popup.getState();

// Add the Popup state to this component's state.
this.state = Object.assign({ menubarItem, popup, expanded });
}

/**
* Manage menubar state.
*
Expand All @@ -276,9 +253,6 @@ export default class MenuBar extends AriaComponent {
stateWasUpdated() {
const { menubarItem } = this.state;

// Make sure we're tracking the Popup state along with this.
this.trackPopupState();

// Prevent tabbing to all but the currently-active menubar item.
rovingTabIndex(this.menuBarItems, menubarItem);

Expand All @@ -304,7 +278,8 @@ export default class MenuBar extends AriaComponent {
RETURN,
} = keyCodes;
const { keyCode } = event;
const { menubarItem, popup } = this.state;
const { menubarItem } = this.state;
const popup = this.constructor.getPopupFromMenubarItem(menubarItem);

switch (keyCode) {
/*
Expand Down

0 comments on commit 51ab17c

Please sign in to comment.