Accessible autocomplete (Type ahead) #225
Replies: 2 comments
-
Apply typeahead componentIn Apply we have our own custom search/typeahead component on the proceedings search page BehaviourThe user types a search term, and the results are returned with the search term(s) highlighted. Hovering over an item highlights the row. The user can then select a proceeding type using the radio buttons, and click the 'Save and continue' button. This component is used in conjunction with the add another pattern. The user is taken to the next page which asks them if they would like to add another proceeding. If they select 'Yes' they are taken back to the search page to add a further proceeding type. Search results return once a user has entered more than 2 characters, and update automatically following further typing or removal of characters. AccessibilityThere is a visually hidden element which informs users that results will return automatically. There is also an aria-live region which is updated when the search results are returned with a message notifying the user that results have returned, along with the number of results. The results section behaves the same as a normal radio button group. Tabbing takes you into the group, and the up/down arrows are used to navigate between results and select an item. Tabbing again then takes you out of the group and moves focus to the 'Save and continue' button. User researchWe have found in user research that users often expect that they can select multiple proceedings at once from the search results, and try to do this. However users have also commented that they like that you can see a list of the proceedings you have selected on the next page, and that you are asked if you would like to select another one. ImplementationThe search behaviour is implemented using JavaScript. The JS can be found here and the CSS is here. At the moment, we are retrieving the list of proceeding types from an internal endpoint using an AJAX call. On page load, we then create a list of hidden proceeding items. The search functionality is implemented using a backend service (code here) also called using AJAX. When search results are returned, we iterate through the results and display the corresponding HTML element for each result, and add the highlighting. Note: We are considering constructing the HTML elements on the fly as results are returned and iterated through, rather than having everything already on the page but hidden. At the moment in our service we have a limited number of items to search through, but in the future we expect this list to expand quite significantly. Example HTML code below, with two available items to search. The first item is visible with search term highlighted, the second item is hidden:
|
Beta Was this translation helpful? Give feedback.
-
Autocomplete for 'Refer and monitor an intervention' serviceOn the 'Refer and Monitor an Intervention' service, we’ve been exploring the use of an autocomplete field for selecting a Probation Delivery Unit (PDU) in the 'Find' journey (currently in the browse sub-stage). Key Details:
Next Steps:
Printscreens: |
Beta Was this translation helpful? Give feedback.
-
Existing
Published components and patterns
GitHub discussions and blog posts
We're building an autocomplete - on Design in government blog
Building an accessible autocomplete - on Adam Silver's blog
Variation
Product name - HMPPS > Prisons > Moving a prisoner to hospital
What the product does - Helps providers/applicants apply for legal aid
Who the users are - Who the users are: Providers/Applicants
What the user need is for this variation
There is a need for users to be able to choose from a list of over 100 items.
Publishing this component is needed as a published version does not yet exist in the GOV.UK Design System
Using the existing component
The existing accessible autocomplete component on GOV.UK's GitHub repo has been used in several live services.
Research showed:
Designing a variation
The team used their research to design a variation of the component that would meet the user need.
This variation:
Research on this variation
This variation:
Guidance
When to use
When not to use
How to use
Contribute
Things we don't know enough about
Beta Was this translation helpful? Give feedback.
All reactions