]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Enable triggering of links within menu via keyboard. 8369/head
authorMarius Olbertz <marius.olbertz@gmail.com>
Wed, 16 Mar 2016 04:36:09 +0000 (05:36 +0100)
committerMarius Olbertz <marius.olbertz@gmail.com>
Wed, 16 Mar 2016 04:36:09 +0000 (05:36 +0100)
js/foundation.accordionMenu.js

index 513ff3e4f738ac09721fd5e2108d6396250577b5..39cc9fd9b594d196b3aa2df35f72cfb2726ab6d6 100644 (file)
@@ -109,19 +109,19 @@ class AccordionMenu {
 
       $elements.each(function(i) {
         if ($(this).is($element)) {
-          $prevElement = $elements.eq(Math.max(0, i-1));
-          $nextElement = $elements.eq(Math.min(i+1, $elements.length-1));
+          $prevElement = $elements.eq(Math.max(0, i-1)).find('a').first();
+          $nextElement = $elements.eq(Math.min(i+1, $elements.length-1)).find('a').first();
 
           if ($(this).children('[data-submenu]:visible').length) { // has open sub menu
-            $nextElement = $element.find('li:first-child');
+            $nextElement = $element.find('li:first-child').find('a').first();
           }
           if ($(this).is(':first-child')) { // is first element of sub menu
-            $prevElement = $element.parents('li').first();
+            $prevElement = $element.parents('li').first().find('a').first();
           } else if ($prevElement.children('[data-submenu]:visible').length) { // if previous element has open sub menu
-            $prevElement = $prevElement.find('li:last-child');
+            $prevElement = $prevElement.find('li:last-child').find('a').first();
           }
           if ($(this).is(':last-child')) { // is last element of sub menu
-            $nextElement = $element.parents('li').first().next('li');
+            $nextElement = $element.parents('li').first().next('li').find('a').first();
           }
 
           return;
@@ -131,7 +131,7 @@ class AccordionMenu {
         open: function() {
           if ($target.is(':hidden')) {
             _this.down($target);
-            $target.find('li').first().focus();
+            $target.find('li').first().find('a').first().focus();
           }
         },
         close: function() {
@@ -139,14 +139,16 @@ class AccordionMenu {
             _this.up($target);
           } else if ($element.parent('[data-submenu]').length) { // close currently open sub
             _this.up($element.parent('[data-submenu]'));
-            $element.parents('li').first().focus();
+            $element.parents('li').first().find('a').first().focus();
           }
         },
         up: function() {
           $prevElement.attr('tabindex', -1).focus();
+          e.preventDefault();
         },
         down: function() {
           $nextElement.attr('tabindex', -1).focus();
+          e.preventDefault();
         },
         toggle: function() {
           if ($element.children('[data-submenu]').length) {
@@ -157,7 +159,6 @@ class AccordionMenu {
           _this.hideAll();
         },
         handled: function() {
-          e.preventDefault();
           e.stopImmediatePropagation();
         }
       });