Skip to content

fix(mat-selection-list): do not allow ctrl + a when mat-selection-list is disabled #12543

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

Closed

Conversation

steve-todorov
Copy link

Fixes #12542

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label Aug 6, 2018
@steve-todorov
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Aug 6, 2018
@@ -374,12 +374,16 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu

/** Selects all of the options. */
selectAll() {
this._setAllOptionsSelected(true);
if (!this._disabled) {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than checking whether the list is disabled, these should loop through the options and check whether each individual one is disabled. That would catch both the case where individual ones are disabled and the entire list is disabled.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that indeed sounds like a better solution.

const event = createKeyboardEvent('keydown', A, selectionList.nativeElement);
Object.defineProperty(event, 'ctrlKey', {get: () => true});

let selectList =
Copy link
Member

Choose a reason for hiding this comment

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

This should be a const since it isn't being re-assigned.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed, thanks! :)

@steve-todorov steve-todorov force-pushed the mat-selection-list-fix branch 2 times, most recently from c1f9b05 to adb9271 Compare August 6, 2018 10:54
}
});
// Don't change selected state if MatSelectionList is disabled
if (!this.disabled) {
Copy link
Member

@devversion devversion Aug 6, 2018

Choose a reason for hiding this comment

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

This check should be removed now. Since we now check each individual option, this check just makes the !option.disabled condition a noop.

I'd format it like this:

this.options.forEach(option => {
  if (!option.disabled && option._setSelected(isSelected)) {
    hasChanged = true;
  }
});

Thanks for your work on this! Good catch.

Copy link
Member

Choose a reason for hiding this comment

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

Also this shouldn't be done in this method, but rather inline inside the keydown handler. This won't allow for all options to be selected/deselected programmatically.

@steve-todorov
Copy link
Author

steve-todorov commented Aug 6, 2018

@crisbeto could you please have a look again when you have some time? I was thinking to add a disabled check in the MatListOption#toggle() method, but decided this is enough because you might want to manually toggle it programmatically for some unknown reason. Let me know your thoughts.

@steve-todorov steve-todorov force-pushed the mat-selection-list-fix branch from adb9271 to 5f74374 Compare August 6, 2018 11:31
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 6, 2018
Along the same lines as angular#12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
crisbeto added a commit to crisbeto/material2 that referenced this pull request Aug 6, 2018
Along the same lines as angular#12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
@josephperrott josephperrott added the target: patch This PR is targeted for the next patch release label Aug 7, 2018
mmalerba pushed a commit that referenced this pull request Aug 14, 2018
Along the same lines as #12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
jelbourn pushed a commit that referenced this pull request Aug 23, 2018
Along the same lines as #12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
jelbourn pushed a commit that referenced this pull request Aug 23, 2018
Along the same lines as #12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
jelbourn pushed a commit that referenced this pull request Aug 29, 2018
Along the same lines as #12543. Currently `mat-select` will select all options when pressing ctrl + a, no matter whether they're disabled. These changes add an extra check to ensure that the disabled ones are skipped.
@ngbot
Copy link

ngbot bot commented Nov 29, 2018

Hi @steve-todorov! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@mmalerba mmalerba added aaa and removed aaa labels Apr 25, 2019
@andrewseguin andrewseguin added the P4 A relatively minor issue that is not relevant to core functions label May 30, 2019
@annieyw
Copy link
Contributor

annieyw commented Mar 15, 2021

@crisbeto do we still want to proceed with this change?

@crisbeto
Copy link
Member

This was resolved in #18885. Closing.

@crisbeto crisbeto closed this Mar 16, 2021
@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 Apr 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement P4 A relatively minor issue that is not relevant to core functions target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(mat-selection-list): do not allow ctrl + a when mat-selection-list is disabled
8 participants