AutoComplete

Best Practice · Last modified July 15, 2009

Providing an auto-complete feature for a standard text box field enables the user to be faster and more accurate in presence of ambiguous or hard to remember information from large datasets when the total number of items would exceed the usable length of a drop down box. Auto-complete allows faster user input by removing ambiguity about expected input data, avoiding potential mis-typed information as well as narrowing down the correct choices.


Delicious Bookmark this on Delicious

What Problem Does This Solve?

The user needs to enter an item into a text box which could ambiguous or hard to remember and therefore has the potential to be mis-typed.

When to Use This Pattern

  • The suggestions can be pulled from a manageable set of data.
  • The input item can be entered in multiple ways.
  • The input item can be matched with a specific data item in the system.
  • Speed and accuracy of entry is an important goal.
  • The total number of items would be too large or inconvenient for displaying in a standard drop down box.

What's the Solution?

Layout

  • Use a standard text box for input.
  • Label the text box to match the user's expection of what field will be searched against.

Interaction

  • As the user types, display a list of suggested items that most closely match what the user has typed. Continue to narrow or broaden the list of suggested items based on the user's input.
  • Display the suggested items list in a drop down box directly underneath the text box. The suggested items list may be based on the complete set of data or more narrowly based on other criteria such as each item's frequency of use.
  • When available, show multiple fields of information for each suggested item. In the Yahoo Mail example above, two fields are presented: the contact's full name and the contact's email address.
  • Highlight the closest matching item within the suggested items list.
    • Show the matched item as first in the list.
    • Highlight the background of the matched item.
    • When multiple fields are shown for each suggested item the match may occur with the initial characters of any of the fields presented.
  • For each suggested item in the suggest items list show the characters that exactly match the user's input. When multiple fields are shown in a suggested item the matching characters may appear in any of the fields presented. In the example below, the characters 'Yu' have been typed by the user. The match is on three items. Notice that the first item matched on the contact's email address '<yuiblogger.com>' whereas the second and third items are matched on the contact's name (e.g., 'Yusef Jones'.)



  • Allow the user to delete a character of input and display the previous suggested items list.
  • Allow the user to complete the input field by pressing the Tab key or Enter; key. The current matched item in the suggested items list will be accepted as the value for the input field.
  • Allow the user to optionally highlight an item of their choice from the suggested item list with the mouse or with the up and down arrow keys.
  • Allow the user to cancel the suggested items list by pressing the Esc key. The drop down list will close. Subsequently pressing the Tab key or Enter key will accept the value from the input field. However, typing more characters after hitting the Esc key will restart the auto completion behavior displaying the suggested items list.
  • If multiple input items are allowed in a single input field, allow the user to use the Comma key to separate each input item.
    • Pressing the comma key will complete an individual item match.
    • The auto complete behavior restarts when the user begins typing characters for the next input item.

Why Use This Pattern?

  • Reducing the number of keystrokes allows for faster user input.
  • Showing additional formatting information in the suggested items list (like the email address in the example above) removes ambiguity.
  • Continual feedback helps the user narrow in on the correct choice.

Accessibility

  • Label the text box to match the user's expection of what field will be searched against.
  • Allow the user to highlight a desired match either using a mouse or navigating to it with the up or down arrow keys.
  • Allow the user to complete the form by pressing the Tab or Enter keys.
  • Allow the user to cancel suggestions by pressing the Esc key.
  • Allow the input field to receive keyboard focus by pressing the Tab key.
  • Once the edit field is in focus make sure that the focus stays in the edit field during autocomplete.
  • Do not send any page refreshes when updating the field (page refreshes will signal assistive technology to start reading the page again.)
  • The insertion cursor should move as the left/right arrow keys are pressed in the text field.