From bbfb4b44d09bf4c1c0b40884fa0ad856ff908479 Mon Sep 17 00:00:00 2001 From: Brett Mason Date: Wed, 30 Nov 2016 19:47:25 +0000 Subject: [PATCH] Fix incorrect keyboard nav within methods --- js/foundation.offcanvas.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/js/foundation.offcanvas.js b/js/foundation.offcanvas.js index 1660de382..aa549a65e 100644 --- a/js/foundation.offcanvas.js +++ b/js/foundation.offcanvas.js @@ -215,15 +215,14 @@ class OffCanvas { last = focusable.eq(-1); focusable.off('.zf.offcanvas').on('keydown.zf.offcanvas', function(e) { - if (e.which === 9 || e.keycode === 9) { - if (e.target === last[0] && !e.shiftKey) { - e.preventDefault(); - first.focus(); - } - if (e.target === first[0] && e.shiftKey) { - e.preventDefault(); - last.focus(); - } + var key = Foundation.Keyboard.parseKey(e); + if (key === 'TAB' && e.target === last[0]) { + e.preventDefault(); + first.focus(); + } + if (key === 'SHIFT_TAB' && e.target === first[0]) { + e.preventDefault(); + last.focus(); } }); } @@ -287,13 +286,18 @@ class OffCanvas { * @function * @private */ - _handleKeyboard(event) { - if (event.which !== 27) return; - - event.stopPropagation(); - event.preventDefault(); - this.close(); - this.$lastTrigger.focus(); + _handleKeyboard(e) { + Foundation.Keyboard.handleKey(e, 'OffCanvas', { + close: () => { + this.close(); + this.$lastTrigger.focus(); + return true; + }, + handled: () => { + e.stopPropagation(); + e.preventDefault(); + } + }); } /** -- 2.47.2