Overview
The<mat-autocomplete> component provides a panel of suggested options that appears below a text input field. It enhances user experience by offering real-time suggestions based on user input.
Basic Usage
- Template-driven
- Reactive Forms
API Reference
MatAutocomplete
Selector:mat-autocomplete
Exported as: matAutocomplete
Inputs
Function that maps an option’s control value to its display value in the trigger.
Whether the first option should be highlighted when the autocomplete panel is opened.
Whether the active option should be selected as the user is navigating.
Whether the user is required to make a selection when interacting with the autocomplete. If enabled, the value will be reset if the user moves away without selecting.
Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will match the width of its host.
Whether ripples are disabled within the autocomplete panel.
CSS classes to apply to the autocomplete panel inside the overlay container.
Whether checkmark indicator for single-selection options is hidden.
Aria label of the autocomplete.
Input that can be used to specify the
aria-labelledby attribute.Outputs
Event that is emitted whenever an option from the list is selected.
Event that is emitted when the autocomplete panel is opened.
Event that is emitted when the autocomplete panel is closed.
Emits whenever an option is activated using keyboard navigation.
Properties
Unique ID to be used by autocomplete trigger’s “aria-owns” property. Auto-generated with prefix
mat-autocomplete-.Whether the autocomplete panel is open.
Whether the autocomplete panel should be visible, depending on option length.
Events
MatAutocompleteSelectedEvent
Reference to the autocomplete panel that emitted the event.
Option that was selected.
Accessibility
- The autocomplete trigger uses
role="combobox"and managesaria-expanded,aria-owns, andaria-activedescendantattributes - Use
aria-labeloraria-labelledbyto provide an accessible label for the autocomplete - The autocomplete panel uses
role="listbox"and each option hasrole="option" - Keyboard navigation is fully supported (Arrow keys, Enter, Escape)
- Screen readers announce the active option and selection changes
Advanced Usage
Display Value Formatting
Auto-selection
UseautoActiveFirstOption to automatically highlight the first option when the panel opens: