aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-01-20 14:22:31 +0100
committerRobert Jaros <rjaros@finn.pl>2020-01-20 14:22:31 +0100
commit2d8dcf194b83c39a1c3628dc207dda3bcc5652f0 (patch)
treeffafb7de0fb88e5e7aa1533818a85a695915bdc2
parent36faf5081ec2f83fe75a3b56f5887ce3c6197cc4 (diff)
downloadkvision-2.9.0.tar.gz
kvision-2.9.0.tar.bz2
kvision-2.9.0.zip
Add "tabChange" event for TabPanel container2.9.0
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt11
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt1
2 files changed, 10 insertions, 2 deletions
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
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
index 583dd74c..00d7e59a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/utils/Snabbdom.kt
@@ -133,6 +133,7 @@ interface BtOn : On {
var tabulatorDataLoading: ((KvEvent) -> Unit)?
var tabulatorDataLoaded: ((KvEvent) -> Unit)?
var tabulatorDataEdited: ((KvEvent) -> Unit)?
+ var tabChange: ((KvEvent) -> Unit)?
var tabClosing: ((KvEvent) -> Unit)?
var tabClosed: ((KvEvent) -> Unit)?
}