Typeahead

Complete typed user input with matching results from a larger data set.

UsageOverview

Typeahead allows the user to receive one or more suggested matches in a list based on any combination of letter numbers or symbols they input.

A good application of this component can help a user find what they are looking for quicker, or empower them to discover new results.

How to use
AnatomyElements


Variation rulesTypes

At its most basic level, typeahead is a function that matches what a person types, usually the beginning of a word, prefix, or ID with a word list.

Suggestions help users construct more useful searches than they might on their own by trying to predict their intentions. This type of typeahead can help users discover new content.

Rich information with complete search results narrow down the search to a specific result.


BehaviorTrigger & Dismissal

Focus on the input field is achieved through a mouse click or through the use of the TAB key in the keyboard. The input field changes to its active state.

Typing at least 3 characters on the input field triggers the typeahead. This is represented by a loading state and the list of results after it's retrieved.

Response times should never exceed more than 1000ms. Anything longer than that has a negative impact on usability.

Selecting an item from the list copies it to the input field which changes to a reset state. The cancel icon on the right clears the query from the input field.

Keyboard navigation
Key Action
Down arrow Moves focus to the next item on the results list
Up arrow Moves focus to the previous item on the results list
Enter Selects the active item in the list
Escape Dismisses the results list
Validation & Errors

If the query returns no results, a message should be displayed in the list.


Order & AlignmentHierarchy

An typeahead component used as a search function should have a prominent position above the data to be searched.

Grouping

Use the category divider item to separate supporting information from the suggested search terms. This makes the list easier to scan because the user can distinguish the information at a glance.


Overflow Rules

Scrolling

A concise typeahead list of no more than 10 items encourages better searching as it suggests the user to refine his/her search query. A long list of options can be overwhelming and it reduces the effectiveness of the typeahead function, while also increasing response times.

If you must use a scrollbar, keep the result list container's height as short as possible (no more than 10 items) and keep the scrollbar visible on the dropdown list.

In other cases, you may add a link to more results at the bottom of the list.


Best practicesAccessibility Responsiveness

In mobile screens, a concise typeahead list is best as in most cases, the space in the viewport is reduced by the keyboard. Keep mobile results to 4 - 6 results and ensure proper spacing between the options on the list.


Related components

// these need proper links later


Feedback

We would like to get your feedback. Tell us how you use this component in your projects and how we can improve it.

HTML/CSS v2
Behavior Specification
Feature: Autocomplete Scenario: Trigger When I type 2 or less characters into
      the search box Then I don't see a suggestion box Scenario: Trigger When I type 3
      or more characters into the search box Then I see the suggestion box And I start
      getting results Scenario: Empty results When I type 3 or more characters into
      the search box that yield no results Then I get feedback about no results being
      given Scenario: Loading Given that results take long to appear When I type 3 or
      more characters into the search box Then I see a loading icon Background: With
      suggestions Given there is a suggestion box with results Scenario: Clear input
      When I click on the action that clears the input field Then the icon disappears
      And I don't see the suggestion box Scenario: Navigate down When I type "↓" Then
      the next item is highlighted Scenario: Navigate up When I type "↑" Then the
      previous item is highlighted Scenario: More results Given there is a limit of
      results When there are more results than the limit Then I see a link to see more
      results