Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drilldown parent fix #10829

Merged
merged 2 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions js/foundation.drilldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -258,18 +258,20 @@ 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() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 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;
}
Expand Down
12 changes: 12 additions & 0 deletions test/javascript/components/drilldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});
Expand Down