]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Use pull request #10829 from Owlbertz/drilldown-parent-fix for v6.5.0
authorMarius Olbertz <marius.olbertz@gmail.com>
Sat, 16 Jun 2018 06:59:17 +0000 (08:59 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 16 Jun 2018 06:59:17 +0000 (08:59 +0200)
e30db5428 Fix Drilldown behavior with parent link when using keyboard.
2c4b3f9be Added test for fix for  #10803.

Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
js/foundation.drilldown.js
test/javascript/components/drilldown.js

index 003ef3d8048090f617a1155e4096c3f773f69f83..5f7d2ca56fcc5ed53792dd8edd282be1f08c84bb 100644 (file)
@@ -226,7 +226,7 @@ class Drilldown extends Plugin {
           if ($element.is(_this.$submenuAnchors)) {
             _this._show($element.parent('li'));
             $element.parent('li').one(transitionend($element), function(){
-              $element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
+              $element.parent('li').find('ul li a').not('.js-drilldown-back a').first().focus();
             });
             return true;
           }
@@ -258,7 +258,9 @@ class Drilldown extends Plugin {
           }
         },
         open: function() {
-          if (!$element.is(_this.$menuItems)) { // not menu item means back button
+          if (_this.options.parentLink && $element.attr('href')) { // Link with href
+            return false;
+          } else if (!$element.is(_this.$menuItems)) { // not menu item means back button
             _this._hide($element.parent('li').parent('ul'));
             $element.parent('li').parent('ul').one(transitionend($element), function(){
               setTimeout(function() {
@@ -266,10 +268,10 @@ class Drilldown extends Plugin {
               }, 1);
             });
             return true;
-          } else if ($element.is(_this.$submenuAnchors)) {
+          } else if ($element.is(_this.$submenuAnchors)) { // Sub menu item
             _this._show($element.parent('li'));
             $element.parent('li').one(transitionend($element), function(){
-              $element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
+              $element.parent('li').find('ul li a').not('.js-drilldown-back a').first().focus();
             });
             return true;
           }
index 69a8e706f9d31cc8a5faf7be643546d471846c28..7c13921a1aa8309d913c2642488f81f546284246 100644 (file)
@@ -304,6 +304,18 @@ describe('Drilldown Menu', function() {
 
       $html.find('> li:nth-child(1) > ul').should.have.class('is-active');
     });
+    it('focuses parent link if parentLink is true', function(done) {
+      $html = $(template).appendTo('body');
+      plugin = new Foundation.Drilldown($html, {parentLink: true});
+
+      $html.find('> li:nth-child(1) > a').focus()
+        .trigger(window.mockKeyboardEvent('ARROW_RIGHT'));
+      
+      setTimeout(function() { // Timeout to make sure transition has ended
+        $html.find('> li:nth-child(1) > ul > li[data-is-parent-link] a')[0].should.be.equal(document.activeElement);
+        done();
+      }, 500);
+    });
     it('closes child element on ARROW_LEFT', function() {
       $html = $(template).appendTo('body');
       plugin = new Foundation.Drilldown($html, {});