Skip to content

Commit b8972da

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
refactor(devtools): replace HostListener with host metadata for keydown handling
Uses host metadata instead of the HostListener decorator for keydown events (cherry picked from commit c74367c)
1 parent 7f8336d commit b8972da

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ const NODE_ITEM_HEIGHT = 18; // px; Required for CDK Virtual Scroll
5151
CdkVirtualForOf,
5252
TreeNodeComponent,
5353
],
54+
host: {
55+
'(document:keydown.ArrowUp)': 'navigateUp($event)',
56+
'(document:keydown.ArrowDown)': 'navigateDown($event)',
57+
'(document:keydown.ArrowLeft)': 'collapseCurrent($event)',
58+
'(document:keydown.ArrowRight)': 'expandCurrent($event)',
59+
},
5460
})
5561
export class DirectiveForestComponent {
5662
private readonly tabUpdate = inject(TabUpdate);
@@ -174,7 +180,6 @@ export class DirectiveForestComponent {
174180
this.setParents.emit(null);
175181
}
176182

177-
@HostListener('document:keydown.ArrowUp', ['$event'])
178183
navigateUp(event: Event): void {
179184
if (this.isEditingDirectiveState(event)) {
180185
return;
@@ -199,7 +204,6 @@ export class DirectiveForestComponent {
199204
this.selectAndEnsureVisible(data[prevIdx]);
200205
}
201206

202-
@HostListener('document:keydown.ArrowDown', ['$event'])
203207
navigateDown(event: Event): void {
204208
if (this.isEditingDirectiveState(event)) {
205209
return;
@@ -227,7 +231,6 @@ export class DirectiveForestComponent {
227231
this.selectAndEnsureVisible(data[idx]);
228232
}
229233

230-
@HostListener('document:keydown.ArrowLeft', ['$event'])
231234
collapseCurrent(event: Event): void {
232235
if (this.isEditingDirectiveState(event)) {
233236
return;
@@ -240,7 +243,6 @@ export class DirectiveForestComponent {
240243
event.preventDefault();
241244
}
242245

243-
@HostListener('document:keydown.ArrowRight', ['$event'])
244246
expandCurrent(event: Event): void {
245247
if (this.isEditingDirectiveState(event)) {
246248
return;

0 commit comments

Comments
 (0)