---
title: "SearchBarScrollBehavior"
description: "A [SearchBarScrollBehavior] defines how a search bar should behave when the content beneath it is
scrolled."
type: "interface"
---

<div class='type'>Interface</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>



```kotlin
@ExperimentalMaterial3Api
interface SearchBarScrollBehavior
```


A `SearchBarScrollBehavior` defines how a search bar should behave when the content beneath it is
scrolled.


## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
@get:FrequentlyChangingValue var scrollOffset: Float
```


The search bar's current offset due to scrolling, in pixels. This offset is applied to the
fixed size of the search bar to control the displayed size when content is being scrolled.

This value is typically negative.

Updates to the `scrollOffset` value are coerced between `scrollOffsetLimit` and 0.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
var scrollOffsetLimit: Float
```


The limit that a search bar can be offset due to scrolling, in pixels.

This value is typically negative.

Use this limit to coerce the `scrollOffset` value when it's updated.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@get:FrequentlyChangingValue var contentOffset: Float
```


The total offset of the content scrolled under the search bar.

The content offset is used to compute the `overlappedFraction`, which can later be read by an
implementation.

This value is updated by a `SearchBarScrollBehavior` whenever a nested scroll connection
consumes scroll events. A common implementation would update the value to be the sum of all
`NestedScrollConnection.onPostScroll` `consumed.y` values.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val nestedScrollConnection: NestedScrollConnection
```


A `NestedScrollConnection` that should be attached to a
`androidx.compose.ui.input.nestedscroll.nestedScroll` in order to keep track of scroll
events.



## Functions

```kotlin
fun Modifier.searchBarScrollBehavior(): Modifier
```


The modifier that adds scrolling behavior to the search bar component. `AppBarWithSearch`
applies this automatically.



