Skip to content

Commit

Permalink
Hide contents of hamburger menu when it is hidden.
Browse files Browse the repository at this point in the history
The contents being visible but offscreen was causing issues with
screen-readers, where the section headers, inputs, etc could still be
tabbed over when the hamburger menu was "closed".

Closes b/131840079

Change-Id: Ic34c6771981da2a8c4893edac0cb44e56869c3bb
  • Loading branch information
theodab committed May 3, 2019
1 parent b0f8944 commit f7f5f0c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ class ShakaDemoConfig {
// changes based on the config changes.
this.reloadAndSaveState_();
});
document.addEventListener('shaka-main-drawer-state-change', () => {
this.setContentAvailability_(shakaDemoMain.getIsDrawerOpen());
});
this.setContentAvailability_(shakaDemoMain.getIsDrawerOpen());
}

/**
* @param {boolean} availability
* @private
*/
setContentAvailability_(availability) {
if (availability) {
this.container_.classList.remove('hidden');
} else {
this.container_.classList.add('hidden');
}
}

/** @private */
Expand Down
24 changes: 24 additions & 0 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,31 @@ class ShakaDemoMain {
drawerCloseButton.addEventListener('click', () => {
const layout = document.getElementById('main-layout');
layout.MaterialLayout.toggleDrawer();
this.dispatchEventWithName_('shaka-main-drawer-state-change');
this.hideNode_(drawerCloseButton);
});
// Dispatch drawer state change events when the drawer button or obfuscator
// are pressed also.
const drawerButton = document.querySelector('.mdl-layout__drawer-button');
goog.asserts.assert(drawerButton, 'There should be a drawer button.');
drawerButton.addEventListener('click', () => {
this.dispatchEventWithName_('shaka-main-drawer-state-change');
this.showNode_(drawerCloseButton);
});
const obfuscator = document.querySelector('.mdl-layout__obfuscator');
goog.asserts.assert(obfuscator, 'There should be an obfuscator.');
obfuscator.addEventListener('click', () => {
this.dispatchEventWithName_('shaka-main-drawer-state-change');
this.hideNode_(drawerCloseButton);
});
this.hideNode_(drawerCloseButton);
}

/** @return {boolean} */
getIsDrawerOpen() {
const drawer = document.querySelector('.mdl-layout__drawer');
goog.asserts.assert(drawer, 'There should be a drawer.');
return drawer.classList.contains('is-visible');
}

/**
Expand Down

0 comments on commit f7f5f0c

Please sign in to comment.