SelectionContainer

Functions summary

Unit
@Composable
SelectionContainer(modifier: Modifier, content: @Composable () -> Unit)

Enables text selection for its direct or indirect children.

Cmn
Unit
@Composable
SelectionContainer(
    state: SelectionState,
    modifier: Modifier,
    content: @Composable () -> Unit
)

Enables text selection for its direct or indirect children.

Cmn

Functions

SelectionContainer

@Composable
fun SelectionContainer(
    modifier: Modifier = Modifier,
    content: @Composable () -> Unit
): Unit

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. However, selected lazy layout items will be pinned so that they don't leave composition when scrolled off-screen.

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.Text

SelectionContainer {
    Column {
        Text("Text 1")
        Text("Text 2")
        Text("טקסט 3")
    }
}
Parameters
modifier: Modifier = Modifier

Modifier for SelectionContainer.

content: @Composable () -> Unit

The content to be selectable.

SelectionContainer

@Composable
fun SelectionContainer(
    state: SelectionState,
    modifier: Modifier = Modifier,
    content: @Composable () -> Unit
): Unit

Enables text selection for its direct or indirect children. Allows passing in a SelectionState to observe currently selected text or perform selection actions such as selectAll or clear.

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. However, selected lazy layout items will be pinned so that they don't disappear when scrolled off-screen.

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.text.selection.rememberSelectionState
import androidx.compose.material.Button
import androidx.compose.material.Text

val selectionState = rememberSelectionState()

Column {
    Button(onClick = { selectionState.selectAll() }) { BasicText("Select All") }
    SelectionContainer(state = selectionState) { BasicText(text = "Text to be selected...") }
}
Parameters
state: SelectionState

SelectionState object containing the currently selected text and selection actions. It is invalid for the same SelectionState to be passed to multiple SelectionContainers.

modifier: Modifier = Modifier

Modifier for SelectionContainer.

content: @Composable () -> Unit

The content to be selectable.