Skip to content
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