Skip to content

rune-kit: TextArea: enable and style a scroll bar on its internal scroll viewport #908

Done

Description

@bobbywalters

Summary

TextArea::auto_grow and TextArea::max_height create an internal viewport keyed "scroll" that clips overflowing text, but there is no way to attach a kit scroll bar to it. As a result, a TextArea that scrolls internally never shows a scroll bar.

Why

El::scroll_bar_styled wraps the element it is called on. Applying it to the enclosing layout element does not work, because that element does not overflow: TextArea caps and scrolls its own internal viewport.

For example, this does not show a scroll bar:

let composer = col()
    .padding(16.0)
    .scroll(ScrollSpec { stick_bottom: true })
    .child(
        TextArea::new(&state.draft)
            .auto_grow(2, 6)
            .build(&k),
    );

// The bar is attached to the outer viewport, which never overflows.
col().child(composer.scroll_bar_styled(ScrollBarStyle::from_kit(&k)));

The viewport that actually overflows is the one created inside TextArea::build by rune::auto_grow(field, min_rows, max_rows), keyed "scroll". It currently has no way to opt into a scroll bar.
Proposed API
Mirror El::scroll_bar and El::scroll_bar_styled on TextArea:

TextArea::new(&state.draft)
    .auto_grow(2, 6)
    .scroll_bar_styled(ScrollBarStyle::from_kit(&k))
    .build(&k);

Implementation sketch
Add option fields to TextArea, then wrap the internal viewport in build if enabled:

pub struct TextArea {
    // ...
    scroll_bar: Option<bool>,
    scroll_bar_style: Option<ScrollBarStyle>,
    // ...
}

impl TextArea {
    /// Enable or disable a visible scroll bar. Use the `Kit` supplied during build if enabled.
    /// Use `scroll_bar_styled` to enable the scroll bar with a passed in style rather than generated.
    pub fn scroll_bar(mut self, on: bool) -> Self {
        self.scroll_bar = if on { Some(true) } else { None };
        self.scroll_bar_style = None;
        self
    }

    /// Draw a scroll bar on the field's internal scroll viewport using the supplied style.
    /// Use `scroll_bar` to generate the scroll bar styling during `build` instead of supplying one.
    pub fn scroll_bar_styled(mut self, style: ScrollBarStyle) -> Self {
        self.scroll_bar = Some(true);
        self.scroll_bar_style = Some(style);
        self
    }

    pub fn build(self, k: &Kit) -> El {
        // ...
        let viewport = rune::auto_grow(field, min_rows, max_rows);
        let viewport = match self.scroll_bar {
            Some(true) => viewport.scroll_bar_styled(style.unwrap_or(ScrollBarStyle::from_kit(&k))),
            _ => viewport,
        };
        // ...
    }
}

The same wrapping should apply to the viewport created by the max_height branch.

Should also have a clean way to turn the scroll bar on and off and use either a supplied style or one generated from the Kit during build.

Wanted to note it for completeness but I don't think the ScrollBar trait impl is needed on TextArea (impl ScrollBar for TextArea). The underlying El that TextArea::build produces will implement it already. But the function names match for consistency.

Activity

  1. Hona commented on Nov 24, 2026

    @Hona
    Member

    Implemented on dev in #1967 (0c85015b7).

    TextArea::scroll_bar(bool) and TextArea::scroll_bar_styled(ScrollBarStyle) attach a kit scroll bar to the internal "scroll" viewport created by auto_grow or max_height (a no-op when neither is set; off by default), following rune::system_scroll_bars() and keeping focus and caret intact while dragging the thumb. The API follows Tree::scroll_bar / Tree::scroll_bar_styled (crates/rune-kit/src/tree/view.rs) and ScrollBar (crates/rune-kit/src/scroll_bar.rs), matching your proposed builder names (with a single internal enum so scroll_bar(false) clears an earlier style). See examples/kit-gallery scene rune-textarea--composer.

    TextArea::new(&s.draft)
        .label("Release notes")
        .auto_grow(2, 6)
        .scroll_bar_styled(ScrollBarStyle::from_kit(&k).always_visible())
        .on_edit(|s: &mut App| &mut s.draft).build(&k)

    Tested with headless Runtime integration and accessibility tests in crates/rune-kit/tests/integration/text_area_chrome.rs and crates/rune-kit/tests/a11y/controls.rs (covering auto_grow, max_height, custom styles, sibling independence, RTL, and a11y_hidden) on Windows and macOS, plus Linux cargo check --tests, kit-gallery build tests, and wasm32 checks. Not visually inspected in a live desktop window or on physical devices. If anything is missing for your use case, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions