Skip to content

Commit

Permalink
feat: add "Tabs._collapse()" to collapse the active tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoden committed Sep 9, 2018
1 parent b819faf commit 7307c43
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions js/foundation.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,10 @@ class Tabs extends Plugin {
*/
_handleTabChange($target, historyHandled) {

/**
* Check for active class on target. Collapse if exists.
*/
// With `activeCollapse`, if the target is the active Tab, collapse it.
if ($target.hasClass(`${this.options.linkActiveClass}`)) {
if(this.options.activeCollapse) {
this._collapseTab($target);

/**
* Fires when the zplugin has successfully collapsed tabs.
* @event Tabs#collapse
*/
this.$element.trigger('collapse.zf.tabs', [$target]);
this._collapse();
}
return;
}
Expand Down Expand Up @@ -323,6 +315,25 @@ class Tabs extends Plugin {
.attr({ 'aria-hidden': 'true' })
}

/**
* Collapses the active Tab.
* @fires Tabs#collapse
* @function
*/
_collapse() {
var $activeTab = this.$element.find(`.${this.options.linkClass}.${this.options.linkActiveClass}`);

if ($activeTab.length) {
this._collapseTab($activeTab);

/**
* Fires when the zplugin has successfully collapsed tabs.
* @event Tabs#collapse
*/
this.$element.trigger('collapse.zf.tabs', [$activeTab]);
}
}

/**
* Public method for selecting a content pane to display.
* @param {jQuery | String} elem - jQuery object or string of the id of the pane to display.
Expand Down

0 comments on commit 7307c43

Please sign in to comment.