Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose Textfield OnFocusChangeListener

I have a standard Textfield and I wanna know when user sets focus in it. is there a way to do that?

I tried to set clickable modifier to trigger the event when somebody clicks on it but looks like it doesn't work with TextField:

modifier = Modifier
            .clickable {
                shouldShowSearchKeyBoard.value = true
            },
like image 558
Rainmaker Avatar asked Sep 12 '25 19:09

Rainmaker


1 Answers

found the answer.

modifier = Modifier
    .focusRequester(focusRequester)
    .onFocusChanged {
        if (it.isFocused) {
            // focused
        } else {
            // not focused
        }
    },
like image 87
Rainmaker Avatar answered Sep 14 '25 11:09

Rainmaker