defmodule LiveSelect do alias LiveSelect.ChangeMsg import Phoenix.Component # for backward compatibility with LiveView 0.17 # generates compile warning if run with LiveView 0.18 import Phoenix.LiveView.Helpers @moduledoc ~S""" The `LiveSelect` field is rendered by calling the `live_select/3` function and passing it a form and the name of the field. LiveSelect creates a text input field in which the user can type text, and hidden input field(s) that will contain the value of the selected option(s). As the input text changes, LiveSelect will render a dropdown below the text input containing the matching options, which the user can then select. Selection can happen either using the keyboard, by navigating the options with the arrow keys and then pressing enter, or by clicking an option with the mouse. Whenever an option is selected, `LiveSelect` will trigger a standard `phx-change` event in the form. See the "Examples" section below for details on how to handle the event. After an option has been selected, the selection can be undone by clicking on the text field. In tags mode, single tags can be removed by clicking on them. ### Single mode demo ### Tags mode demo ## Reacting to user's input Whenever the user types something in the text input, LiveSelect sends a `t:LiveSelect.ChangeMsg.t/0` message to your LiveView. The message has a `text` property containing the current text entered by the user, and a `field` property with the name of the LiveSelect field. The LiveView's job is to [`handle_info/2`](`c:Phoenix.LiveView.handle_info/2`) the message and then call `update_options/2` to update the dropdown's content with the new set of selectable options. See the "Examples" section below for details. ## Multiple selection with tags mode When `:tags` mode is enabled `LiveSelect` allows the user to select multiple entries. The entries will be visible above the text input field as removable tags. The selected entries will be passed to your live view's `change` and `submit` events as a list of entries, just like an [HTML