Listbox

A single-select value picker with keyboard navigation, intelligent positioning, and Phoenix form integration. Use a listbox when users need to select one value from a predefined set of options.

Unlike Dropdown, which provides an action menu with role="menu", Listbox uses role="listbox" and works like a native <select>. It includes smart positioning with Floating UI , and its options match the trigger's width by default.

Quick Start

The most basic listbox requires three components: .listbox, .listbox_trigger, and .listbox_options with .listbox_option elements.

This example starts with "Cherry" selected through the value attribute. Selecting another option updates the .listbox_value content immediately.

Form Integration

.listbox renders a hidden <input> with the given name. Selecting an option updates the input and dispatches an input event. This makes a parent form's phx-change event run as it does for a native form field. Use .listbox_value to render the current value or a placeholder in the trigger.

Selected fruit (from server state): none

The selected fruit below the trigger comes from server state. It confirms that the phx-change event completed while the trigger value updated immediately.

Disabled Options

Disable a listbox option with the disabled=true attribute. Disabled options cannot receive focus or be selected.

Keyboard Interaction

The listbox provides keyboard navigation that follows standard ARIA patterns. Use the arrow keys to move between options and Enter or Space to select an option.

Key Description
When the trigger button is focused:
Enter / Space Opens the listbox and focuses the current selection (or the first option, if none)
Opens the listbox and focuses the first non-disabled option
Opens the listbox and focuses the last non-disabled option
When the listbox is open:
Esc Closes the listbox without changing the selection, and returns focus to the trigger
/ Focuses the previous/next non-disabled option (wraps around)
Home / End Focuses the first/last non-disabled option
Enter / Space Selects the focused option, updates the displayed value, and closes the listbox
A-Z / 0-9 Focuses the first option that starts with the typed character. Repeated presses cycle through matching options.