---
title: "requestFocus"
description: "Action that gives input focus to this node."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun SemanticsPropertyReceiver.requestFocus(label: String? = null, action: (() -> Boolean)?)
```


Action that gives input focus to this node.

#### Parameters

| | |
| --- | --- |
| label | Optional label for this action. |
| action | Action to be performed when the `SemanticsActions.RequestFocus` is called. |




<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun FocusRequesterModifierNode.requestFocus(): Boolean
```


Use this function to request focus. If the system grants focus to a component associated with
this `FocusRequester`, its `onFocusChanged` modifiers will receive a `FocusState` object where
`FocusState.isFocused` is true.



## Code Examples
### RequestFocusSample
```kotlin
@Composable
fun RequestFocusSample() {
    val focusRequester = remember { FocusRequester() }
    var color by remember { mutableStateOf(Black) }
    Box(
        Modifier.clickable { focusRequester.requestFocus() }
            .border(2.dp, color)
            // The focusRequester should be added BEFORE the focusable.
            .focusRequester(focusRequester)
            // The onFocusChanged should be added BEFORE the focusable that is being observed.
            .onFocusChanged { color = if (it.isFocused) Green else Black }
            .focusable()
    )
}
```

