From 9fea7e7b2abceaea36f20fc87c3d4ecb71418d3d Mon Sep 17 00:00:00 2001 From: Thomas Erbe Date: Sat, 30 Jan 2021 20:28:57 +0000 Subject: [PATCH] Panel Tabs - Properly detect is-active #120 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. --- src/plugins/panelTabs.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/plugins/panelTabs.js b/src/plugins/panelTabs.js index 8fd0e70..69ee1a7 100644 --- a/src/plugins/panelTabs.js +++ b/src/plugins/panelTabs.js @@ -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'); @@ -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);