We just launched Compose Examples featuring over 150+ components! Check it out →

semantics

Common

Modifier in Compose Ui

Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc.

The provided lambda receiver scope provides "key = value"-style setters for any [SemanticsPropertyKey]. Additionally, chaining multiple semantics modifiers is also a supported style.

The resulting semantics produce two [SemanticsNode] trees:

The "unmerged tree" rooted at [SemanticsOwner.unmergedRootSemanticsNode] has one [SemanticsNode] per layout node which has any [SemanticsModifier] on it. This [SemanticsNode] contains all the properties set in all the [SemanticsModifier]s on that node.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.8.0-alpha01")
}

Overloads


fun Modifier.semantics(
    mergeDescendants: Boolean = false,
    properties: (SemanticsPropertyReceiver.() -> Unit)
): Modifier

Parameters

namedescription
mergeDescendantsWhether the semantic information provided by the owning component and its descendants should be treated as one logical entity. Most commonly set on screen-reader-focusable items such as buttons or form fields. In the merged semantics tree, all descendant nodes (except those themselves marked [mergeDescendants]) will disappear from the tree, and their properties will get merged into the parent's configuration (using a merging algorithm that varies based on the type of property -- for example, text properties will get concatenated, separated by commas). In the unmerged semantics tree, the node is simply marked with [SemanticsConfiguration.isMergingSemanticsOfDescendants].
propertiesproperties to add to the semantics. [SemanticsPropertyReceiver] will be provided in the scope to allow access for common properties and its values.
by @alexstyl