Enables text selection for its direct or indirect children.
Use of a lazy layout, such as LazyRow or LazyColumn, within a SelectionContainer has undefined behavior on text items that aren't composed. For example, texts that aren't composed will not be included in copy operations and select all will not expand the selection to include them.
This context is expected to be associated with a worker thread to ensure that text classification, which can be a time-consuming operation, does not block the UI thread. Providing a CoroutineContext not backed by a worker thread may lead to performance issues or unexpected behavior with TextClassifier.
CompositionLocal used to change the TextSelectionColors used by text and text field components in the hierarchy.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-04 UTC.
[null,null,["Last updated 2025-06-04 UTC."],[],[],null,["# androidx.compose.foundation.text.selection\n==========================================\n\nCommon/AllAndroid/JVM\n\nClasses\n-------\n\n|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|-----|\n| [TextSelectionColors](/reference/kotlin/androidx/compose/foundation/text/selection/TextSelectionColors) | Represents the colors used for text selection by text and text field components. | Cmn |\n\nTop-level functions summary\n---------------------------\n\n|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|\n| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[Composable](/reference/kotlin/androidx/compose/runtime/Composable) [DisableSelection](/reference/kotlin/androidx/compose/foundation/text/selection/package-summary#DisableSelection(kotlin.Function0))`(content: @`[Composable](/reference/kotlin/androidx/compose/runtime/Composable)` () `-\u003e` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Disables text selection for its direct or indirect children. | Cmn |\n| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[Composable](/reference/kotlin/androidx/compose/runtime/Composable) [SelectionContainer](/reference/kotlin/androidx/compose/foundation/text/selection/package-summary#SelectionContainer(androidx.compose.ui.Modifier,kotlin.Function0))`(modifier: `[Modifier](/reference/kotlin/androidx/compose/ui/Modifier)`, content: @`[Composable](/reference/kotlin/androidx/compose/runtime/Composable)` () `-\u003e` `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)`)` Enables text selection for its direct or indirect children. | Cmn |\n\nTop-level properties summary\n----------------------------\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|\n| [ProvidableCompositionLocal](/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal)`\u003c`[CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)`\u003e` | [LocalTextClassifierCoroutineContext](/reference/kotlin/androidx/compose/foundation/text/selection/package-summary#LocalTextClassifierCoroutineContext()) The [CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) used for launching [TextClassifier](https://developer.android.com/reference/android/view/textclassifier/TextClassifier.html) operations within the selection features. | android |\n| [ProvidableCompositionLocal](/reference/kotlin/androidx/compose/runtime/ProvidableCompositionLocal)`\u003c`[TextSelectionColors](/reference/kotlin/androidx/compose/foundation/text/selection/TextSelectionColors)`\u003e` | [LocalTextSelectionColors](/reference/kotlin/androidx/compose/foundation/text/selection/package-summary#LocalTextSelectionColors()) CompositionLocal used to change the [TextSelectionColors](/reference/kotlin/androidx/compose/foundation/text/selection/TextSelectionColors) used by text and text field components in the hierarchy. | Cmn |\n\nTop-level functions\n-------------------\n\n### DisableSelection\n\nCmn \nArtifact: [androidx.compose.foundation:foundation](/jetpack/androidx/releases/compose-foundation) \n[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/selection/SelectionContainer.kt+function:DisableSelection) \nAdded in [1.0.0](/jetpack/androidx/releases/compose-foundation#1.0.0) \n\n```\n@Composable\nfun DisableSelection(content: @Composable () -\u003e Unit): Unit\n```\n\nDisables text selection for its direct or indirect children. To use this, simply add this to wrap one or more text composables. \n\n```kotlin\nimport androidx.compose.foundation.layout.Column\nimport androidx.compose.foundation.text.selection.DisableSelection\nimport androidx.compose.foundation.text.selection.SelectionContainer\nimport androidx.compose.material.Text\n\nSelectionContainer {\n Column {\n Text(\"Text 1\")\n\n DisableSelection {\n Text(\"Text 2\")\n Text(\"טקסט 3\")\n }\n\n Text(\"Text 3\")\n }\n}\n``` \n\n### SelectionContainer\n\nCmn \nArtifact: [androidx.compose.foundation:foundation](/jetpack/androidx/releases/compose-foundation) \n[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/selection/SelectionContainer.kt+function:SelectionContainer) \nAdded in [1.0.0](/jetpack/androidx/releases/compose-foundation#1.0.0) \n\n```\n@Composable\nfun SelectionContainer(\n modifier: Modifier = Modifier,\n content: @Composable () -\u003e Unit\n): Unit\n```\n\nEnables text selection for its direct or indirect children.\n\nUse of a lazy layout, such as [LazyRow](/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyRow(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Function1)) or [LazyColumn](/reference/kotlin/androidx/compose/foundation/lazy/package-summary#LazyColumn(androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.LazyListState,androidx.compose.foundation.layout.PaddingValues,kotlin.Boolean,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean,androidx.compose.foundation.OverscrollEffect,kotlin.Function1)), within a [SelectionContainer](/reference/kotlin/androidx/compose/foundation/text/selection/package-summary#SelectionContainer(androidx.compose.ui.Modifier,kotlin.Function0)) has undefined behavior on text items that aren't composed. For example, texts that aren't composed will not be included in copy operations and select all will not expand the selection to include them. \n\n```kotlin\nimport androidx.compose.foundation.layout.Column\nimport androidx.compose.foundation.text.selection.SelectionContainer\nimport androidx.compose.material.Text\n\nSelectionContainer {\n Column {\n Text(\"Text 1\")\n Text(\"Text 2\")\n Text(\"טקסט 3\")\n }\n}\n```\n\nTop-level properties\n--------------------\n\n### LocalTextClassifierCoroutineContext\n\nandroid \nArtifact: [androidx.compose.foundation:foundation](/jetpack/androidx/releases/compose-foundation) \n[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/selection/PlatformSelectionBehaviors.android.kt+symbol:LocalTextClassifierCoroutineContext) \n\n```\nval LocalTextClassifierCoroutineContext: ProvidableCompositionLocal\u003cCoroutineContext\u003e\n```\n\nThe [CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) used for launching [TextClassifier](https://developer.android.com/reference/android/view/textclassifier/TextClassifier.html) operations within the selection features.\n\nThis context is expected to be associated with a worker thread to ensure that text classification, which can be a time-consuming operation, does not block the UI thread. Providing a [CoroutineContext](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html) not backed by a worker thread may lead to performance issues or unexpected behavior with [TextClassifier](https://developer.android.com/reference/android/view/textclassifier/TextClassifier.html). \n\n### LocalTextSelectionColors\n\nCmn \nArtifact: [androidx.compose.foundation:foundation](/jetpack/androidx/releases/compose-foundation) \n[View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/text/selection/TextSelectionColors.kt+symbol:LocalTextSelectionColors) \nAdded in [1.0.0](/jetpack/androidx/releases/compose-foundation#1.0.0) \n\n```\nval LocalTextSelectionColors: ProvidableCompositionLocal\u003cTextSelectionColors\u003e\n```\n\nCompositionLocal used to change the [TextSelectionColors](/reference/kotlin/androidx/compose/foundation/text/selection/TextSelectionColors) used by text and text field components in the hierarchy."]]