-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(list-key-manager): infinite loop if all items are disabled #9981
Conversation
* 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
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.
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); |
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.
You can chain the withWrap
and setActiveItem
.
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.
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; |
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.
Might be a good idea to return
here instead so we don't put some extra logic below by accident.
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.
Yeah that works too. Changed it
* 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.
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.
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; |
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.
Use parentheses around the multiplication to make the order of operations explicit
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.
Done.
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 #9963
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. |
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