# SemanticsModifierNode

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/node/SemanticsModifierNode.kt+class:androidx.compose.ui.node.SemanticsModifierNode) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface SemanticsModifierNode : DelegatableNode
  ```

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that adds semantics key/value for use in testing, accessibility, and similar use cases.

This is the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` equivalent of `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsModifier`

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsPropertyReceiver.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).applySemantics()()` Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc. | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#isImportantForBounds()` Whether this semantics modifier node should be taken into account when computing the layout boundaries of the corresponding `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode`, which are used for accessibility and testing. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#shouldClearDescendantSemantics()` Clears the semantics of all the descendant nodes and sets new semantics. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#shouldMergeDescendantSemantics()` Whether the semantic information provided by this node and its descendants should be treated as one logical entity. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode.https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.node.SemanticsModifierNode).invalidateSemantics()()` Invalidate semantics associated with this node. | Cmn |

### Inherited functions

From [androidx.compose.ui.node.DelegatableNode](https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#onDensityChange()()`

Invoked when the density changes for this node.
Cmn `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `@https://developer.android.com/reference/kotlin/androidx/annotation/EmptySuper
https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#onLayoutDirectionChange()()`

Invoked when the layout direction changes for this node.
Cmn

### Inherited properties

From [androidx.compose.ui.node.DelegatableNode](https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode) `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/DelegatableNode#node()`

A reference of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.Node` that holds this node's position in the node hierarchy.
Cmn

## Public functions

### SemanticsPropertyReceiver.applySemantics

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/node/SemanticsModifierNode.kt+function:applySemantics) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.5.0)

```
fun SemanticsPropertyReceiver.applySemantics(): Unit
```

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

The `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsPropertyReceiver` provides "key = value"-style setters for any `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsPropertyKey`. Additionally, chaining multiple semantics modifiers is also a supported style.

The resulting semantics produce two `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode` trees:

The "unmerged tree" rooted at `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsOwner#unmergedRootSemanticsNode()` has one `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode` per layout node which has any `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode` on it. This `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode` contains all the properties set in all the `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode`s on that node.

The "merged tree" rooted at `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsOwner#rootSemanticsNode()` has equal-or-fewer nodes: it simplifies the structure based on `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#shouldMergeDescendantSemantics()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#shouldClearDescendantSemantics()`. For most purposes (especially accessibility, or the testing of accessibility), the merged semantics tree should be used.

Note: The implementation of `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).applySemantics()` should be used to set semantic properties or semantic actions. Don't call applySemantics() from within applySemantics(). It will result in an infinite loop.

## Public properties

### isImportantForBounds

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
open val isImportantForBounds: Boolean
```

Whether this semantics modifier node should be taken into account when computing the layout boundaries of the corresponding `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsNode`, which are used for accessibility and testing. By default, all semantics modifier nodes affect semantics bounds.

This property should be set to false if this node should be skipped when looking for a semantics modifier node that will be used to determine the semantics bounds of the layout node. For example, in a chain of Modifier.outerSemantics(..).padding(..).innerSemantics(..), the outerSemantics modifier should have `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#isImportantForBounds()` set to false if the semantics and accessibility bounds for the node should be determined by the bounds inside of the padding.

### shouldClearDescendantSemantics

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.5.0)

```
open val shouldClearDescendantSemantics: Boolean
```

Clears the semantics of all the descendant nodes and sets new semantics.

In the merged semantics tree, this clears the semantic information provided by the node's descendants (but not those of the layout node itself, if any) In the unmerged tree, the semantics node is marked with "`https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsConfiguration#isClearingSemantics()`", but nothing is actually cleared.

Compose's default semantics provide baseline usability for screen-readers, but this can be used to provide a more polished screen-reader experience: for example, clearing the semantics of a group of tiny buttons, and setting equivalent actions on the card containing them.

### shouldMergeDescendantSemantics

Cmn Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.5.0)

```
open val shouldMergeDescendantSemantics: Boolean
```

Whether the semantic information provided by this node 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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#shouldMergeDescendantSemantics()`) 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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsConfiguration#isMergingSemanticsOfDescendants()`.

## Extension functions

### SemanticsModifierNode.invalidateSemantics

Cmn Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/node/SemanticsModifierNode.kt+function:invalidateSemantics)

```
fun SemanticsModifierNode.invalidateSemantics(): Unit
```

Invalidate semantics associated with this node. This will reset the `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsConfiguration` associated with the layout node backing this modifier node, and will re-calculate it the next time the `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsConfiguration` is read.

Semantics are automatically invalidated when backed by mutable state, or if the hierarchy is recomposed. In these cases `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).applySemantics()` is called and the latest semantics values are applied. However in cases where semantics properties are not backed by mutable state objects, a change to the semantic property will not trigger `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).applySemantics()`. This function can be used to manually invalidate semantics to ensure that `https://developer.android.com/reference/kotlin/androidx/compose/ui/node/SemanticsModifierNode#(androidx.compose.ui.semantics.SemanticsPropertyReceiver).applySemantics()` will be called the next time the `https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/SemanticsConfiguration` is read.