Skip to content

fix(material/autocomplete): don't assign to model value while typing when requireSelection is enabled - #27572

Merged
crisbeto merged 1 commit into
angular:mainfrom
crisbeto:27423/require-selection-model-typing
Aug 3, 2023
Merged

fix(material/autocomplete): don't assign to model value while typing when requireSelection is enabled#27572
crisbeto merged 1 commit into
angular:mainfrom
crisbeto:27423/require-selection-model-typing

Conversation

@crisbeto

Copy link
Copy Markdown
Member

Follow-up to #27423 based on the feedback. Usually mat-autocomplete assigns to the model as the user is typing which may not be desired when requireSelection is enabled, because at the end of the selection either an option value will set or it'll be reset.

These changes add a condition so that the value isn't assigned while typing and requireSelection is enabled.

@crisbetocrisbeto added P2 The issue is important to a large percentage of users, with a workaround target: rc This PR is targeted for the next release-candidate labels Aug 3, 2023
@crisbetocrisbeto added action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Aug 3, 2023
@crisbeto

Copy link
Copy Markdown
MemberAuthor

I had to add and remove the merge label to verify that the change will be merged in the right branch.

…when requireSelection is enabled
Follow-up to angular#27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset.
These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled.
@crisbeto
crisbetoforce-pushed the 27423/require-selection-model-typing branch from 2a775d8 to e342192CompareAugust 3, 2023 07:25
@crisbetocrisbeto added the action: merge The PR is ready for merge by the caretaker label Aug 3, 2023
@crisbeto
crisbeto merged commit 77ffdf9 into angular:mainAug 3, 2023
crisbeto added a commit that referenced this pull request Aug 3, 2023
…when requireSelection is enabled (#27572)
Follow-up to #27423 based on the feedback. Usually `mat-autocomplete` assigns to the model as the user is typing which may not be desired when `requireSelection` is enabled, because at the end of the selection either an option value will set or it'll be reset.
These changes add a condition so that the value isn't assigned while typing and `requireSelection` is enabled.
(cherry picked from commit 77ffdf9)
@mozgor

mozgor commented Aug 10, 2023

Copy link
Copy Markdown

Regarding your early comments in previous thread and especially this one, this fix means that despite being against the generic expectations of not interacting directly with the DOM while dealing with reactive forms (quoting you) this is the actual way of filtering autocomplete options ? I understand the reasoning behind this fix, but I'd double check before propagating updated guidelines inside our project.

@crisbeto

Copy link
Copy Markdown
MemberAuthor

Yes, I had to make the tradeoff because it would've been a weird experience if the form control was emitting events with the string value while the user is typing and then a null event at the end if they don't select something since there's no way to distinguish where the value is coming from.

@mozgor

Copy link
Copy Markdown

Make sense, even if it would have been easier for my use case to filter out null value rather than switching source. Controls "valuesChanges" stream was very convenient especially to chain filter / debounce operators.

I'll figure that out, thanks for the confirmation.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-botangular-automatic-lock-botBot locked and limited conversation to collaborators Sep 10, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: mergeThe PR is ready for merge by the caretakerP2The issue is important to a large percentage of users, with a workaroundtarget: rcThis PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@crisbeto@mozgor@andrewseguin