Erik
09/24/2022, 2:11 PMDiv(attrs = {
style {
maxHeight(8.em)
overflow("scroll")
}
}) { /* content */ }
When the content overflows, I'd like the scrollable element to scroll to the bottom (by default it stays at the current scroll position, which is the top if never scrolled). I've found solutions in JS that probably work, but I'd like to know if this can be done nicely from my Kotlin code.Big Chungus
09/24/2022, 2:17 PMErik
09/24/2022, 2:18 PMBig Chungus
09/24/2022, 2:20 PMErik
09/24/2022, 2:24 PMErik
09/24/2022, 2:35 PMDiv(attrs = {
style {
maxHeight(8.em)
overflow("scroll")
}
ref {
it.scrollTop = it.scrollHeight.toDouble()
onDispose { }
}
}) {}
Erik
09/24/2022, 2:35 PMit
is a HTMLDivElement
here)Erik
09/24/2022, 2:36 PMErik
09/24/2022, 2:37 PMref {}
provides the native element, but it's not very nice that you must call onDispose {}
Big Chungus
09/24/2022, 2:52 PMBig Chungus
09/24/2022, 2:53 PMErik
09/25/2022, 9:15 AMErik
09/25/2022, 9:15 AMBig Chungus
09/25/2022, 9:16 AMErik
09/25/2022, 9:16 AM99999.9
(not nice that it must be a double instead of any number)Erik
09/25/2022, 9:17 AMErik
09/25/2022, 9:43 AMref
approachs in the attrs doesn't work, because that disposable effect only runs once when the composition enters for the first time. I want to run on every recomposition, so I ended up using a disposable effect in the Div {}
blockBig Chungus
09/25/2022, 9:51 AM