Created
November 13, 2020 13:04
-
-
Save alexzuza/11244800f934a09b67ef3013debc82b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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