Forwarding Keyboard Inputs
The List widget supports receiving keyboard events from other widgets through the pipeKeyDown prop. A common use case is a search interface where the user types in a TextField while navigating results with arrow keys.
<div
controller={PageController}
class="flex flex-col gap-2"
style="width: 300px"
>
<TextField
value={m.query}
placeholder="Search..."
onKeyDown={(e, instance) =>
instance.getControllerByType(PageController).onKeyDown(e)
}
inputAttrs={{ autoComplete: "off" }}
autoFocus
/>
<List
records={m.filteredRecords}
selection={{ type: KeySelection, bind: m.selection, keyField: "id" }}
mod="bordered"
style="height: 200px; overflow-y: auto"
emptyText="No items found."
recordAlias={m.$record}
pipeKeyDown={(cb, instance) =>
instance.getControllerByType(PageController).pipeKeyDown(cb)
}
focused
scrollSelectionIntoView
>
<HighlightedSearchText text={m.$record.text} query={m.query} />
</List>
</div> - Australia
- Austria
- Belgium
- Brazil
- Canada
- Denmark
- Finland
- France
- Germany
- Italy
- Japan
- Netherlands
- Norway
- Spain
- Sweden
- Switzerland
- United Kingdom
- United States
How It Works
- The List’s
pipeKeyDownprop receives a callback for forwarding keyboard events - Store the callback in the controller using
getControllerByTypefor type safety - On the TextField’s
onKeyDown, forward arrow and enter keys to the stored callback - Use
focusedprop to enable keyboard navigation without clicking the list - Use
scrollSelectionIntoViewto keep the selected item visible