Skip to content

rune-kit: Composable headless components and public reusable utilities #2653

Done

Description

@Vricken

rune-kit: Composable headless components and public reusable utilities

Motivation

Rune Kit provides a growing collection of themeable components, and Rune's underlying primitives allow applications to build custom UI from scratch.

However, there is an important middle ground between configuring an existing component and completely reimplementing it.

An application may want to retain most of a component's existing functionality while significantly changing its appearance, structure or interaction behaviour. Ideally, developers should be able to copy an existing Rune Kit component into their own crate, modify the relevant parts, and continue using its underlying shared utilities.

Currently, private helpers, internal state and tightly coupled presentation and behaviour can make this difficult without duplicating implementation logic or maintaining a fork.

This is particularly relevant given Rune's contribution model, where downstream developers cannot necessarily implement a change locally and have that exact implementation upstreamed through a pull request.

Proposed architectural principles

1. Separate behaviour from presentation

Where appropriate, components should be built on reusable, headless behavioural primitives, independently of their default visual implementations.

These could expose functionality such as:

  • Component state machines and interaction state.
  • Keyboard navigation and focus management.
  • Accessibility roles, properties and actions.
  • Selection, filtering and search behaviour.
  • Dragging, reordering and interaction lifecycle management.
  • Overlay positioning, dismissal and focus restoration.
  • Validation and editing behaviour.
  • Animation and transition state.

The existing styled Rune Kit components would consume these primitives, while applications could also use them to construct entirely different presentations.

For example, an application should be able to create a substantially different dropdown without independently implementing keyboard navigation, focus management, accessibility and selection behaviour.

Radix UI, React Aria and Base UI are useful references for this separation.

2. Expose reusable component utilities publicly

Where Rune Kit components rely on helpers that could reasonably be useful to downstream component authors, those helpers should be accessible through public APIs.

This includes:

  • Styling and visual-state utilities.
  • Theme token resolution.
  • Focus rings, disabled states and interaction feedback.
  • Layout, sizing and positioning helpers.
  • Selection and navigation utilities.
  • Reusable animation definitions.
  • Component state accessors and configuration types.
  • Shared event handling and callback abstractions.

Ideally, copying a component's implementation into an application should not require recursively copying unrelated private dependencies.

For example, Button and IconButton currently share internal helpers such as Skin, skin and paint in controls/actions.rs. Exposing suitable reusable styling abstractions would make it easier to construct custom button variants while preserving existing theme and interaction behaviour.

This does not necessarily mean making every implementation detail public. Internal invariants and implementation-specific machinery can remain private. The goal is to expose meaningful, reusable abstractions rather than requiring downstream developers to duplicate them.

3. Support structural customisation and composition

Theme tokens are useful for changing visual properties, but some customisations require changing the structure of a component.

Where appropriate, components should provide mechanisms for:

  • Replacing individual visual elements or component parts.
  • Supplying arbitrary El content.
  • Decorating existing elements without losing their behaviour.
  • Overriding rendering through callbacks or builders.
  • Accessing relevant internal state through public getters or handles.
  • Composing existing behavioural primitives in new ways.
  • Supporting component-owned state without unnecessarily requiring knowledge of the application's root state type.

For example, an application might want to replace a dropdown's trigger, customise how its options are rendered, or place its list inside a different overlay while retaining the underlying selection behaviour.

The objective is not to add a builder option for every conceivable customisation, but to provide sufficiently flexible composition primitives.

Existing precedents

Several previous issues appear to originate from this broader architectural limitation:

Many of these issues have subsequently been addressed. They are referenced here as examples of recurring architectural friction, rather than requests to implement those specific features again.

Source ownership and downstream development

The developer experience provided by shadcn/ui is another useful reference.

Developers can take ownership of individual components, modify them locally and continue depending on shared underlying primitives rather than maintaining a fork of the entire UI framework.

A similar approach in Rune Kit would be particularly valuable for AI-assisted development. An agent could inspect an existing component, adapt its implementation to an application's needs, and reuse the existing behaviour, accessibility, styling and interaction utilities.

This would also make it easier for third-party component libraries and design systems to develop independently of Rune Kit.

API stability and implementation scope

I understand that exposing additional APIs creates maintenance and compatibility obligations.

If useful, less mature extension APIs could be explicitly documented as experimental or unstable until their abstractions settle.

I'm not suggesting that every existing component needs to be immediately refactored, or that every private function should become public.

An incremental approach could establish these principles for new components and extract reusable functionality from existing components as they are developed or revisited.

The exact crate structure, API design and initial implementation scope are decisions I would leave to the maintainers.

Desired outcome

An application developer should be able to:

  1. Use an existing Rune Kit component unchanged.
  2. Customise it through theme tokens and configuration.
  3. Replace or compose individual parts while retaining existing behaviour.
  4. Copy its implementation into their own crate and modify it without recursively duplicating unrelated private dependencies.
  5. Build entirely new components using the same underlying behavioural and styling primitives.

A useful demonstration would be an external crate implementing a significantly customised dropdown or table while reusing Rune Kit's existing interaction logic, accessibility and theme utilities, without requiring a fork.

The broader goal is to make Rune Kit an extensible foundation for building component libraries, rather than only a collection of configurable, prebuilt components.

Would this align with Rune Kit's intended long-term architectural direction?

References

