Skip to content

fix(mdc chips) Fix matChipRemove Expression has changed error #16574

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

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Changes from all commits
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
10 changes: 7 additions & 3 deletions src/material-experimental/mdc-chips/chip-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ export class MatChipRow extends MatChip implements AfterContentInit, AfterViewIn
super.ngAfterContentInit();

if (this.removeIcon) {
// removeIcon has tabIndex 0 for regular chips, but should only be focusable by
// the GridFocusKeyManager for row chips.
this.removeIcon.tabIndex = -1;
// Defer setting the value in order to avoid the "Expression
// has changed after it was checked" errors from Angular.
Copy link
Member

Choose a reason for hiding this comment

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

Could this be done earlier in the component lifecycle to avoid the extra round of change detection?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the earliest it can be done is in ngAfterContentInit, because the removeIcon is a ContentChild.

@ContentChild(MatChipRemove, {static: false}) removeIcon: MatChipRemove;

Another possible fix would be injecting the parent chip into the remove icon and setting the tabIndex property in the remove icon's constructor. We'd have to make an injection token, or put the icons back in the chip file, like how they are in the non-mdc chips:

constructor(protected _parentChip: MatChip) {}

setTimeout(() => {
// removeIcon has tabIndex 0 for regular chips, but should only be focusable by
// the GridFocusKeyManager for row chips.
this.removeIcon.tabIndex = -1;
});
}
}

Expand Down