Combobox

A fully accessible searchable input with intelligent positioning, keyboard navigation, and flexible data handling. Perfect for autocomplete scenarios, large option sets, and user-generated content.

The combobox combines text input with dropdown suggestions, supporting both frontend filtering and server-side async search. Features full keyboard navigation, smart positioning with Floating UI, and seamless Phoenix form integration.

Quick Start

The most basic combobox requires three components: .combobox, .combobox_input, and .combobox_options with .combobox_option elements.

Start typing to filter through options. The component automatically handles frontend filtering and keyboard navigation. Use arrow keys to navigate and Enter to select.

Advanced Usage

Server-side Search

For large datasets or dynamic content, enable server-side search by adding phx-change to the input. The component automatically switches to async mode with debounced search queries.

The async pattern sends search queries to your LiveView with automatic debouncing. Handle the phx-change event to filter results server-side and update the options dynamically.

Create Custom Values

Allow users to create values that don't exist in the predefined list using the .creatable_option component. Perfect for tags, categories, or any user-generated content scenarios.

Type a custom tag name and press Enter to create a new one.

The creatable option automatically appears when the user types something that doesn't match existing options. It shows "Create '[user input]'" and submits the typed value when selected.

Multiple Selection

Enable multiple selection by adding the multiple={true} attribute to the combobox. Use the .combobox_selections component to display selected items as removable pills.

Select multiple skills. Click the × button or press Backspace to remove selections.

The .combobox_selections component uses a template-based approach for rendering pills. Customize the appearance using the :selection slot - it supports any markup including icons, badges, and remove buttons. The dropdown stays open after each selection for quick multi-select workflows, and selected items are visually highlighted with data-selected="true".

For a react-select style appearance, wrap the selections and input in a flex container styled to look like an input field. The pills and input appear together in the same visual container, creating a seamless multi-select experience.

Smart Positioning

Powered by Floating UI, the combobox intelligently positions itself using the placement and offset attributes. It automatically flips to the opposite side when there's insufficient space.

Use placement="top-start", placement="right-start", or other positioning options. The component automatically repositions on scroll and window resize to stay visible.

Flexible Markup

Combobox options support rich, custom markup including icons, descriptions, badges, and complex layouts. The component is completely unstyled, giving you full control over the visual presentation.

Build complex option layouts with multiple text elements, icons, images, or any HTML content. Use group-data-focus:text-white and similar selectors to style elements based on focus state.

Styling States

Combobox options expose two data attributes for styling different interaction states:

  • data-focus - Set to true when an option is focused via keyboard navigation or mouse hover. Perfect for highlighting the currently focused item.
  • data-selected - Set to true on the option that matches the current selection. Use this to visually indicate which option is selected, even when reopening the dropdown.

Use Tailwind's data-focus: and data-selected: modifiers to style these states.

Keyboard Interaction

The combobox component provides full keyboard accessibility with comprehensive navigation support. All interactions follow standard ARIA patterns for combobox components.

Key Description
When the input is focused:
/ Opens the combobox and focuses the first option
When the combobox is open:
Esc Closes the combobox and restores the previously selected value
/ Focuses the previous/next option (wraps around)
Home / PageUp Focuses the first option
End / PageDown Focuses the last option
Enter Selects the currently focused option and closes the combobox
Tab Selects the currently focused option and closes the combobox
A-Z / a-z Filters available options (frontend mode) or triggers search event (async mode)
Backspace Removes the last selected item (multi-select mode, when input is empty)