Skip to content

Commit

Permalink
XWIKI-18007: Drawer menu improvements for accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
wthrajat committed Feb 4, 2023
1 parent 3a9d056 commit db4383f
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,26 @@ require(['jquery', 'iscroll', 'drawer'], function($, IScroll) {
// Unfortunately drawer doesn't declare the dependency on iscroll and expects it to be defined as a global variable.
window.IScroll = IScroll;
$(function() {
// Note that the 'drawer-open' and 'drawer-close' CSS classes are added before the open and close animations end
// which prevents us from using them in automated tests. We need something more reliable so we listen to
// 'drawer.opened' and 'drawer.closed' events and add our own markers.
$('.drawer-nav').closest('body').drawer().on('drawer.opened', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'true');
}).on('drawer.closed', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'false');
});
/* Note that the 'drawer-open' and 'drawer-close' CSS classes are added before the open and close animations end
which prevents us from using them in automated tests. We need something more reliable so we listen to
'drawer.opened' and 'drawer.closed' events and add our own markers. */
$('.drawer-nav')
.closest('body')
.drawer()
.on('drawer.opened', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'true');
})
.on('drawer.closed', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'false');
});
});
// Drawer can be closed by pressing the ESC key, irrespective of how you opened it (by using keyboard or by clicking it)
$(document).on('keydown', function (event) {
if (event.key === 'Escape') {
$('.drawer-nav').closest('body').drawer('close');}
// Drawer can be closed by pressing the ESC key, regardless of how it was opened, whether by keyboard or clicking.
$(document).on('keydown', function (event) {
if (event.key === 'Escape') {
$('.drawer-nav')
.closest('body')
.drawer('close');
}
});
});
##
Expand Down

0 comments on commit db4383f

Please sign in to comment.