File

src/core/src/directives/keyboard.directive.ts

Implements

OnDestroy

Metadata

Selector input[matKeyboard], textarea[matKeyboard]

Index

Properties
Methods
Inputs
Outputs
HostListeners

Constructor

constructor(_elementRef: ElementRef, _keyboardService: MatKeyboardService, _control?: NgControl)
Parameters :
Name Type Optional
_elementRef ElementRef No
_keyboardService MatKeyboardService No
_control NgControl Yes

Inputs

darkTheme

Type : boolean

duration

Type : number

isDebug

Type : boolean

matKeyboard

Type : string

Outputs

altClick $event Type: EventEmitter<void>
capsClick $event Type: EventEmitter<void>
enterClick $event Type: EventEmitter<void>
shiftClick $event Type: EventEmitter<void>

HostListeners

blur
Arguments : '$event'
blur()
focus
Arguments : '$event'
focus()

Methods

ngOnDestroy
ngOnDestroy()
Returns : void

Properties

Private _keyboardRef
_keyboardRef: MatKeyboardRef<MatKeyboardComponent>
Type : MatKeyboardRef<MatKeyboardComponent>
import { Directive, ElementRef, EventEmitter, HostListener, Input, OnDestroy, Optional, Output, Self } from '@angular/core';
import { NgControl } from '@angular/forms';

import { MatKeyboardRef } from '../classes/keyboard-ref.class';
import { MatKeyboardComponent } from '../components/keyboard/keyboard.component';
import { MatKeyboardService } from '../services/keyboard.service';

@Directive({
  selector: 'input[matKeyboard], textarea[matKeyboard]'
})
export class MatKeyboardDirective implements OnDestroy {

  private _keyboardRef: MatKeyboardRef<MatKeyboardComponent>;

  @Input() matKeyboard: string;

  @Input() darkTheme: boolean;

  @Input() duration: number;

  @Input() isDebug: boolean;

  @Output() enterClick: EventEmitter<void> = new EventEmitter<void>();

  @Output() capsClick: EventEmitter<void> = new EventEmitter<void>();

  @Output() altClick: EventEmitter<void> = new EventEmitter<void>();

  @Output() shiftClick: EventEmitter<void> = new EventEmitter<void>();

  constructor(private _elementRef: ElementRef,
              private _keyboardService: MatKeyboardService,
              @Optional() @Self() private _control?: NgControl) {}

  ngOnDestroy() {
    this._hideKeyboard();
  }

  @HostListener('focus', ['$event'])
  private _showKeyboard() {
    this._keyboardRef = this._keyboardService.open(this.matKeyboard, {
      darkTheme: this.darkTheme,
      duration: this.duration,
      isDebug: this.isDebug
    });

    // reference the input element
    this._keyboardRef.instance.setInputInstance(this._elementRef);

    // set control if given, cast to smth. non-abstract
    if (this._control) {
      this._keyboardRef.instance.attachControl(this._control.control);
    }

    // connect outputs
    this._keyboardRef.instance.enterClick.subscribe(() => this.enterClick.next());
    this._keyboardRef.instance.capsClick.subscribe(() => this.capsClick.next());
    this._keyboardRef.instance.altClick.subscribe(() => this.altClick.next());
    this._keyboardRef.instance.shiftClick.subscribe(() => this.shiftClick.next());
  }

  @HostListener('blur', ['$event'])
  private _hideKeyboard() {
    if (this._keyboardRef) {
      this._keyboardRef.dismiss();
    }
  }

}

result-matching ""

    No results matching ""