Skip to content

fix(list-key-manager): infinite loop if all items are disabled #9981

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

Conversation

devversion
Copy link
Member

  • Currently if the ListKeyManager is being used in wrap mode, and all items are disabled, pressing the down arrow key will cause the key manager to go into an infinite loop that searches for the next item.

Related #9963

* Currently if the `ListKeyManager` is being used in wrap mode, and all items are disabled, pressing the down arrow key will cause the key manager to go into an infinite loop that searches for the next item.

Related angular#9963
@devversion devversion added pr: needs review target: patch This PR is targeted for the next patch release labels Feb 16, 2018
@devversion devversion requested a review from jelbourn as a code owner February 16, 2018 12:53
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 16, 2018
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

// If the test setup crashes or this test times out, this test can be considered as failed.
it('should not get into an infinite loop if all items are disabled', () => {
keyManager.withWrap();
keyManager.setActiveItem(0);
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 chain the withWrap and setActiveItem.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to keep it consistent with the rest of the tests. All of those don't seem to chain either.


if (!item.disabled) {
this.setActiveItem(index);
break;
Copy link
Member

Choose a reason for hiding this comment

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

Might be a good idea to return here instead so we don't put some extra logic below by accident.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that works too. Changed it

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Feb 16, 2018
devversion added a commit to devversion/material2 that referenced this pull request Feb 17, 2018
* Currently if a list option is disabled through the `[disabled]` binding, the disabled option still has the `pointer` cursor.

* No longer delegates the keydown event to the ListKeyManager when disabled. Right now there can be an exception because all items are disabled. See angular#9981.

Fixes angular#9952.
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

this.setActiveItem(this._activeItemIndex);
private _setActiveInWrapMode(delta: -1 | 1, items: T[]): void {
for (let i = 1; i <= items.length; i++) {
const index = (this._activeItemIndex + delta * i + items.length) % items.length;
Copy link
Member

Choose a reason for hiding this comment

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

Use parentheses around the multiplication to make the order of operations explicit

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jelbourn jelbourn merged commit 230e22b into angular:master Feb 18, 2018
jelbourn pushed a commit that referenced this pull request Feb 18, 2018
* Currently if a list option is disabled through the `[disabled]` binding, the disabled option still has the `pointer` cursor.
* No longer delegates the keydown event to the ListKeyManager when disabled. Right now there can be an exception because all items are disabled. See #9981.

Fixes #9952.
tinayuangao pushed a commit that referenced this pull request Feb 20, 2018
Currently if the `ListKeyManager` is being used in wrap mode, and all items are disabled, pressing the down arrow key will cause the key manager to go into an infinite loop that searches for the next item.

Related #9963
tinayuangao pushed a commit that referenced this pull request Feb 20, 2018
* Currently if a list option is disabled through the `[disabled]` binding, the disabled option still has the `pointer` cursor.
* No longer delegates the keydown event to the ListKeyManager when disabled. Right now there can be an exception because all items are disabled. See #9981.

Fixes #9952.
andrewseguin pushed a commit that referenced this pull request Feb 20, 2018
* Currently if a list option is disabled through the `[disabled]` binding, the disabled option still has the `pointer` cursor.
* No longer delegates the keydown event to the ListKeyManager when disabled. Right now there can be an exception because all items are disabled. See #9981.

Fixes #9952.
andrewseguin pushed a commit that referenced this pull request Feb 20, 2018
Currently if the `ListKeyManager` is being used in wrap mode, and all items are disabled, pressing the down arrow key will cause the key manager to go into an infinite loop that searches for the next item.

Related #9963
@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 8, 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