Skip to content

Commit e9e44f6

Browse files
crisbetojosephperrott
authored andcommitted
fix(list-key-manager): allow withWrap to be disabled (#11920)
1 parent d88e021 commit e9e44f6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/cdk/a11y/key-manager/list-key-manager.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,20 @@ describe('Key managers', () => {
526526

527527
keyManager.onKeydown(fakeKeyEvents.downArrow);
528528
});
529+
530+
it('should be able to disable wrapping', () => {
531+
keyManager.withWrap();
532+
keyManager.setFirstItemActive();
533+
keyManager.onKeydown(fakeKeyEvents.upArrow);
534+
535+
expect(keyManager.activeItemIndex).toBe(itemList.items.length - 1);
536+
537+
keyManager.withWrap(false);
538+
keyManager.setFirstItemActive();
539+
keyManager.onKeydown(fakeKeyEvents.upArrow);
540+
541+
expect(keyManager.activeItemIndex).toBe(0);
542+
});
529543
});
530544

531545
describe('skip predicate', () => {

src/cdk/a11y/key-manager/list-key-manager.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
9090
}
9191

9292
/**
93-
* Turns on wrapping mode, which ensures that the active item will wrap to
93+
* Configures wrapping mode, which determines whether the active item will wrap to
9494
* the other end of list when there are no more items in the given direction.
95+
* @param shouldWrap Whether the list should wrap when reaching the end.
9596
*/
96-
withWrap(): this {
97-
this._wrap = true;
97+
withWrap(shouldWrap = true): this {
98+
this._wrap = shouldWrap;
9899
return this;
99100
}
100101

0 commit comments

Comments
 (0)