# clickable

Common/AllAndroid/JVM

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/foundation/clickable.modifier#(androidx.compose.ui.Modifier).clickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)( enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onClickLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role?, interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?, onClick: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Configure component to receive clicks via input or accessibility "click" event. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/foundation/clickable.modifier#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)( interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?, indication: https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication?, enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onClickLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role?, onClick: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Configure component to receive clicks via input or accessibility "click" event. | Cmn |

## Functions

### Modifier.clickable

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/Clickable.kt+function:clickable) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.9.0)

```
fun Modifier.clickable(
    enabled: Boolean = true,
    onClickLabel: String? = null,
    role: Role? = null,
    interactionSource: MutableInteractionSource? = null,
    onClick: () -> Unit
): Modifier
```

Configure component to receive clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds and show a default indication when it's pressed.

This overload will use the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication` from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#LocalIndication()`. Use the other overload to explicitly provide an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication` instance. Note that this overload only supports `https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationNodeFactory` instances provided through `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#LocalIndication()` - it is strongly recommended to migrate to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationNodeFactory`, but you can use the other overload if you still need to support `https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication` instances that are not `https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationNodeFactory`.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)` is `null`, an internal `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` will be lazily created only when needed. This reduces the performance cost of clickable during composition, as creating the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/indication.modifier#(androidx.compose.ui.Modifier).indication(androidx.compose.foundation.interaction.InteractionSource,androidx.compose.foundation.Indication)` can be delayed until there is an incoming `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`. If you are only passing a remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` and you are never using it outside of clickable, it is recommended to instead provide `null` to enable lazy creation. If you need the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication` to be created eagerly, provide a remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource`.

If you need to support double click or long click alongside the single click, consider using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/combinedClickable.modifier#(androidx.compose.ui.Modifier).combinedClickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.String,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)`.

***Note*** Any removal operations on Android Views from `clickable` should wrap `onClick` in a `post { }` block to guarantee the event dispatch completes before executing the removal. (You do not need to do this when removing a composable because Compose guarantees it completes via the snapshot state system.)

```kotlin
import androidx.compose.foundation.clickable
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
```

| Parameters |
|---|---|
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | Controls the enabled state. When `false`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)`, and this modifier will appear disabled for accessibility services |
| `onClickLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | semantic / accessibility label for the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)` action |
| `role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role? = null` | the type of user interface element. Accessibility services might use this to describe the element or do customizations |
| `interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource? = null` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` that will be used to dispatch `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/PressInteraction.Press` when this clickable is pressed. If `null`, an internal `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` will be created if needed. |
| `onClick: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | will be called when user clicks on the element |

### Modifier.clickable

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/Clickable.kt+function:clickable) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.0.0)

```
fun Modifier.clickable(
    interactionSource: MutableInteractionSource?,
    indication: Indication?,
    enabled: Boolean = true,
    onClickLabel: String? = null,
    role: Role? = null,
    onClick: () -> Unit
): Modifier
```

Configure component to receive clicks via input or accessibility "click" event.

Add this modifier to the element to make it clickable within its bounds and show an indication as specified in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` parameter.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` is `null`, and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` is an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationNodeFactory`, an internal `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` will be lazily created along with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` only when needed. This reduces the performance cost of clickable during composition, as creating the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` can be delayed until there is an incoming `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/Interaction`. If you are only passing a remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` and you are never using it outside of clickable, it is recommended to instead provide `null` to enable lazy creation. If you need `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` to be created eagerly, provide a remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource`.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` is *not* an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/IndicationNodeFactory`, and instead implements the deprecated `https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication#rememberUpdatedInstance(androidx.compose.foundation.interaction.InteractionSource)` method, you should explicitly pass a remembered `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` as a parameter for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` instead of `null`, as this cannot be lazily created inside clickable.

If you need to support double click or long click alongside the single click, consider using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/combinedClickable.modifier#(androidx.compose.ui.Modifier).combinedClickable(kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.String,kotlin.Function0,kotlin.Function0,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)`.

***Note*** Any removal operations on Android Views from `clickable` should wrap `onClick` in a `post { }` block to guarantee the event dispatch completes before executing the removal. (You do not need to do this when removing a composable because Compose guarantees it completes via the snapshot state system.)

```kotlin
import androidx.compose.foundation.clickable
import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier

val count = remember { mutableStateOf(0) }
// content that you want to make clickable
Text(text = count.value.toString(), modifier = Modifier.clickable { count.value += 1 })
```

| Parameters |
|---|---|
| `interactionSource: https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` that will be used to dispatch `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/PressInteraction.Press` when this clickable is pressed. If `null`, an internal `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/MutableInteractionSource` will be created if needed. |
| `indication: https://developer.android.com/reference/kotlin/androidx/compose/foundation/Indication?` | indication to be shown when modified element is pressed. By default, indication from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#LocalIndication()` will be used. Pass `null` to show no indication, or current value from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#LocalIndication()` to show theme default |
| `enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | Controls the enabled state. When `false`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)`, and this modifier will appear disabled for accessibility services |
| `onClickLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | semantic / accessibility label for the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).clickable(androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.Indication,kotlin.Boolean,kotlin.String,androidx.compose.ui.semantics.Role,kotlin.Function0)` action |
| `role: https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/Role? = null` | the type of user interface element. Accessibility services might use this to describe the element or do customizations |
| `onClick: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | will be called when user clicks on the element |