Using kotlin-react-app, I'm trying to create a dro...
# javascript
h
Using kotlin-react-app, I'm trying to create a drop-area for files. I can define a div
Copy code
div("App-header") {
            attrs.onDragOverFunction = { event -> event.preventDefault() }
            attrs.onDropFunction = ::filesDropped
but the
onDropFunction
has the signature
Event -> Unit
. I'm trying to follow some html5 JS tutorial and to access the files that were dropped, they use
ev.dataTransfer
, but in Kotlin this is only available for
DragEvent
. The problem is that the provided
event
is not of type
DragEvent
and something like this fails
Copy code
private fun filesDropped(event: Event) {
        console.log("Files dropped")
        event.preventDefault()
        val dragEvent = event as DragEvent
        val items = dragEvent.dataTransfer?.items ?: return
Is there a simple example/tutorial how to do this in Kotlin?
Hmm, this works
val dragEvent = event.unsafeCast<DragEvent>()