Skip to content

ScrollArea

Clip and scroll bounded child content.

On this page

Available with egui, Masonry and GPUI through the same public component API. Platform input and accessibility coverage still have alpha limits.

Usage

Replace src/App.iru in a scaffolded project with this complete file, then run cargo run. Keep the scaffold's main.rs and build.rs; this file includes its state, handlers and scoped styles.

src/App.iru
<view>
    <Column class="example">
        <Row class="actions">
            <Button text="Back to top" @click={top} class="action" />
            <Button text="Jump down" @click={bottom} />
        </Row>
        <Text text={format!("Vertical offset: {:.0}", offset)} />
        <ScrollArea height={Size::Px(240.0)} scroll_to={request} @scroll={observe_scroll} class="sample">
            <Input model:value={draft} placeholder="A draft stays editable while scrolling" />
            <For each={&messages} item="message" key={message.id}>
                <Text text={message.text.clone()} class="message" />
            </For>
        </ScrollArea>
    </Column>
</view>
<rust>
use inrux::prelude::*;

/// Stable keys identify the repeated rows.
#[derive(Clone)]
pub struct Message {
    id: u32,
    text: String,
}

let draft: String = String::new();
let messages: Vec<Message> = (1..=30)
    .map(|id| Message {
        id,
        text: format!("Message {id}"),
    })
    .collect();
let request: ScrollRequest = ScrollRequest {
    revision: 0,
    offset: ScrollOffset::default(),
};
let offset: f32 = 0.0;

/// A new revision issues a command without controlling later wheel movement.
fn top(state: &mut State, _: &Context<State>) {
    state.request.revision += 1;
    state.request.offset = ScrollOffset::default();
}
/// The viewport clamps an oversized requested offset to its content bounds.
fn bottom(state: &mut State, _: &Context<State>) {
    state.request.revision += 1;
    state.request.offset = ScrollOffset {
        x: 0.0,
        y: 10_000.0,
    };
}
/// Observe scrolling through the typed coordinator event path.
fn observe_scroll(state: &mut State, metrics: ScrollMetrics, _: &Context<State>) {
    state.offset = metrics.offset.y;
}
</rust>
<style scoped>
.example {
    padding: 24px;
    gap: 16px;
}
.actions {
    gap: 8px;
}
.action {
    background: #b84200;
    color: white;
    padding: 12px;
    border-radius: 6px;
}
.action:hover {
    background: #913400;
}
.action:focus-visible {
    border-width: 2px;
    border-color: #262626;
}
.sample {
    padding: 12px;
    gap: 8px;
    background: #f5f5f5;
}
.message {
    padding: 8px;
}
</style>

API Reference

Props

PropTypeDefaultDescription
scroll_toScrollRequestNot setProgrammatic offset request; increment its revision for each new command.

Common props

PropTypeDefaultDescription
idString-like expressionNot setStyle-selector identity; independent of retained mount identity.
classString-like expressionNot setWhitespace-separated stylesheet classes.
styleStyleNot setExplicit Rust style overrides for this node.
keyString-like expressionNot setRetained sibling identity; preserve it while reordering children.
widthSizeComponent styleExplicit width constraint; otherwise use the resolved style.
heightSizeComponent styleExplicit height constraint; otherwise use the resolved style.
paddingf32Component styleUniform padding in logical pixels; otherwise use the resolved style.
gapf32Component styleChild spacing in logical pixels; otherwise use the resolved style.

“Component style” means the attribute is omitted and the normal style cascade supplies the value. Application styles can override framework defaults.

Emits

EventPayloadDescription
@scrollScrollMetricsViewport size, content size and current offset; optional typed listener.

Bind events with @event={handler}. Ordinary handlers receive &mut State and &Context<State>; controlled value handlers can also receive the listed payload. With model:value or model:checked, the setter runs before the optional model listener, which reads the updated state. Stateless children forward a typed Emit<T>.

Behavior

ScrollArea defaults to full width, 240 logical pixels high, vertical auto and horizontal hidden. UI-owned offsets preserve native wheel responsiveness and system-adjusted direction. Nested routing, bounds and scrollbar geometry share policy across engines.

Styling and limits

Auto indicators hide after idle and reveal on edge interaction. overflow:scroll keeps them visible. Application padding belongs inside the viewport when the track should stay at the outer boundary. Input/TextArea manage their own editing viewports.

Read the detailed reference for validation and native integration details. The playgrounds include a working ScrollArea specimen with its surrounding state and reset controls.

Inrux · Built with Nuxt Content, IPEX, and Akaza UI.