Skip to content

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

Closed

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?

Activity

  1. self-assigned this
    on Nov 20, 2017
  2. devversion commented on Nov 20, 2017

    @devversion
    Member

    Should be revisited after #7456

  3. devversion commented on Dec 6, 2017

    @devversion
    Member

    Fixed with #7456

  4. angular-automatic-lock-bot commented on Sep 7, 2019

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Sep 7, 2019
  6. added
    blocked
    on Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

blocked

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions