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

MatSelectionList should update option selection state when list of options changes #16062

Closed
benelliott opened this issue May 20, 2019 · 2 comments · Fixed by #16080
Closed
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@benelliott
Copy link
Contributor

What is the expected behavior?

MatSelectionList should update option selection state when list of options changes

What is the current behavior?

If you change the list of options after the view has been initialised, MatSelectionList does not update the model of the new options to reflect that they are selected in the model.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-ptk4tc?file=app/app.component.ts

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

Latest StackBlitz template

Is there anything else we should know?

MatSelectionList should listen to options.changes on the options QueryList:

@ContentChildren(MatListOption, {descendants: true}) options: QueryList<MatListOption>;

This is how MatSelect works:

this.options.changes.pipe(startWith(null), takeUntil(this._destroy)).subscribe(() => {

@benelliott
Copy link
Contributor Author

One problem is that MatSelectionList does not internally keep track of its selection state - instead it delegates this to each corresponding option item (except for _tempValues which is only used for initialisation). I think that to fix this bug we would need to introduce a longer-lived version of _tempValues that can be consulted whenever an option item is added.

@crisbeto crisbeto self-assigned this May 21, 2019
@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels May 21, 2019
crisbeto added a commit to crisbeto/material2 that referenced this issue May 21, 2019
Fixes a `mat-list-option` that is added after initialization not being selected, even if it matches the control value.

Fixes angular#16062.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 27, 2019
Fixes a `mat-list-option` that is added after initialization not being selected, even if it matches the control value.

Fixes angular#16062.
jelbourn pushed a commit that referenced this issue Jun 19, 2019
Fixes a `mat-list-option` that is added after initialization not being selected, even if it matches the control value.

Fixes #16062.
RudolfFrederiksen pushed a commit to RudolfFrederiksen/material2 that referenced this issue Jun 21, 2019
…#16080)

Fixes a `mat-list-option` that is added after initialization not being selected, even if it matches the control value.

Fixes angular#16062.
andrewseguin pushed a commit that referenced this issue Jul 2, 2019
Fixes a `mat-list-option` that is added after initialization not being selected, even if it matches the control value.

Fixes #16062.
@angular-automatic-lock-bot
Copy link

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-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants