Skip to content

Lookup

A Lookup is a predictive text input that presents a dropdown menu with suggestions based on the current input value.

Guidelines

When to use lookups

Use the Lookup component to let users search through a dataset to choose a predefined value for a form field. This can be useful when there are many options the user can choose from, so they need to filter the items via a text query.

Avoid using Lookup to enable users to search for and navigate to content. Instead, use SearchInput or TypeaheadSearch.

Specifications

Specification of Lookup.

Lookup includes the following elements:

  1. Input
    A TextInput where the user types to look for the suggested results. This can optionally include a start icon, clear button, and placeholder text.
  2. Dropdown menu
    Suggested results are displayed via the Menu component.

Component limitations

Since the Lookup component uses a TextInput, its base min-width is set to size-1600 token (equivalent to 256px in the default Codex theme), but it can be customized to a smaller width if needed. There is no maximum width set. If the text entered in the input exceeds the available space, it will overflow horizontally.

Refer to the Lookup component in Codex Figma.

Types

An input field featuring an optional placeholder will enable users to initiate their search for suggested results. These suggestions will be displayed within a dropdown menu, and if the menu cannot fully accommodate the results, a scrollbar with the choice of infinite scroll can be included.

Lookup with a custom placeholder.

Clearable, with start icon

An optional start icon and clear button could appear within the input field.

A clearable Lookup component with a custom start icon.

With custom menu item display

Custom content and formats can be applied to change the appearance of menu items according to your needs.

Lookup with custom menu items displayed.

With initial suggestions

When the input field is focused, an initial list of suggestions may appear within the menu. When typing within the input field, these suggestions disappear, and the menu showcases a list of items matching the typed value. It is advisable to include a minimum of 2 suggested items and ideally limit the maximum to 4 or 5 items.

Lookup displaying a list of suggested results in the first image and a list of matched results in the second.

No results

If there are no results for the text typed by the user, a non-interactive "no results" message will be displayed within the menu.

Lookup with no results found.

Lookup within a form field

A Lookup can be wrapped within a Field to include features like label, description, help text, or validation messages.

Lookup within a Field.

Interaction states

Interaction can take place within both the input and the displayed menu:

Interaction states of Lookup: default, hover, focus, active, filled, and filled active where a menu item selected is displayed.

  1. Default
  2. Hover
  3. Focus
  4. Active
  5. Filled
  6. Filled active (with a menu item selected)
  7. Error
  8. Error hover
  9. Disabled

Best practices

Consider the following recommendations when using Lookups.

Lookup wrapped within a Field.

Do:
  • Wrap the Lookup within the Field component to incorporate features such as labels, descriptions, help text, or validation messages.

A standalone Lookup.

Don't:
  • Use a standalone Lookup on a page.

Keyboard navigation

KeyFunction
Down arrowWhen the focus is placed on the Lookup, it opens the menu. When the menu is open, pressing it navigates through menu options. If pressed at the last visible option, it scrolls to the next "hidden" menu item.
Up arrowWhen the focus is placed on the Lookup, it opens the menu. When the menu is open, it navigates through menu options.
EscWhen the menu is open, it closes the menu.
EnterIt opens the menu when the focus is placed on the Lookup. If the menu is open, it closes the menu. If the focus is placed in any of the options within the menu, the focused option is selected.

Demos

Configurable

NameValue
Props
status
disabled
View
Reading direction

Default

The Lookup component will emit input events on input, which the parent component should react to by computing or fetching menu items, then providing those items to the Lookup component for display by updating the menu-items prop.

Items are displayed via the MenuItem component—see the MenuItem docs for more options. In this example, a menuConfig object is passed to the Lookup to bold the label text.

Note that in this example, menu items are Wikidata items with a human-readable label and a Wikidata entity ID value.

WARNING

The parent component must update the menu-items prop after each input event, otherwise the Lookup component will stay in the pending state indefinitely. If there are no results for the given input, set the menu-items prop to an empty array ([]).

Selected value:

NameValue
View
Reading direction

With custom menu item display

The menu-item slot can be used to set up custom menu item content and formatting.

With "no results" content

A non-interactive "no results" message can be displayed via the no-results slot. If populated, this slot will automatically display when there are zero menu items.

With initial suggestions

You can show an initial list of options as "suggestions" by passing in an array of menu items initially. The parent component must handle resetting the menu items to this list of suggestions when the input is cleared.

Selected value:

NameValue
View
Reading direction

With initial selection and input

To set an initial selection, do the following:

  1. Set the selected prop to the value of the initially selected item.
  2. Use the optional v-model:input-value prop to set the input value to the label of the selected item (or the value, if there is no label).
  3. Optional: if you want the selected item to appear in the menu when it is opened, you must provide the selected item in the list of menuItems. Otherwise, you can initialize menuItems to an empty array or a list of initial suggestions.

You can also use v-model:input-value to set an initial input value without an initial selection.

Selected value: Q81

With fetched results and infinite scroll

Often, Lookup is used to fetch results from an API endpoint. Parent components should react to the input event emitted by Lookup to search for results, then pass back to the Lookup either an array of results to display as menu items or an empty array if there are no results. Between those two events, a pending state animation will display in the input.

Scrolling is enabled by setting the visibleItemLimit property of the menuConfig prop.

With scrolling enabled, when the user nears the end of the list of results, a load-more event is emitted. The parent component can react to this by fetching more results and appending them to the list of menu items provided to the Lookup. These new items will then be displayed within the menu.

Clearable, with start icon

Props of the TextInput component can be bound to Lookup and will be passed down to the TextInput component inside of it, so you can take advantage of features like the "clear" button and icons.

With placeholder

Attributes (except for class) will fall through to the input element, so you can set things like placeholder on the Lookup component and they'll be applied to the input.

Form field

A Lookup can be wrapped in the Field component to add features like a semantic label, description and help text, validation messages, and more. See the Field page for more information.

Search Wikidata items
Start typing the name of a Wikidata item to see suggestions

Vue usage

Typical use of this component will involve listening for input events, fetching or otherwise computing menu items, then passing those menu items back to the Lookup for display.

TextInput props apply

This component contains a TextInput component. You can bind TextInput props to this component and they will be passed to the TextInput within.

Attributes passed to input

This component will pass any HTML attributes applied to it, except for CSS class, to the <input> element within the component.

Props

Prop nameDescriptionTypeDefault
selected(required)Value of the current selection.

Must be bound with v-model:selected.

The property should be initialized to null rather than using a falsy value.
string|number|null
menuItems(required)Menu items.MenuItemData[]
inputValueCurrent value of the input. This prop is optional and should only be used if you need to keep track of the input value for some reason (e.g. to set an initial value).

Optionally provided by v-model:input-value binding in the parent component.
string|numbernull
initialInputValueInitial value of the text input. Non-reactive.
@deprecated Use inputValue instead.
string|number''
disabledWhether the entire component is disabled.booleanfalse
menuConfigConfiguration for various menu features. All properties default to false.

See the MenuConfig type.
MenuConfig{}
statusstatus property of the TextInput componentValidationStatusType'default'

Events

Event namePropertiesDescription
changeevent EventWhen an input value change is committed by the user (e.g. on blur)
load-moreWhen the user scrolls towards the bottom of the menu.

If it is possible to add or load more menu items, then now would be a good moment so that the user can experience infinite scrolling.
update:selectedselected string|number|null - The new selected valueWhen the selected value changes.
update:input-valueinputValue string|number - The new input valueWhen the input value changes. Only emitted if the inputValue prop is provided.
inputvalue string|number - The new valueWhen the text input value changes.
focusevent FocusEventWhen the input comes into focus
blurevent FocusEventWhen the input loses focus

Slots

NameDescriptionBindings
menu-itemDisplay of an individual item in the menumenu-item MenuItemData - The current menu item
no-resultsMessage to show if there are no results to display.

CSS-only version

Markup structure

There is no true CSS-only version of the Lookup component. However, a CSS-only TextInput component can be used instead, since it has visual parity with the Lookup component with its menu collapsed. For example, you could display a CSS-only TextInput on page load while a Vue app loads, then replace it with the Vue Lookup component once the Vue app has mounted.

The example below is a simple text input with a placeholder, but icons and different states are supported—see the TextInput docs for more information.