Skip to content

Instantly share code, notes, and snippets.

@alexzuza
Created November 13, 2020 13:04
Show Gist options
  • Save alexzuza/11244800f934a09b67ef3013debc82b8 to your computer and use it in GitHub Desktop.
Save alexzuza/11244800f934a09b67ef3013debc82b8 to your computer and use it in GitHub Desktop.
import { Component, OnInit, Input, ElementRef, HostListener, ViewChild } from '@angular/core';
@Component({
selector: '[context-help]',
templateUrl: './context-help.component.html',
styleUrls: ['./context-help.component.css'],
})
export class ContextHelpComponent {
@Input('context-help') content: string;
@ViewChild('container') containerRef: ElementRef;
showHelp = false;
@HostListener('document:click', ['$event'])
documentClicked({ target }: MouseEvent) {
if (!this.containerRef.nativeElement.contains(target)) {
this.showHelp = false;
}
}
@HostListener('window:keydown.Escape')
escapedClicked(): void {
this.showHelp = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment