Skip to content

Commit

Permalink
Added support for keyboard controlling of the dialog, closes #117
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed May 27, 2018
1 parent eba1f7e commit e4951bf
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/lib/color-picker.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild,
ViewEncapsulation, ElementRef, ChangeDetectorRef } from '@angular/core';
import { Component, OnInit, OnDestroy, AfterViewInit,
ViewChild, HostListener, ViewEncapsulation,
ElementRef, ChangeDetectorRef } from '@angular/core';

import { detectIE } from './helpers';

Expand Down Expand Up @@ -99,6 +100,14 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
@ViewChild('alphaSlider') alphaSlider: ElementRef;
@ViewChild('dialogPopup') dialogElement: ElementRef;

@HostListener('document:keyup.esc', ['$event']) handleEsc(event: any): void {
this.onCancelColor(event);
}

@HostListener('document:keyup.enter', ['$event']) handleEnter(event: any): void {
this.onAcceptColor(event);
}

constructor(private elRef: ElementRef, private cdRef: ChangeDetectorRef, private service: ColorPickerService) {}

ngOnInit(): void {
Expand Down Expand Up @@ -533,7 +542,7 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
this.cdRef.detectChanges();
}, 0);

this.directiveInstance.toggle(true);
this.directiveInstance.stateChanged(true);

if (!this.isIE10) {
document.addEventListener('mousedown', this.listenerMouseDown);
Expand All @@ -547,7 +556,7 @@ export class ColorPickerComponent implements OnInit, OnDestroy, AfterViewInit {
if (this.show) {
this.show = false;

this.directiveInstance.toggle(false);
this.directiveInstance.stateChanged(false);

if (!this.isIE10) {
document.removeEventListener('mousedown', this.listenerMouseDown);
Expand Down

0 comments on commit e4951bf

Please sign in to comment.