Skip to content

Commit

Permalink
Panel Tabs - Properly detect is-active #120
Browse files Browse the repository at this point in the history
When the plugin has initialised look for a nav item with `is-active` and use this as the active state. If none is found then use the first item.
  • Loading branch information
Thomas Erbe committed Jan 30, 2021
1 parent bdef153 commit 9fea7e7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/plugins/panelTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export class PanelTabs extends Plugin {

this.setupNavEvents();

this.on('init', this.showActiveTab.bind(this));

Bulma(this.root).data('panelTabs', this);

this.trigger('init');
Expand Down Expand Up @@ -136,6 +138,25 @@ export class PanelTabs extends Plugin {
}
});
}

/**
* This is called on init and will setup the panel tabs for the current active tab, if any
*/
showActiveTab() {
let activeNavFound = false;

Bulma.each(this.navItems, (navItem) => {
if(navItem.classList.contains('is-active')) {
this.setActive(navItem.getAttribute('data-target'));
activeNavFound = true;
}
});

// If no nav item has is-active then use the first one
if(!activeNavFound) {
this.setActive(this.navItems[0].getAttribute('data-target'));
}
}
}

Bulma.registerPlugin('panelTabs', PanelTabs);
Expand Down

0 comments on commit 9fea7e7

Please # to comment.