https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
z

Zoff

10/24/2023, 6:19 AM
how can i make a textfiled take focus when it's shown?
Copy code
LaunchedEffect(Unit) {
    textFieldFocusRequester.requestFocus()
}
this only gives it focus on the first time its composed. when i show another tab and then show the tab with the textfield again it does no longer take the focus. not sure how to fix that
a

Alexander Maryanovsky

10/24/2023, 7:14 AM
Create the focus requester at the tab level and pass it down to the textfield (or via a composition local). Register it with the textfield, and request the focus when the tab becomes active.
z

Zoff

10/24/2023, 7:16 AM
ah yes i'll try that thanks
a

Alexander Maryanovsky

10/24/2023, 7:17 AM
Or if you want a more generic solution, put a
onTabActivated
function in a composition local and use it at the textfield level
z

Zoff

10/24/2023, 11:58 AM
i got it working now thanks
3 Views