From 2d8dcf194b83c39a1c3628dc207dda3bcc5652f0 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Mon, 20 Jan 2020 14:22:31 +0100 Subject: Add "tabChange" event for TabPanel container --- .../src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'kvision-modules/kvision-bootstrap/src/main/kotlin') diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt index d75d10df..44c0a243 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt @@ -146,6 +146,7 @@ open class TabPanel( * @param route JavaScript route to activate given child * @return current container */ + @Suppress("UnsafeCastFromDynamic") open fun addTab( title: String, panel: Component, icon: String? = null, image: ResString? = null, closable: Boolean = false, route: String? = null @@ -181,6 +182,9 @@ open class TabPanel( e.preventDefault() if (route != null) { routing.navigate(route) + } else { + e.asDynamic().data = activeIndex + this@TabPanel.dispatchEvent("tabChange", obj { detail = e }) } } } @@ -194,8 +198,10 @@ open class TabPanel( if (route != null) { routing.on( route, - { _ -> activeIndex = this@TabPanel.content.getChildren().indexOf(childrenMap[currentIndex]) }) - .resolve() + { _ -> + activeIndex = this@TabPanel.content.getChildren().indexOf(childrenMap[currentIndex]) + this@TabPanel.dispatchEvent("tabChange", obj { detail = obj { data = activeIndex } }) + }).resolve() } return this } @@ -210,6 +216,7 @@ open class TabPanel( } content.remove(content.getChildren()[index]) activeIndex = content.activeIndex + this@TabPanel.dispatchEvent("tabChange", obj { detail = obj { data = activeIndex } }) return this } -- cgit