components icon indicating copy to clipboard operation
components copied to clipboard

feat(autocomplete): allow configuring requireSelection blur behavior without resetting value to null

Open liesahead opened this issue 8 months ago • 2 comments

Feature Description

Please add a configurable option such as preserving the previous selection on blur, so that requireSelection does not have to emit null unless the application explicitly wants that behavior.

Related issues:

  • #27767: requireSelection clears input on blur
  • #28590: [requireSelection]="true" breaks valueChanges

Use Case

In our case, we manually restore the previous selected value when Angular resets the control to null.

That workaround causes multiple valueChanges emissions for a single user interaction: first null, then the previously selected value after we restore it. This is noisy, annoying to handle, and not reliably distinguishable from a real clear action triggered by the user.

We want to detect an actual clear action separately from the case where the user only focuses the input, opens the autocomplete panel, and then blurs without selecting a new option. A configurable behavior here would prevent unnecessary state changes and extra reactive form events.

liesahead avatar Mar 19 '26 12:03 liesahead

For example, in react Material UI library it works exactly like we expected it would work in angular and it seems in angular you cannot even achieve that behavior unless implementing autocomplete component ourselves.

Example how it's expected to work: https://mui.com/material-ui/react-autocomplete/#country-select

Here are possible options that seem to be very convenient:

  • freeSolo so the textbox can contain any arbitrary value.
  • selectOnFocus to help the user clear the selected value.
  • clearOnBlur to help the user enter a new value.

liesahead avatar Mar 19 '26 14:03 liesahead

Hi, mind if I take this one? Was thinking a new preserveSelectionOnBlur input on MatAutocomplete that skips the null reset when requireSelection is on. Happy to adjust if you'd rather see it shaped differently.

pradhankukiran avatar May 21 '26 15:05 pradhankukiran