WindowedItem
HkWindowedItem is one item of a virtualised list: a wrapper that either renders its content (when the item is inside the scroll window) or holds the item's space without its content (when it is outside). That reserved box is the whole trick — the scroll length never collapses as content leaves the window, so the scrollbar does not twitch and the page does not reflow while the user drags — and the wrapper is invisible either way, so it can be used with any item markup inside.
- The wrapper renders one item. The list, its scroll root and which items exist are the host's; this component only answers "should this item draw its children right now".
- In Vue the answer comes from the scroll-window context and the item's own geometry. In Rust the answer is the in_window prop you pass, with the same arithmetic exported as pure functions. That asymmetry is the subject of the third section.
- A list that grows as the user reaches the bottom is InfiniteTail, not this: the tail appends real rows and never swaps contents. A windowed list has a fixed length the scrollbar can be trusted on.
- The container that publishes the scroll window context in Vue is ScrollContainer in its windowed mode.
Import
;
use *; // WindowedItem, windowed_item_in_buffer
use *; // WindowedItemProps, rsx!, VNode
The Rust form is a plain function, WindowedItem(WindowedItemProps { … }); inside rsx! the element form is WindowedItem { … } and every prop may be omitted except children, whose own Default is the empty element. Vue's as is spelled tag in Rust — as is a Rust keyword, the same rename other mirrors apply — and itemKey, estimatedHeight, overscanScreens become item_key, estimated_height, overscan_screens.
The two arms: real content and a reserved box
The root element always carries two data attributes: data-state ("real" or "placeholder") and data-windowed-key (the item's identity, absent when the host gave none). The real arm renders the default slot and carries no inline style. The placeholder arm renders the slot's absence: no children at all, aria-hidden="true", and one inline declaration reserving the height — measuredHeight when the host has measured the item, estimatedHeight (default 96) until then.
The sheet makes that box inert and transparent: pointer-events: none and a transparent background, so it neither receives a press nor paints over the surface. It is still a real box in the layout, which is what makes the scroll length stable.
as (Rust tag) picks the element — div by default, li inside a ul, article for an article list. The wrapper adds no chrome beyond display: block and break-inside: avoid, so the item's own markup owns all of the visual structure.
A placeholder arm carries the same height and no content at all.
Outside a scroll-window context the wrapper always takes the real arm — Vue treats a missing context as "nothing to judge against" and the Rust mirror's in_window: None means the same thing — so a bare HkWindowedItem on its own is a plain wrapper. That is why the first example renders exactly like an unwrapped item.
Who decides the window
In Vue the wrapper decides on its own — but only inside a scroll-window context, which the page publishes by putting the list in a windowed scroll container. On mount it reads that context (the scroll root and the default overscan), judges whether the item is within one overscan screen of the root using the drawn rectangle against clientHeight — scaling the buffer by the root's drawn scale, because a zoomed or scaled root makes the rects bigger than the laid-out height — and then keeps the answer live with an IntersectionObserver whose root is the scroll root and whose rootMargin is the overscan — as a percentage of the root's own box above and below, Math.round(overscan * 100)%, so it scales with the container instead of assuming a screen height. When the item re-enters it re-measures the height so the reserved box tracks the real one.
The overscan resolves as overscanScreens on the item, then the context's value, then one screen. The scaling arithmetic and the margin string are exported by the Rust mirror as windowed_item_overscan_scale / windowed_item_in_buffer and windowed_item_root_margin, so a host that runs its own observer reproduces the verdict exactly.
The Rust mirror cannot run either half — the vdom has no DOM lifecycle — so the membership is a controlled prop: in_window: Some(true) renders the real arm, Some(false) the reserved box, and None the real arm unconditionally (Vue's no-context case). measured_height is likewise a prop holding the host's last positive reading; the mirror does not clamp it, because clamping would silently disagree with the height the box reserves.
overscanScreens is the mirror's one prop that never reaches the DOM: it is the number a host's own observer — and windowed_item_in_buffer — consumes. In Vue it reaches the observer's margin instead. Both examples above resolve to the real arm (the mirror's default in_window: None), because that is the arm a static render can show.
The still frame
A windowed list is defined by motion: rows leave the window as the user scrolls and their boxes stay behind. A snapshot has no scroll, no viewport relative to the tail, and no observer, so every example on this page renders its real arm — the placeholder arm is the one thing a static render cannot demonstrate. To read the reserved box in a snapshot, drive in_window: Some(false) explicitly in Rust (or mount the Vue component without a windowed scroll container and accept the real arm); the attributes are data-state="placeholder", aria-hidden="true" and a single height: declaration.
[D] Two mirror-only props exist for exactly this: offset_top stamps top:{V}px next to the reserved height, for a host that positions windowed rows absolutely — Vue leaves positioning entirely to the host's flow and this file cannot invent one. With offset_top: None the style attribute is Vue's byte for byte. And class is the mirror's spelling of the class Vue merges into the root automatically, appended after hk-windowed-item.
The items of a windowed list are a host concern: this component renders one item, and the loop, the keys and the total length are the page's. The Vue side's scroll-window provider, which the windowed mode of ScrollContainer publishes, has no Rust counterpart: there the scroll root belongs to the host and the overscan arrives as a prop on each item.
API
Vue
Props
| Name | Type | Default | Required |
|---|---|---|---|
| itemKey | String | undefined | — |
| estimatedHeight | Number | 96 | — |
| overscanScreens | <code>Number as PropType<number | null></code> | null | — |
| as | String | "div" | — |
Rust
Props — WindowedItem
| Prop | Type | Default | Description |
|---|---|---|---|
| item_key | Option<String> | None | The item's identity, stamped as data-windowed-key (Vue: itemKey; absent when the host has no key). |
| estimated_height | f64 | 96.0 | Height reserved by the placeholder before the item is measured, in px (Vue: estimatedHeight, default 96). |
| overscan_screens | Option<f64> | None | The window buffer in screens (Vue: overscanScreens, default null). |
| tag | String | "div".to_string() | Host element tag (Vue as, default div). |
| in_window | Option<bool> | None | CONTROLLED window membership (Vue: inWindow + the presence of the scroll-window context). |
| measured_height | Option<f64> | None | The host's last measured height, in px (Vue: measuredHeight). |
| offset_top | Option<f64> | None | [D] Mirror-only: the item's top offset in px for an absolutely positioned windowed row (Vue leaves positioning to the host's flow). |
| class | String | "" | Extra class appended to the root (Vue merges the fallthrough class). |
| children | Element | (empty) | The item's content (Vue: the default slot). |
Accessibility
- The real arm is ordinary content with no role of its own, so the item's semantics come from whatever element as names and from what the host puts inside it. A ul of as="li" wrappers is a real list; a div stack of them is not.
- The placeholder arm is aria-hidden="true" and pointer-inert: a screen reader never meets an empty box, and a pointer never presses one. The reserved height is layout only — assistive technology is told nothing about how far down the list a user is, which is correct, since nothing there is content.
- Nothing here manages focus. Scrolling an item out of the window removes its content from the DOM, so an item that holds the focused element must not be allowed to leave — keep the focused item inside the overscan, or move focus to a stable control before the window moves past it.
- The placeholder has no accessible name and no live-region role; a list that wants to announce "showing rows 21 to 40" says so with its own status text, not through these wrappers.
- Because the placeholder reserves the measured height rather than an estimated one wherever possible, the scrollbar a keyboard or screen-reader user moves with stays stable — an estimate that is far off turns scrolling into a jump, which is a usability problem before it is a visual one.
Related components
- InfiniteTail — the list that grows with real rows, with skeleton placeholders and an end note.
- ScrollContainer — the container that publishes the scroll-window context in Vue; its mode="windowed" and overscanScreens are what this wrapper reads.
- CardList — the non-virtualised list surface, for lists short enough to deliver whole.
- Skeleton — the placeholder atom, when the reservation should look like loading rather than like empty space.
- Table — the tabular sibling, when the windowed data is columns rather than a column of items.