Skip to content

SelectionListNode: add WithHighlightedIndex() for pre-selection#213

Merged
Aaronontheweb merged 3 commits into
devfrom
feature/selection-node-highlighted-index
May 18, 2026
Merged

SelectionListNode: add WithHighlightedIndex() for pre-selection#213
Aaronontheweb merged 3 commits into
devfrom
feature/selection-node-highlighted-index

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Owner

Summary

SelectionListNode<T> always started with item index 0 highlighted and exposed no public API to change it. This blocks pre-selection when re-entering a previously configured view (e.g. a wizard edit flow where the user's prior choice should be re-highlighted).

Adds WithHighlightedIndex(int) — a fluent builder consistent with WithMode, WithHighlightColors, etc.

Changes

  • Add WithHighlightedIndex(int) fluent builder
    • Clamps the index to the valid range
    • Ignores the call when the list is empty — the issue's proposed Math.Clamp(index, 0, _items.Count - 1) throws ArgumentException (min > max) on an empty list; guarding avoids that
    • Calls EnsureVisible() so a pre-selected off-screen item is scrolled into view on the first render
  • 6 new tests: fluent return, sets highlight, clamps above range, clamps negative, empty-list guard, scroll-into-view
  • Docs: new "Pre-selecting an Item" section + API reference table entry

Testing

All 1018 tests pass (1012 existing + 6 new), 0 failures.

Fixes #203

SelectionListNode<T> always started highlighting at index 0 with no
public way to pre-select an item -- e.g. a wizard edit flow that should
re-highlight the user's prior choice.

- Add WithHighlightedIndex(int) fluent builder; clamps to the valid
  range, ignores the call when the list is empty (avoids Math.Clamp
  throwing on min > max), and calls EnsureVisible() to scroll the
  pre-selected item into view
- 6 new tests covering fluent return, clamping (both ends), the
  empty-list guard, and scroll-into-view on first render
- Document the new method and add it to the API reference table

Fixes #203
Adds WithHighlightedIndex(49) to the Gallery's column 3 so the 100-item
fill-height list opens scrolled to item #50 instead of the top --
visually demonstrating pre-selection and scroll-into-view together.
@Aaronontheweb Aaronontheweb merged commit 1dcc48e into dev May 18, 2026
8 checks passed
@Aaronontheweb Aaronontheweb deleted the feature/selection-node-highlighted-index branch May 18, 2026 16:49
@Aaronontheweb Aaronontheweb mentioned this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectionListNode: add WithHighlightedIndex to support pre-selection

1 participant