From 65545f31a1f6e20857f4283ecec4790046971d6f Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 3 Apr 2018 17:23:23 +0200 Subject: Add onClick event handler for Link component --- src/main/kotlin/pl/treksoft/kvision/html/Link.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt index d1cf9a12..5fc613e2 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Link.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Link.kt @@ -22,6 +22,7 @@ package pl.treksoft.kvision.html import com.github.snabbdom.VNode +import org.w3c.dom.events.MouseEvent import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.ResString import pl.treksoft.kvision.core.StringPair @@ -72,6 +73,18 @@ open class Link( return pr } + /** + * A convenient helper for easy setting onClick event handler. + */ + open fun onClick(handler: Link.(MouseEvent) -> Unit): Link { + this.setEventListener { + click = { e -> + self.handler(e) + } + } + return this + } + companion object { /** * DSL builder extension function. -- cgit