-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Conversation
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. What to do if you already signed the CLAIndividual signers
Corporate signers
|
@googlebot I signed it! |
CLAs look good, thanks! |
src/lib/list/selection-list.ts
Outdated
@@ -374,12 +374,16 @@ export class MatSelectionList extends _MatSelectionListMixinBase implements Focu | |||
|
|||
/** Selects all of the options. */ | |||
selectAll() { | |||
this._setAllOptionsSelected(true); | |||
if (!this._disabled) { |
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.
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.
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.
Yes, that indeed sounds like a better solution.
src/lib/list/selection-list.spec.ts
Outdated
const event = createKeyboardEvent('keydown', A, selectionList.nativeElement); | ||
Object.defineProperty(event, 'ctrlKey', {get: () => true}); | ||
|
||
let selectList = |
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.
This should be a const
since it isn't being re-assigned.
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.
Fixed, thanks! :)
c1f9b05
to
adb9271
Compare
src/lib/list/selection-list.ts
Outdated
} | ||
}); | ||
// Don't change selected state if MatSelectionList is disabled | ||
if (!this.disabled) { |
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.
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.
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.
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.
@crisbeto could you please have a look again when you have some time? I was thinking to add a |
…t/mat-list-option is disabled
adb9271
to
5f74374
Compare
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.
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.
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.
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.
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.
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.
Hi @steve-todorov! This PR has merge conflicts due to recent upstream merges. |
@crisbeto do we still want to proceed with this change? |
This was resolved in #18885. Closing. |
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. |
Fixes #12542