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

fix(selection-list): disabling list doesn't disable ripples of options #11955

Merged

Conversation

devversion
Copy link
Member

  • Fixes that dynamically changing the [disabled] binding does not update the state of the list options (e.g. ripple disabled state; checkbox disabled styling)

Fixes #9952

@devversion devversion added the target: patch This PR is targeted for the next patch release label Jun 27, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 27, 2018
@jelbourn
Copy link
Member

@devversion
Copy link
Member Author

devversion commented Jun 27, 2018

If the [disabled] binding is being updated on the MatSelectionList the change will be recognized and the changes will be reflected.

Apparently this does not mean that the child components itself will be updated because they also are set to OnPush. The child components (<mat-list-option>) will only check for changes if a binding has been updated (which is not the case).

So in that case we need to manually mark the options for check. e.g. through _stateChanges as it's been done for sort as well (see here)


So in short: The getter will surely return the right value. But the value is not being used anywhere because the template of the <mat-list-option> isn't asking for a new value at all (no changes detected)

@@ -140,6 +142,9 @@ export class MatListOption extends _MatListOptionMixinBase
/** @docs-private */
@Inject(forwardRef(() => MatSelectionList)) public selectionList: MatSelectionList) {
super();

this._parentStateSubscription = this.selectionList._stateChanges
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment that explains what this is for?

Also, instead of keeping track of the subscription, we've been moving towards a pattern of having a _destroyed subject and using takeUntil

@@ -335,6 +345,10 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu
});
}

ngOnChanges() {
this._stateChanges.next();
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to only do this for now in the disabled setter, or is there other state shared between the two components?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently there is no other "state" that needs to be shared between child and parent.

Since we use the mixinDisabled, we can't customize the setter and notify the state change. As an alternative, we can just remove the mixin and implement the disabled property our self.

That way, we could even get rid of the stateChanges subject and just manually run something like options.forEach(option => option._markForCheck(). But maybe we will have things to share at some point. What do you prefer? (removing mixin seems to be the cleaner way for now)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I would go with removing the mixin for now.

Copy link
Member

Choose a reason for hiding this comment

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

You can declare the changes: SimpleChanges parameter on the ngOnChanges method which will tell you whether disabled changed.

it('should update state of options if list state has changed', () => {
// To verify that the template of the list options has been re-rendered after the disabled
// property of the selection list has been updated, the ripple directive can be used.
// Inspecting the host classes of the options doesn't work because those update as part
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I get this part. Both the disabled class/aria-disabled and the ripple depend on the same property, which means that they should update at the same time, if they don't it could indicate that the test is catching another issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

The difference is: The host bindings of the <mat-list-option> seem to be updated as part of the parent template (<mat-selection-list>), while the actual template of the <mat-list-option> is only being updated if the change detection runs on MatListOption (which is obviously not the case)

Maybe I miss something crucial, but from my findings it looks like this is the case.

* Fixes that dynamically changing the `[disabled]` binding does not update the state of the list options (e.g. ripple disabled state; checkbox disabled styling)

Fixes angular#9952
@devversion devversion force-pushed the fix/list-state-change-options branch from b3977d0 to 6fbd3e8 Compare June 28, 2018 15:05
@devversion
Copy link
Member Author

@jelbourn Done. Made the requested changes.

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

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.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jun 28, 2018
@josephperrott josephperrott merged commit d3212a6 into angular:master Jun 29, 2018
@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 9, 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.

MatSelectionList disabled input is only checked at creation time
5 participants