From: Marius Olbertz Date: Sat, 16 Jun 2018 06:59:17 +0000 (+0200) Subject: Use pull request #10829 from Owlbertz/drilldown-parent-fix for v6.5.0 X-Git-Tag: v6.5.0-rc.1^2~175 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c14720b57baf9d662051bc077a585bac68c2467c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #10829 from Owlbertz/drilldown-parent-fix for v6.5.0 e30db5428 Fix Drilldown behavior with parent link when using keyboard. 2c4b3f9be Added test for fix for #10803. Signed-off-by: Nicolas Coden --- diff --git a/js/foundation.drilldown.js b/js/foundation.drilldown.js index 003ef3d80..5f7d2ca56 100644 --- a/js/foundation.drilldown.js +++ b/js/foundation.drilldown.js @@ -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; } diff --git a/test/javascript/components/drilldown.js b/test/javascript/components/drilldown.js index 69a8e706f..7c13921a1 100644 --- a/test/javascript/components/drilldown.js +++ b/test/javascript/components/drilldown.js @@ -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, {});