From ea425920b8b7da13f2f999101f4db632abe9eb89 Mon Sep 17 00:00:00 2001 From: Gorrie Date: Thu, 12 Jan 2017 13:46:05 +1300 Subject: [PATCH] Add attribute for auto focus Checks for the attribute [data-autofocus] within the toggled off canvas and focuses on the first occurrence if available. Otherwise reverts to standard behaviour. --- js/foundation.offcanvas.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/foundation.offcanvas.js b/js/foundation.offcanvas.js index 2121ca0c8..fb5c2b1f1 100644 --- a/js/foundation.offcanvas.js +++ b/js/foundation.offcanvas.js @@ -196,7 +196,12 @@ class OffCanvas { if (this.options.autoFocus === true) { this.$element.one(Foundation.transitionend(this.$element), function() { - _this.$element.find('a, button').eq(0).focus(); + var canvasFocus = _this.$element.find('[data-autofocus]'); + if (canvasFocus.length) { + canvasFocus.eq(0).focus(); + } else { + _this.$element.find('a, button').eq(0).focus(); + } }); } -- 2.47.2