Skip to content

Commit

Permalink
feat(module: input-item): fix input-item bug (#500)
Browse files Browse the repository at this point in the history
* feat(module: input-item): fix input cursor bug

* feat(module: input-item): hide keyboard when editable is false
  • Loading branch information
sWhite01111 authored and 3fuyu committed Jul 22, 2019
1 parent 50ade9b commit 9f9f579
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/input-item/input-item.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<input #inputElement
[type]="type"
[name]="name"
[ngModel]="value"
[(ngModel)]="value"
[defaultValue]="defaultValue"
[placeholder]="placeholder"
[disabled]="disabled"
Expand Down
8 changes: 4 additions & 4 deletions components/input-item/input-item.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ describe('InputComponent', () => {
component.value = 'test';
fixture.detectChanges();
inputEle = inputItem.nativeElement.querySelector('input');
expect(inputEle.value).toBe('test', 'type is text');
expect(inputEle.getAttribute('ng-reflect-model')).toBe('test', 'type is text');

component.value = null;
fixture.detectChanges();
inputEle = inputItem.nativeElement.querySelector('input');
expect(inputEle.value).toBe('', 'value is undefined');
expect(inputEle.getAttribute('ng-reflect-model')).toBe('', 'value is undefined');

component.type = 'money';
fixture.detectChanges();
Expand All @@ -76,7 +76,7 @@ describe('InputComponent', () => {
component.defaultValue = 'default test';
fixture.detectChanges();
inputEle = inputItem.nativeElement.querySelector('input');
expect(inputEle.value).toBe('test', 'type is text');
expect(inputEle.getAttribute('ng-reflect-model')).toBe('test', 'type is text');

component.type = 'money';
fixture.detectChanges();
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('InputComponent', () => {
component.defaultValue = 'test';
fixture.detectChanges();
inputEle = inputItem.nativeElement.querySelector('input');
expect(inputEle.value).toBe('test', 'type is text');
expect(inputEle.getAttribute('ng-reflect-model')).toBe('test', 'type is text');

component.type = 'money';
fixture.detectChanges();
Expand Down
17 changes: 4 additions & 13 deletions components/input-item/input-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
}
]
})
export class InputItemComponent implements OnInit, AfterViewInit, OnChanges, ControlValueAccessor {
export class InputItemComponent implements OnInit, AfterViewInit, ControlValueAccessor {
prefixCls: string = 'am-input';
wrapCls: object;
labelCls: object;
Expand Down Expand Up @@ -298,9 +298,6 @@ export class InputItemComponent implements OnInit, AfterViewInit, OnChanges, Con
break;
}
this._value = value;
if (this._type !== 'money') {
this.inputElementRef.nativeElement.value = this._value;
}
this._onChange(this._value);
this.onChange.emit(this._value);
}, 0);
Expand All @@ -315,6 +312,9 @@ export class InputItemComponent implements OnInit, AfterViewInit, OnChanges, Con
}

inputFocus(value) {
if (!this._editable && document.activeElement instanceof HTMLElement) {
document.activeElement.blur();
}
setTimeout(() => {
this._focus = true;
this.clsFocus = true;
Expand Down Expand Up @@ -343,9 +343,6 @@ export class InputItemComponent implements OnInit, AfterViewInit, OnChanges, Con
this.onChange.emit(this._value);
this._onChange(this._value);
this._isClear = true;
if (this._type !== 'money') {
this.inputElementRef.nativeElement.value = this._value;
}
this.inputFocus(this._value);
}

Expand Down Expand Up @@ -375,12 +372,6 @@ export class InputItemComponent implements OnInit, AfterViewInit, OnChanges, Con

registerOnTouched(fn: any): void {}

ngOnChanges() {
if (this.inputElementRef && this._type !== 'money' && this._value !== undefined) {
this.inputElementRef.nativeElement.value = this._value;
}
}

ngOnInit() {
this.setCls();
this.render.addClass(this._el, this._prefixListCls + '-item');
Expand Down

0 comments on commit 9f9f579

Please sign in to comment.