Skip to content

Commit

Permalink
refactor: migrate @HostBinding usage to host property of in the @Comp…
Browse files Browse the repository at this point in the history
…onent/@directive decorator
  • Loading branch information
jrassa committed Sep 13, 2024
1 parent 5166433 commit 189c998
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/app/common/link-accessibility.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, ElementRef, HostListener, Renderer2, inject } from '@angular/core';
import { Directive, ElementRef, Renderer2, inject } from '@angular/core';

/**
* Used to enable link for keyboard accessibility.
Expand All @@ -8,7 +8,10 @@ import { Directive, ElementRef, HostListener, Renderer2, inject } from '@angular
*/
@Directive({
selector: '[linkAccessibility]',
standalone: true
standalone: true,
host: {
'(keydown.enter)': 'onEnter($event)'
}
})
export class LinkAccessibilityDirective {
private elRef = inject(ElementRef);
Expand All @@ -19,7 +22,6 @@ export class LinkAccessibilityDirective {
this.renderer.setAttribute(el, 'tabIndex', '0');
}

@HostListener('keydown.enter', ['$event'])
onEnter(event: Event) {
event.target?.dispatchEvent(new Event('click'));
}
Expand Down
1 change: 0 additions & 1 deletion src/app/common/multi-select.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { NgSelectComponent } from '@ng-select/ng-select';
@Directive({
selector: 'ng-select[multi-select]',
standalone: true,
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
['class.ng-hide-arrow-wrapper']: 'hideArrow()'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
AfterViewInit,
ChangeDetectorRef,
Directive,
HostListener,
Input,
OnDestroy,
OnInit,
Expand All @@ -20,7 +19,12 @@ export interface AsyFilterHeaderColumnDef {
name: string;
}

@Directive({ standalone: true })
@Directive({
standalone: true,
host: {
'(click)': '_handleClick($event)'
}
})
export abstract class AsyAbstractHeaderFilterComponent<T>
implements AsyFilterable, AfterViewInit, OnDestroy, OnInit
{
Expand Down Expand Up @@ -104,7 +108,6 @@ export abstract class AsyAbstractHeaderFilterComponent<T>
/**
* Stop click event propagation to prevent sorting from being updated
*/
@HostListener('click', ['$event'])
_handleClick(event: Event) {
event.stopPropagation();
}
Expand Down
1 change: 0 additions & 1 deletion src/app/common/table/filter/asy-filter.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface AsyFilterable {
@Directive({
selector: '[asyFilter]',
exportAs: 'asyFilter',
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: { class: 'asy-filter' },
standalone: true
})
Expand Down
1 change: 0 additions & 1 deletion src/app/common/table/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap';
selector: 'asy-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: {
class: 'sidebar',
'[class.sidebar-open]': 'open()',
Expand Down
1 change: 0 additions & 1 deletion src/app/common/table/sort/asy-sort.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface AsySortable {
@Directive({
selector: '[asySort]',
exportAs: 'asySort',
// eslint-disable-next-line @angular-eslint/no-host-metadata-property
host: { class: 'asy-sort' },
standalone: true
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { DOCUMENT, LowerCasePipe, NgClass } from '@angular/common';
import {
Component,
DestroyRef,
HostListener,
OnInit,
inject,
signal,
viewChild
} from '@angular/core';
import { Component, DestroyRef, OnInit, inject, signal, viewChild } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';

import { WINDOW } from '@ng-web-apis/common';
Expand All @@ -23,7 +15,10 @@ import { MessageService } from '../message.service';
templateUrl: './view-all-messages.component.html',
styleUrls: ['./view-all-messages.component.scss'],
standalone: true,
imports: [SystemAlertComponent, SearchInputComponent, NgClass, LowerCasePipe, AgoDatePipe]
imports: [SystemAlertComponent, SearchInputComponent, NgClass, LowerCasePipe, AgoDatePipe],
host: {
'(window:scroll)': 'onScroll()'
}
})
export class ViewAllMessagesComponent implements OnInit {
readonly #destroyRef = inject(DestroyRef);
Expand Down Expand Up @@ -52,7 +47,6 @@ export class ViewAllMessagesComponent implements OnInit {
});
}

@HostListener('window:scroll')
onScroll() {
// If at the bottom of the page, load more messages
if (
Expand Down

0 comments on commit 189c998

Please sign in to comment.