Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(autocomplete): deselect the other options when the user select an option #3690

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
*/
private _setValueAndClose(event: MdOptionSelectionChange | null): void {
if (event) {
this.autocomplete.options.forEach((option) => {
if (option != event.source) {
option.deselect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling deselect() here will emit a selection change event for every option on the list. That's fine, but it will change the behavior of subscriptions to optionSelections. Instead of getting 1 event on selection, people will get 1 event per option (so, 50 events for a 50 option list). So I'd also add a filter to optionSelections to ensure we're only catching events from options that have selected set to true.

Also can you move this out into its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but instead of setting a filter on optionSelections, I've change to only call the deselect function on the option that was previously selected.

Please let me know if this PR needs any other changes

}
});

this._setTriggerValue(event.source.value);
this._onChange(event.source.value);
}
Expand Down