Keyboard navigation of a list in one placement: a roving tab stop, type to
find, and PageUp and PageDown. One Bundle holds the current item's id and
the typeahead query, so a printable key can move the pointer and extend the
query in one transition, which two placements cannot do under virtual.
The resolver allows one owner per event on a slot, so a host that needs
both arrows and typeahead takes this, not RovingTabindex plus Typeahead .
ListNavigation.Args# const · packages/primitives/src/interaction/list-navigation.ts:37
const Args: Schema . Struct <{
readonly orientation: Schema . Literals <
readonly ['vertical' , 'horizontal' , 'both' ]
>
readonly loop: Schema . Boolean
readonly virtual: Schema . Boolean
readonly timeoutMs: Schema . Number
readonly page: Schema . Number
}> ListNavigation.behavior# function · packages/primitives/src/interaction/list-navigation.ts:302
function behavior < Field extends string >(
declared: Declared < typeof bundle, Field >,
args: Args ,
) : {
< Slots , Input extends { readonly [K in Field ]: Model }, ParentMessage >(
bound: SlotView . Bound < Slots , Input , ParentMessage >,
) : <
Container extends keyof Slots & string ,
Item extends keyof Slots & string ,
> (
options: BehaviorOptions < Input , Slots , ParentMessage , Container , Item >,
) => Behavior . NamedBehavior <
Slots ,
Input ,
ParentMessage ,
| A11y . ProvidedOn < Container , 'navigation' >
| A11y . ProvidedOn < Item , 'focus-strategy' >
>
< Slots >(
slots: SlotView . Unbound < Slots >,
) : < Input extends { readonly [K in Field ]: Model }, ParentMessage > (
options: BehaviorOptions < Input , Slots , ParentMessage >,
) => Behavior . NamedBehavior < Slots , Input , ParentMessage >
} Show all 24 lines Wires a placed ListNavigation to the slots. The container gets the keys
route as its one key handler. Each item gets tabindex and OnFocus as
under RovingTabindex . Under virtual nothing takes DOM focus and the
container carries aria-activedescendant.
ListNavigation.BehaviorOptions# interface · packages/primitives/src/interaction/list-navigation.ts:103
interface BehaviorOptions <
Input ,
Slots ,
ParentMessage ,
Container extends keyof Slots & string = keyof Slots & string ,
Item extends keyof Slots & string = keyof Slots & string ,
> extends KeyOptions< Input , ParentMessage > {
readonly container: Container
readonly item: Item
} ListNavigation.bundle# const · packages/primitives/src/interaction/list-navigation.ts:72
const bundle: Bundle . Bundle <
'ListNavigation' ,
{
readonly orientation: 'both' | 'horizontal' | 'vertical'
readonly loop: boolean
readonly virtual: boolean
readonly timeoutMs: number
readonly page: number
},
{
readonly current: string | null
readonly query: string
readonly generation: number
},
| { readonly _tag: 'Cleared' }
| { readonly _tag: 'Focused' ; readonly id: string }
| {
readonly _tag: 'Typed'
readonly char: string
readonly match: string | null
}
| { readonly _tag: 'Expired' ; readonly generation: number },
never ,
never ,
never ,
NoView ,
{},
{
focus : (
model: Model ,
id: string ,
) => Readonly <{
model: {
readonly current: string | null
readonly query: string
readonly generation: number
}
commands?: Update . Commands <
| { readonly _tag: 'Cleared' }
| { readonly _tag: 'Focused' ; readonly id: string }
| {
readonly _tag: 'Typed'
readonly char: string
readonly match: string | null
}
| { readonly _tag: 'Expired' ; readonly generation: number },
never
>
outMessage?: never
}>
},
undefined
> Show all 53 lines ListNavigation.item# function · packages/primitives/src/interaction/list-navigation.ts:262
function item < Field extends string >(
declared: Declared < typeof bundle, Field >,
args: Args ,
) : {
< Slots , Input extends { readonly [K in Field ]: Model }, ParentMessage >(
bound: SlotView . Bound < Slots , Input , ParentMessage >,
) : < Item extends keyof Slots & string > (
options: ItemOptions < Input , Slots , Item >,
) => Behavior . NamedBehavior <
Slots ,
Input ,
ParentMessage ,
A11y . ProvidedOn < Item , 'focus-strategy' >
>
< Slots >(
slots: SlotView . Unbound < Slots >,
) : < Input extends { readonly [K in Field ]: Model }, ParentMessage > (
options: ItemOptions < Input , Slots >,
) => Behavior . NamedBehavior < Slots , Input , ParentMessage >
} Show all 20 lines The item half of behavior, for a container whose keydown is a router's
(Keys.behavior listing keys beside routes of its own): each item gets
tabindex (none under virtual) and an OnFocus reporting it current, so
neither the items' attributes nor the Focused Message is written by hand.
ListNavigation.ItemOptions# interface · packages/primitives/src/interaction/list-navigation.ts:209
interface ItemOptions <
Input ,
Slots ,
Item extends keyof Slots & string = keyof Slots & string ,
> {
readonly item: Item
readonly items : ( input: Input ) => Behaviors . Collection . Items < unknown >
} ListNavigation.KeyOptions# interface · packages/primitives/src/interaction/list-navigation.ts:84
interface KeyOptions < Input , ParentMessage > {
readonly items : ( input: Input ) => Behaviors . Collection . Items < unknown >
readonly text : ( input: Input , index: number ) => string
readonly direction ?: ( input: Input ) => RovingTabindex . Direction
readonly typeahead?: boolean
readonly commit ?: ( input: Input , id: string ) => ParentMessage
} ListNavigation.KeyOutcome# type · packages/primitives/src/interaction/list-navigation.ts:119
type KeyOutcome =
| {
readonly _tag: 'Navigate'
readonly id: string
}
| {
readonly _tag: 'Type'
readonly char: string
readonly match: string | null
} The key's outcome, before it is turned into an attribute: navigation to an
id, a typed character with its match, or nothing.
ListNavigation.keyOutcome# function · packages/primitives/src/interaction/list-navigation.ts:123
function keyOutcome (
items: Behaviors . Collection . Items < unknown >,
texts: ReadonlyArray < string >,
state: {
readonly current: string | null
readonly query: string
},
key: string ,
modifiers: KeyboardModifiers ,
options: RovingTabindex . MoveOptions ,
) : KeyOutcome | undefined ListNavigation.keys# function · packages/primitives/src/interaction/list-navigation.ts:149
function keys < Field extends string >(
declared: Declared < typeof bundle, Field >,
args: Args ,
) : < Input extends { readonly [K in Field ]: Model }, ParentMessage > (
options: KeyOptions < Input , ParentMessage >,
) => Behaviors . Keys . Route < Input , ParentMessage > The route a ListNavigation installs on its container: arrows, Home, End,
PageUp and PageDown move by id; a printable key extends the query and moves
to its match (unless typeahead is off); Enter commits when commit is
given. Focus moves to the item answered; under virtual the route sends the
Message alone. List it in a Keys.behavior beside routes of your own, such
as one that clears a search field on Escape.
ListNavigation.Message# const · packages/primitives/src/interaction/list-navigation.ts:27
const Message: MessageUnion <{
readonly Focused: { readonly id: Schema . String }
readonly Typed: {
readonly char: Schema . String
readonly match: Schema . NullOr < Schema . String >
}
readonly Expired: { readonly generation: Schema . Number }
readonly Cleared: {}
}> ListNavigation.Model# const · packages/primitives/src/interaction/list-navigation.ts:20
const Model: Schema . Struct <{
readonly current: Schema . NullOr < Schema . String >
readonly query: Schema . String
readonly generation: Schema . Number
}>