-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
This line works fine with mat-icon, but was causing errors in a unit test environment when matChipRemove was on a button element. Defer the tab index update to avoid the errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
// 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
components/src/material/chips/chip.ts
Line 401 in 52dddcc
constructor(protected _parentChip: MatChip) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, it's fine for now, then. Someday I want to audit the library's use of this pattern and see if we can use an alternative approach
This line works fine with mat-icon, but was causing errors in a unit test environment when matChipRemove was on a button element. Defer the tab index update to avoid the errors.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This line works fine with mat-icon, but was causing errors in a
unit test environment when matChipRemove was on a button element.
Defer the tab index update to avoid the errors.