Skip to content

Commit

Permalink
Merge pull request #165 from ztn0/fix-pickfile-safari
Browse files Browse the repository at this point in the history
fix: trigger onchange event Safari
  • Loading branch information
vinceglb authored Dec 11, 2024
2 parents 12c167d + 4061fac commit 46d51bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public actual object FileKit {
suspendCoroutine { continuation ->
// Create input element
val input = document.createElement("input") as HTMLInputElement
// Visually hide the element
input.style.display = "none"

document.body?.appendChild(input)

// Configure the input element
input.apply {
Expand Down Expand Up @@ -60,11 +64,14 @@ public actual object FileKit {
continuation.resume(mode.parseResult(result))
} catch (e: Throwable) {
continuation.resumeWithException(e)
} finally {
document.body?.removeChild(input)
}
}

input.oncancel = {
continuation.resume(null)
document.body?.removeChild(input)
}

// Trigger the file picker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public actual object FileKit {
suspendCoroutine { continuation ->
// Create input element
val input = document.createElement("input") as HTMLInputElement
// Visually hide the element
input.style.display = "none"

// Configure the input element
input.apply {
Expand Down Expand Up @@ -60,11 +62,14 @@ public actual object FileKit {
continuation.resume(mode.parseResult(result))
} catch (e: Throwable) {
continuation.resumeWithException(e)
} finally {
document.body?.removeChild(input)
}
}

input.oncancel = {
continuation.resume(null)
document.body?.removeChild(input)
}

// Trigger the file picker
Expand Down

0 comments on commit 46d51bd

Please sign in to comment.