]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Add attribute for auto focus 9632/head
authorGorrie <gorriecoe@gmail.com>
Thu, 12 Jan 2017 00:46:05 +0000 (13:46 +1300)
committerGorrie <gorriecoe@gmail.com>
Thu, 12 Jan 2017 00:46:05 +0000 (13:46 +1300)
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

index 2121ca0c8b752b5bcdfd6328125ab49eb6896732..fb5c2b1f11b8ee1d9b07bea12f35f2f72af488fd 100644 (file)
@@ -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();
+        }
       });
     }