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

Conversation

vanessanschmitt
Copy link
Collaborator

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 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.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 19, 2019
@vanessanschmitt
Copy link
Collaborator Author

vanessanschmitt commented Jul 22, 2019

@jelbourn or @crisbeto, would one of you mind taking a look?

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jul 22, 2019
// 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) {}

Copy link
Member

@jelbourn jelbourn left a 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

@jelbourn jelbourn merged commit 67532db into angular:master Jul 25, 2019
andrewseguin pushed a commit that referenced this pull request Jul 29, 2019
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.
@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
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants