Skip to content

Setting mat-list-option selected attribute programatically triggers selectionChange event #8550

@eTallang

Description

@eTallang

Bug, feature request, or proposal:

Bug

What is the expected behavior?

As with mat-select, setting the selected-attribute on a mat-list-option should not trigger the selectionChange event, as this in many cases causes unintentional behavior (e.g. when setting initial state on component initialization).

What is the current behavior?

Setting the selected-attribute on a mat-list-option triggers the selectionChange event, as if the element was selected by the user.

What are the steps to reproduce?

http://plnkr.co/edit/SBTQUM2Pl2TcNhSQaDW0?p=preview
In the plunkr above, each selectionChange event from the element in the selection list pushes a new element to the log array. The button that programatically sets the selected state should not trigger a selectionChange.

What is the use-case or motivation for changing an existing behavior?

I wish to set the intitial state of my selection-list based on a query parameter in the url. This causes unintentional behavior, since setting the selected-attribute triggers a selectionChange event, which in my case triggers a HTTP-request. My current workaround is using a mat-select, which does not trigger a change-event upon setting the checked-attribute programatically.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular 5.0.0
Angular Material 5.0.0-rc0

Is there anything else we should know?

Metadata

Metadata

Assignees

Labels

blockedThis issue is blocked by some external factor, such as a prerequisite PR

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions