Combobox

v0.0.10

v0.0.10StableComponentStatelessJSApache-2.0
Installation mix mishka.ui.gen.component combobox
Source View Source

Overview of combobox component

The Phoenix LiveView combobox component provides a searchable dropdown select field that allows users to choose from a list of options. It combines the functionality of both an input field and a dropdown menu, making it ideal for selecting from large datasets. The component is built with a Phoenix Scroll Area component inside to handle large option lists smoothly. It supports dynamic filtering of options as users type, keyboard navigation, and customizable styling through various props like color, size, and border radius.

Overview of combobox component

Select multiple pets from different categories

Base variant

Base variant

heex
<.combobox>
  <:option value="ca">Canada</:option>
  <:option value="us">United States</:option>
  <:option value="mx">Mexico</:option>
  <:option value="sp">Spain</:option>
  <:option value="de">Germany</:option>
  <:option value="jp">Japan</:option>
  <:option value="ch">China</:option>
  <:option value="sw">Sweden</:option>
</.combobox>

Default variant

Default variant

heex
<.combobox variant="default"></.combobox> //natural
<.combobox variant="default" color="primary"></.combobox>
<.combobox variant="default" color="secondary"></.combobox>
<.combobox variant="default" color="misc"></.combobox>
<.combobox variant="default" color="dawn"></.combobox>
<.combobox variant="default" color="info"></.combobox>
<.combobox variant="default" color="danger"></.combobox>
<.combobox variant="default" color="success"></.combobox>
<.combobox variant="default" color="warning"></.combobox>
<.combobox variant="default" color="silver"></.combobox>

Bordered variant

Bordered variant

heex
<.combobox variant="bordered"></.combobox> //natural
<.combobox variant="bordered" color="primary"></.combobox>
<.combobox variant="bordered" color="secondary"></.combobox>
<.combobox variant="bordered" color="misc"></.combobox>
<.combobox variant="bordered" color="dawn"></.combobox>
<.combobox variant="bordered" color="info"></.combobox>
<.combobox variant="bordered" color="danger"></.combobox>
<.combobox variant="bordered" color="success"></.combobox>
<.combobox variant="bordered" color="warning"></.combobox>
<.combobox variant="bordered" color="silver"></.combobox>

Label prop

You can use the label prop to add custom title text above the combobox.

Label prop

heex
<.combobox label="This is label"></.combobox>

Description prop

The description prop allows you to add explanatory text below the label for additional context about the combobox.

Description prop

Description of filed
heex
<.combobox description="This is description"></.combobox>

Rounded prop

The rounded prop offers values like "extra_small", "small", "medium", "large", and "extra_large".

Rounded prop

heex
<.combobox rounded="extra_small"></.combobox>
<.combobox rounded="small"></.combobox>
<.combobox rounded="medium"></.combobox>
<.combobox rounded="large"></.combobox>
<.combobox rounded="extra_large"></.combobox>

Border prop

The border prop offers values like "extra_small", "small", "medium", "large", and "extra_large".

Border prop

heex
<.combobox border="extra_small"></.combobox>
<.combobox border="small"></.combobox>
<.combobox border="medium"></.combobox>
<.combobox border="large"></.combobox>
<.combobox border="extra_large"></.combobox>

Padding prop

The padding prop offers values such as "extra_small", "small", "medium", "large", and "extra_large". These values set the horizontal padding of the combobox trigger.

Padding prop

heex
<.combobox padding="extra_small"></.combobox>
<.combobox padding="small"></.combobox>
<.combobox padding="medium"></.combobox>
<.combobox padding="large"></.combobox>
<.combobox padding="extra_large"></.combobox>

Space prop

The space prop offers values such as "extra_small", "small", "medium", "large", and "extra_large". These values set the vertical space between the label, the description and the trigger.

Space prop

heex
<.combobox space="extra_small"></.combobox>
<.combobox space="small"></.combobox>
<.combobox space="medium"></.combobox>
<.combobox space="large"></.combobox>
<.combobox space="extra_large"></.combobox>

Size prop

The size prop offers values such as "extra_small", "small", "medium", "large", and "extra_large". These values set the minimum height of the trigger, the size of its icon and the text size of the trigger and the options.

Size prop

heex
<.combobox size="extra_small"></.combobox>
<.combobox size="small"></.combobox>
<.combobox size="medium"></.combobox>
<.combobox size="large"></.combobox>
<.combobox size="extra_large"></.combobox>

Searchable prop

The searchable prop is a boolean. It adds a search box at the top of the dropdown, so the user can type to filter the options.

Searchable prop

heex
<.combobox searchable></.combobox>

Search placeholder prop

The search_placeholder prop sets the placeholder text of the search box.

Search placeholder prop

heex
<.combobox searchable search_placeholder="Search a country"></.combobox>

Group Combobox

Group Combobox

heex
<.combobox>
  <:option group="Cars" value="sedan">Sedan</:option>
  <:option group="Cars" value="suv">SUV</:option>
  <:option group="Cars" value="coupe">Sports Coupe</:option>
  <:option group="Cars" value="hatchback">Hatchback</:option>

  <:option group="Motorcycles" value="cruiser">Cruiser</:option>
  <:option group="Motorcycles" value="sport">Sport Bike</:option>
  <:option group="Motorcycles" value="touring">Touring</:option>
  <:option group="Motorcycles" value="dirt">Dirt Bike</:option>

  <:option group="Commercial" value="truck">Delivery Truck</:option>
  <:option group="Commercial" value="van">Cargo Van</:option>
  <:option group="Commercial" value="bus">Bus</:option>
</.combobox>

Multi Select

The multiple prop is a boolean that enables multi-select functionality in the combobox. When enabled, users can select multiple options which will appear as tags in the input field.

Multi Select

heex
<.combobox multiple={true}>
  <:option value="apple">Apple</:option>
  <:option value="banana">Banana</:option>
  <:option value="orange">Orange</:option>
  <:option value="mango">Mango</:option>
</.combobox>

Creatable prop

The creatable prop enables users to add new options directly from the search input when no matching result is found. This is useful for dynamic forms where predefined options may not cover all user needs, such as tag management, category assignment, or custom field entries. When enabled, a button labeled Create 'typed text' appears in the dropdown, allowing inline option creation without leaving the form. Use the create_label prop to change the word before the typed text and the on_create prop to specify a server event that is pushed when a new option is created.

Creatable prop

heex
<.combobox
  id="language-select"
  options={@creatable_languages}
  placeholder="Select a language"
  searchable
  creatable
  create_label="Add"
  on_create="add_language"
/>

# In your LiveView — reject by pattern matching:
def handle_event("add_language", %{"value" => "error"}, socket) do
  {:reply, %{error: "This value is not allowed"}, socket}
end

# Accept (optionally modify value/label):
def handle_event("add_language", %{"value" => value}, socket) do
  {:reply, %{value: value, label: value}, socket}
end

Real world example

Real world example

Full Name
Select your area of expertise

Do you accept terms and conditions?