Make inputs cancelable

Closes #179
This commit is contained in:
Farkas József
2016-11-26 22:49:06 +01:00
parent a70a5fada2
commit 4cb46f3339
6 changed files with 39 additions and 10 deletions

View File

@@ -58,6 +58,8 @@ import { SvgModuleComponent } from './components/svg/module';
import { SvgKeyboardWrapComponent } from './components/svg/wrap';
import { MainAppComponent, appRoutingProviders, routing } from './main-app';
import { CancelableDirective } from './directives';
import { MapperService } from './services/mapper.service';
import { KeymapEffects, MacroEffects } from './store/effects';
@@ -121,7 +123,8 @@ const storeConfig = {
MacroMouseTabComponent,
MacroTextTabComponent,
AddOnComponent,
SettingsComponent
SettingsComponent,
CancelableDirective
],
imports: [
BrowserModule,

View File

@@ -1,13 +1,15 @@
<div class="row">
<h1 class="col-xs-12 pane-title">
<i class="fa fa-keyboard-o"></i>
<input #name class="keymap__name pane-title__name"
type="text"
value="{{ keymap.name }}"
(change)="editKeymapName($event.target.value)"
(keyup.enter)="name.blur()"
<input #name cancelable
class="keymap__name pane-title__name"
type="text"
value="{{ keymap.name }}"
(change)="editKeymapName($event.target.value)"
(keyup.enter)="name.blur()"
/> keymap
(<input #abbr class="keymap__abbrev pane-title__abbrev"
(<input #abbr cancelable
class="keymap__abbrev pane-title__abbrev"
type="text"
value="{{ keymap.abbreviation }}"
(change)="editKeymapAbbr($event.target.value)"

View File

@@ -1,9 +1,10 @@
<div class="row">
<h1 class="col-xs-12 pane-title">
<i class="fa fa-play"></i>
<input #macroName class="pane-title__name"
type="text"
value="{{ macro.name }}"
<input #macroName cancelable
class="pane-title__name"
type="text"
value="{{ macro.name }}"
(change)="editMacroName($event.target.value)"
(keyup.enter)="macroName.blur()"
/>

View File

@@ -0,0 +1,21 @@
import { Directive, ElementRef, HostListener, Renderer } from '@angular/core';
@Directive({
selector: '[cancelable]'
})
export class CancelableDirective {
private originalValue: string;
constructor(private elementRef: ElementRef, private renderer: Renderer) { }
@HostListener('focus') onFocus(): void {
this.originalValue = this.elementRef.nativeElement.value;
}
@HostListener('keyup.escape') onEscape(): void {
this.renderer.setElementProperty(this.elementRef.nativeElement, 'value', this.originalValue);
this.renderer.invokeElementMethod(this.elementRef.nativeElement, 'blur');
}
}

View File

@@ -0,0 +1 @@
export { CancelableDirective } from './cancelable.directive';

1
src/directives/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './cancelable';