Activity

  1. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    some of this direction has already landed piecemeal on dev: rune-kit already exposes state machines (ComboboxState, ToastStackState, LineSelection, TableState, TreeModel, PaneState, Reorder, ZoomPan), overlay/layout pieces (popover::{anchored, raised, fit_scroll, anchor_rect}, scrim/scrim_tx, PopupList::build_list, Table::header, TableColumn::size_el), search::Fold, Kit::{interactive, elevate, alpha, on, selection}, and rune's state-independent El::*_any handlers (#1993, #2487).

    the gap is still real for copy-and-modify and custom controls: shared internals like Kit's visual-state/focus/disabled helpers (surface_state, hover_surface, overlay_state, focus_ring, focus_ring_state, disabled_dim in crates/rune-kit/src/tokens/kit.rs), list_nav (NavStep, NavAction, NavPolicy, TypeAhead, type_select), grip::Grip, Acts, over/press_over, and controls/actions.rs's Skin/skin/paint are pub(crate) or private, and most controls (Select, Menu, Dialog, Checkbox, Switch, Slider, etc.) couple keyboard/a11y behaviour directly to their styled builders.

    two architectural questions before deciding scope or exposing new APIs:

    1. direction and layout: should rune-kit commit to headless behavioural primitives plus public component-authoring utilities as an ongoing direction—and if so, should those live as modules inside rune-kit (for example primitives / style / nav) or in a separate headless crate underneath rune-kit?
    2. public surface and first slice: how broad a utility/headless API surface do we want to maintain, and if we do this incrementally, should the first concrete slice expose the already-shared internal utilities (Kit state/focus/dim helpers, list_nav, grip, button surface helpers) or extract one headless control (such as Select / Menu / Combobox) to establish the pattern?
  2. Vricken commented on Nov 27, 2026

    @Vricken
    Author

    Thanks for the detailed assessment.

    1. Direction and layout: Yes, I'd strongly favour headless behavioural primitives and public component-authoring utilities as an ongoing architectural direction. I don't have a strong preference regarding whether these live within rune-kit or in a separate crate, and would leave that decision to the maintainers.

    2. Public surface and first slice: From a downstream developer's perspective, exposing the existing shared utilities would already provide considerable immediate value, particularly for copying and adapting existing components. Separating behaviour from presentation would also be valuable in the longer term.

    However, I think the appropriate public API surface, implementation order and compatibility commitments are ultimately decisions best made by the maintainers.

    My main interest is establishing extensibility and composability as ongoing design principles, so developers can build upon and adapt Rune Kit without needing to fork it or request upstream changes for every customisation.

  3. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    that priority order is clear: exposing the already-shared internal utilities first (Kit visual-state/focus/disabled helpers, list_nav, grip, button surface helpers) unlocks copy-and-adapt downstream work immediately, with headless behavioural primitives following incrementally.

    leaving this under needs-design for a maintainer call on the long-term direction, crate/module layout, and public api surface.

  4. Vricken commented on Dec 2, 2026

    @Vricken
    Author

    @Hona Sorry for the ping, and thank you for implementing the animation sampling and date-time field requests!

    I wanted to highlight this particular issue because, of all my outstanding requests, I consider it the most important for Rune's long-term extensibility.

    Separating component behaviour from presentation and exposing shared component-authoring utilities would allow developers to build, adapt and extend components independently, without relying on upstream changes for every customisation or maintaining their own forks.

    I also think this would significantly benefit the broader Rune ecosystem by enabling third-party component libraries and custom design systems, while potentially reducing the number of feature requests maintainers need to handle themselves.

    As someone seriously considering migrating an existing desktop application to Rune, this architectural direction would be a significant factor in that decision.

    I'd really appreciate your thoughts on this proposal. No pressure, of course, and thanks again for all the work going into Rune!

  5. Hona commented on Dec 2, 2026

    @Hona
    Member

    Shipped in #3208 (1dcbb2c30) on dev.

    Design decision: Added an additive rune_kit::headless module alongside public re-exports of rune-kit's shared component-authoring utilities so downstream apps and custom design systems can reuse keyboard navigation, WAI-ARIA roles/states, focus management, disclosure state machines, and floating placement without adopting rune-kit's default visual chrome—while keeping existing styled components 100% source- and behavior-compatible:

    • Headless primitives (rune_kit::headless): Button, Toggle, Switch, Checkbox, Disclosure (+ DisclosureState), Listbox, Menu, Tabs (Automatic & Manual activation), and Popover wrapping caller-supplied El visuals with zero default styling.
    • Public reusable utilities: RovingFocus/ListNav, FloatingPlacement, Dismiss (outside_dismiss, escape_dismiss, modal_dismiss and *_tx variants), plus newly public list_nav, Grip, Acts, ButtonSkin, over, press_over, Placement::{split, from_parts, opposite_side}, and Kit visual-state/focus/disabled/motion helpers.

    Verified locally (Windows headless runtime):

    • cargo test -j 1 -p rune-kit --lib headless (10/10 passed), list_nav (7/7), grip (3/3), popover::tests (7/7)
    • cargo check -j 1 -p rune-kit --all-features and cargo check -j 1 -p rune-kit --target wasm32-unknown-unknown
    • scripts/file-size.sh (0 errors, 0 folder-shape issues)

    Not tested on real hardware: Interactive GUI windows, real macOS/Linux/Wayland/browser screen readers (VoiceOver/Orca/NVDA/DOM mirror), and GPU presentation were not run locally; please reopen if any edge case surfaces on real platforms.

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