Ayfri
07/05/2022, 9:09 PMmutableState<Boolean>
? For now I have this but it's very ugly I guess 👀
data class Tab(val name: String, val link: String, val selected: MutableState<Boolean> = mutableStateOf(false))
@Composable
fun Tab(tab: Tab) {
NavLink(tab.link, {
if (tab.selected.value) {
ref { htmlAnchorElement ->
htmlAnchorElement.classList.add("selected")
onDispose {}
}
} else {
ref { htmlAnchorElement ->
htmlAnchorElement.classList.remove("selected")
onDispose {}
}
}
}) {
Text(tab.name)
}
}
Big Chungus
07/06/2022, 12:31 AMAyfri
07/06/2022, 12:32 AMBig Chungus
07/06/2022, 12:33 AMhfhbd
07/07/2022, 11:47 AMselected
? routing compose already parses the current path and sets the active
class. But I guess, it should be better to provide a Boolean in the attrs block to set the classes by yourselfhfhbd
07/07/2022, 11:48 AMNavLink(tab.link, { selected ->
if (selected) {
classes("selected")
}
}) {
Text(tab.name)
}
Ayfri
07/07/2022, 12:41 PMactive
class set by routing-compose, so I used it in the endhfhbd
07/07/2022, 12:43 PMAyfri
07/07/2022, 12:43 PM