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): do not allow toggling disabled options #12617

Merged

Conversation

devversion
Copy link
Member

@devversion devversion commented Aug 10, 2018

  • Currently due to a misplaced disabled check in the selection list, users can toggle the state of a disabled <mat-option> by using the keyboard.

  • The issue is that we just check for the disabled state of the selection list, instead of looking at the disabled state of the individual option that should be toggled.

--

Note: We can also have tests for ENTER and SHIFT navigation, but not sure if that's necessary. Having the SPACE test, seems to already cover the actual "fault".

Fixes #12608

* Currently due to a misplaced `disabled` check in the selection list, users can toggle the state of a disabled `<mat-option>` by using the keyboard.

Fixes angular#12608
@devversion devversion added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release labels Aug 10, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 10, 2018
}
this._toggleFocusedOptionIfEnabled();
// Always prevent space from scrolling the page since the list has focus
event.preventDefault();
break;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be simpler to fix the issue by having a return here instead of the break?

Copy link
Member Author

@devversion devversion Aug 10, 2018

Choose a reason for hiding this comment

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

How does the issue relate to the break here? The issue is that we just check the state of SelectionList#disabled instead of looking at the disabled state of the individual option that should be toggled.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry I misread it.

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem, I've updated the PR description to explain what's causing the issue.

/** Toggles the selected state of the currently focused option. */
private _toggleSelectOnFocusedOption(): void {
/** Toggles the state of the currently focused option if enabled. */
private _toggleFocusedOptionIfEnabled(): void {
Copy link
Member

Choose a reason for hiding this comment

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

Even though this method is private, the naming sounds weird. If we end up doing this, instead of what I mentioned above, I think it should be turned into _getFocusedOption and then the place it gets consumed would check whether it's disabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed on Slack. In my opinion, this would result in code duplication that can be avoided by just having such a method.

I'm not sure about the method name, though. I agree that IfEnabled sounds weird. For now, changed it to just _toggleFocusedOption.

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 labels Aug 10, 2018
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

@mmalerba mmalerba merged commit 4cfdb20 into angular:master Aug 16, 2018
@devversion devversion deleted the fix/selection-list-toggle-disabled branch August 16, 2018 17:35
mmalerba pushed a commit that referenced this pull request Aug 20, 2018
* fix(selection-list): do not allow toggling disabled options

* Currently due to a misplaced `disabled` check in the selection list, users can toggle the state of a disabled `<mat-option>` by using the keyboard.

Fixes #12608

* Rename function
@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 P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mat-Selection-List disabled options keyboard selectable
5 participants