Skip to content

Commit

Permalink
Implement focus trap in nav drawer
Browse files Browse the repository at this point in the history
Fixes #2665
  • Loading branch information
davwheat committed Aug 12, 2021
1 parent 4fae02e commit 6e40585
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions js/src/common/utils/Drawer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { createFocusTrap } from './focusTrap';

/**
* The `Drawer` class controls the page's drawer. The drawer is the area the
* slides out from the left on mobile devices; it contains the header and the
* footer.
*/
export default class Drawer {
/**
* @type {import('./focusTrap').FocusTrap}
*/
focusTrap;

constructor() {
// Set up an event handler so that whenever the content area is tapped,
// the drawer will close.
Expand All @@ -13,6 +20,8 @@ export default class Drawer {
this.hide();
}
});

this.focusTrap = createFocusTrap('#drawer', { allowOutsideClick: true });
}

/**
Expand Down Expand Up @@ -41,6 +50,8 @@ export default class Drawer {

const $app = $('#app');

this.focusTrap.deactivate();

if (!this.isOpen()) return;

const $drawer = $('#drawer');
Expand All @@ -65,6 +76,8 @@ export default class Drawer {

requestAnimationFrame(() => {
this.$backdrop.addClass('in');

this.focusTrap.activate();
});
}
}

0 comments on commit 6e40585

Please sign in to comment.