Skip to content

fix(list-key-manager): allow withWrap to be disabled #11920

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
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cdk/a11y/key-manager/list-key-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,20 @@ describe('Key managers', () => {

keyManager.onKeydown(fakeKeyEvents.downArrow);
});

it('should be able to disable wrapping', () => {
keyManager.withWrap();
keyManager.setFirstItemActive();
keyManager.onKeydown(fakeKeyEvents.upArrow);

expect(keyManager.activeItemIndex).toBe(itemList.items.length - 1);

keyManager.withWrap(false);
keyManager.setFirstItemActive();
keyManager.onKeydown(fakeKeyEvents.upArrow);

expect(keyManager.activeItemIndex).toBe(0);
});
});

describe('skip predicate', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/cdk/a11y/key-manager/list-key-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
}

/**
* Turns on wrapping mode, which ensures that the active item will wrap to
* Configures wrapping mode, which determines whether the active item will wrap to
* the other end of list when there are no more items in the given direction.
* @param shouldWrap Whether the list should wrap when reaching the end.
*/
withWrap(): this {
this._wrap = true;
withWrap(shouldWrap = true): this {
this._wrap = shouldWrap;
return this;
}

Expand Down