Autocomplete

Autocomplete allows users to quickly filter through a list of options and pick one or more values for a field.

v0.36.4BetaNot reviewed for accessibility

Description

Use AutoComplete to provide a user with a list of selectable suggestions that appear when they type into the input field. This list is populated by server search results.

Accessibility

Always set an accessible label to help the user interact with the component.

  • label_text is required and visible by default.
  • If you must hide the label, set visually_hide_label to true. However, please note that a visible label should almost always be used unless there is compelling reason not to. A placeholder is not a label.

Arguments

NameTypeDefaultDescription
label_text
String

N/A

The label of the input.

src
String

N/A

The route to query.

input_id
String

N/A

Id of the input element.

input_name
String

nil

Optional name of the input element, defaults to input_id when not set.

list_id
String

N/A

Id of the list element.

visually_hide_label
Boolean

false

Controls if the label is visible. If true, screen reader only text will be added.

show_clear_button
Boolean

false

Adds optional clear button.

system_arguments
Hash

N/A

size
Hash

:medium

Input size can be small, medium (default), or large

full_width
Boolean

false

Input can be full-width or fit to content

width
String

:auto

Optional parameter to set max width of results list. One of :auto, :large, :medium, :small, :xlarge, or :xxlarge.

disabled
Boolean

false

Disabled input

invalid
Boolean

false

Invalid input

placeholder
String

nil

The placeholder text displayed within the input

inset
Boolean

false

subtle input background color

monospace
Boolean

false

monospace input font family

Examples

Slots

results

Customizable results list.

NameTypeDefaultDescription
system_arguments
Hash

N/A

leading_visual

Leading visual.

  • leading_visual_icon for a Octicon.
NameTypeDefaultDescription
system_arguments
Hash

N/A

Same arguments as Octicon.

input

Customizable input used to search for results. It is preferred to use this slot sparingly - it will be created by default if not explicity added.

NameTypeDefaultDescription
system_arguments
Hash

N/A

AutoComplete::Item

Use AutoCompleteItem to list results of an auto-completed search.

Arguments

NameTypeDefaultDescription
value
String

N/A

Value of the item.

selected
Boolean

false

Whether the item is selected.

disabled
Boolean

false

Whether the item is disabled.

description_variant
Hash

:block

Changes the description style. Allowed values are :inline, :block

description
String

N/A

Display description text below label

system_arguments
Hash

N/A

Slots

leading_visual

The leading visual rendered before the link.

NameTypeDefaultDescription
kwargs
Hash

N/A

The arguments accepted by Avatar or Octicon

trailing_visual

The trailing visual rendered after the link.

NameTypeDefaultDescription
kwargs
Hash

N/A

The arguments accepted by Octicon, Label, or Counter

description

Optional description

NameTypeDefaultDescription
system_arguments
Hash

N/A