Product Search Forms #
Description:
An accessible product search form enables users to efficiently find products or information without encountering barriers, especially for those using assistive technologies. Accessible search forms enhance the user experience by providing clear labels, meaningful instructions, keyboard navigability, and user-friendly feedback.
Key Accessibility Practices for Product Search Forms #
- Clear Labels and Descriptions:
- Use a visible
<label>for the search input field, such as “Search Products.” Labels help users understand the field’s purpose, especially for screen reader users. - Include a
placeholderif additional guidance is needed (e.g., “Search by product name or SKU”) but ensure it does not replace the<label>element.
- Use a visible
- Accessible Search Button:
- Provide a clear button labeled “Search” next to the input field instead of relying on users pressing “Enter.” Screen reader users and those with cognitive disabilities benefit from a clear, actionable button.
- Use descriptive button text or an
aria-labelif the button only contains an icon, such as a magnifying glass.
- Autocomplete and Suggestions:
- If autocomplete is available, make sure it is accessible by using
aria-live="polite"to announce suggestions as they appear. - Consider adding
aria-autocomplete="list"androle="listbox"for the suggestion box to ensure screen reader compatibility.
- If autocomplete is available, make sure it is accessible by using
- Keyboard Navigation:
- Ensure the form is keyboard-accessible, allowing users to navigate between the input field, search button, and suggestions using the “Tab” key.
- Ensure that selecting a suggestion with the arrow keys or “Enter” key updates the search input field without triggering the search prematurely.
- Error and Status Notifications:
- Use polite live regions to notify users when no results are found or if the search was successful. This feedback helps screen reader users know the outcome without an interruptive announcement.
Here’s an example of an accessible product search form that incorporates the practices outlined above.
Explanation #
- Labels and Placeholder Text:
- The search input has a visible
<label>that clearly describes the purpose of the field, and aplaceholderprovides additional guidance without replacing the label. This makes the field easy to understand for all users, including screen reader users.
- The search input has a visible
- Accessible Search Button:
- The “Search” button is labeled and positioned next to the input field, providing a clear action for users. This benefits screen reader users and anyone who may not be familiar with pressing “Enter” to initiate a search.
- Autocomplete Suggestions:
- When users begin typing, the
displaySuggestions()function generates a list of suggestions that appear below the search field. The suggestion box usesrole="listbox", and each suggestion hasrole="option"to improve compatibility with screen readers. - Each suggestion is also keyboard-navigable (
tabindex="0"), and users can select an option by clicking or pressing “Enter,” which fills the search field without immediately triggering the search.
- When users begin typing, the
- Error and Status Notifications:
- The
status-messagediv provides feedback, such as a reminder to enter a search term if the field is empty or a message confirming that results are displayed. - These notifications use
aria-live="polite"androle="status"to ensure screen readers announce updates without interrupting the user.
- The
- Keyboard Accessibility:
- The form is fully navigable by keyboard. Users can tab through the input field, suggestions, and search button in a logical order. The suggestions are focusable and have a visible style change on focus, helping keyboard-only users.
Key Takeaways #
- Use Clear Labels and Accessible Buttons: Each field should have a visible label, and the search button should be labeled clearly or include an
aria-labelif it’s an icon button. - Implement Accessible Autocomplete: For autocomplete suggestions, use
aria-live="polite"to announce options as they appear, andaria-autocomplete="list"withrole="listbox"for compatibility with screen readers. - Provide Keyboard Access to Suggestions: Make suggestions keyboard-accessible, allowing users to navigate with the “Tab” key and select options without prematurely triggering the search.
- Use Live Regions for Status Notifications: Employ polite live regions to announce outcomes like “No results found” or “Results displayed” for screen reader users.
- Error Feedback: When an input is required, provide feedback if it’s left empty and prevent form submission until the required information is entered.
By following these practices, you’ll create an accessible product search form