Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Key API and keys event handling #556

Merged
merged 6 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/src/jsMain/kotlin/dev/fritz2/components/popover.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dev.fritz2.dom.Window
import dev.fritz2.dom.html.Key
import dev.fritz2.dom.html.Keys
import dev.fritz2.dom.html.RenderContext
import dev.fritz2.dom.key
import dev.fritz2.dom.keys
import dev.fritz2.styling.*
import dev.fritz2.styling.params.BasicParams
import dev.fritz2.styling.params.BoxParams
Expand All @@ -20,8 +20,8 @@ import dev.fritz2.styling.theme.PopoverSizes
import dev.fritz2.styling.theme.Theme
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import org.w3c.dom.HTMLElement

/**
Expand Down Expand Up @@ -154,7 +154,7 @@ open class PopoverComponent : Component<Unit>,

private val visible = object : RootStore<Boolean>(false) {
val toggle = handle { !it }
val closeOnKey = handle<Key> { _, _ -> false }
val closeOnKey = handle<Unit> { _, _ -> false }
}

override fun render(
Expand All @@ -167,7 +167,7 @@ open class PopoverComponent : Component<Unit>,
context.apply {

if (this@PopoverComponent.closeOnEscape.value) {
Window.keyups.key().filter { it == Keys.Escape } handledBy this@PopoverComponent.visible.closeOnKey
Window.keyups.keys(Keys.Escape).map { } handledBy this@PopoverComponent.visible.closeOnKey
}

div(staticCss.name, id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import dev.fritz2.dom.EventContext
import dev.fritz2.dom.Tag
import dev.fritz2.dom.Window
import dev.fritz2.dom.html.Div
import dev.fritz2.dom.html.Key
import dev.fritz2.dom.html.Keys
import dev.fritz2.dom.html.RenderContext
import dev.fritz2.dom.keys
import dev.fritz2.styling.StyleClass
import dev.fritz2.styling.div
import dev.fritz2.styling.name
Expand Down Expand Up @@ -362,19 +362,15 @@ open class SliderComponent(protected val store: Store<Int>? = null) :
clicks.events handledBy internalStore.updateByClick
Window.mousemoves.events handledBy internalStore.updateByMovement
Window.mouseups.events.map { false } handledBy internalStore.updateMovementTracking
keydowns.events.mapNotNull {
when (Key(it)) {
Keys.ArrowDown, Keys.ArrowLeft -> {
it.preventDefault()
Direction.DOWN
keydowns.keys(Keys.ArrowDown, Keys.ArrowUp, Keys.ArrowLeft, Keys.ArrowRight)
.mapNotNull { (key, event) ->
event.preventDefault()
when (key) {
Keys.ArrowDown, Keys.ArrowLeft -> Direction.DOWN
Keys.ArrowUp, Keys.ArrowRight -> Direction.UP
else -> null
}
Keys.ArrowUp, Keys.ArrowRight -> {
it.preventDefault()
Direction.UP
}
else -> null
}
} handledBy internalStore.updateByKeystroke
} handledBy internalStore.updateByKeystroke

internalStore.data.render { state ->
div({
Expand Down
Loading