Skip to content

Commit f89136a

Browse files
committed
fix(command.component): re-listen to keymanager changes when items change
fix #4
1 parent fc9039a commit f89136a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

projects/ngneat/cmdk/src/lib/components/command/command.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ export class CommandComponent
141141
const emit = true;
142142
this.setValue(value, emit);
143143
});
144+
}
145+
146+
private initKeyManager() {
147+
this.keyManager = new ActiveDescendantKeyManager(this.items)
148+
.withWrap(this.loop)
149+
.withPageUpDown()
150+
.skipPredicate((item) => item.disabled || !item.filtered);
144151

145152
// set active group on active item change
146153
this.keyManager.change.pipe(untilDestroyed(this)).subscribe(() => {
@@ -153,13 +160,6 @@ export class CommandComponent
153160
});
154161
}
155162

156-
private initKeyManager() {
157-
this.keyManager = new ActiveDescendantKeyManager(this.items)
158-
.withWrap(this.loop)
159-
.withPageUpDown()
160-
.skipPredicate((item) => item.disabled || !item.filtered);
161-
}
162-
163163
get filteredItems() {
164164
return this.items?.filter((item) => item.filtered);
165165
}
@@ -267,6 +267,7 @@ export class CommandComponent
267267
private scrollActiveIntoView() {
268268
const item = this.keyManager.activeItem;
269269
const nativeElement = item?._elementRef?.nativeElement;
270+
console.log(nativeElement);
270271
if (nativeElement) {
271272
if (nativeElement.parentElement?.firstChild === nativeElement) {
272273
// First item in Group, ensure heading is in view

0 commit comments

Comments
 (0)