Skip to content

Commit

Permalink
fix(module: input-item): fix ios9 chinese character bug (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
sWhite01111 authored and fisherspy committed Jan 16, 2019
1 parent 3e7efd4 commit f421746
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 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 All @@ -31,6 +31,8 @@
[pattern]="pattern"
[style.color]='fontColor'
(ngModelChange)="inputChange($event)"
(compositionstart)="compositionStart($event)"
(compositionend)="compositionEnd($event)"
(blur)="inputBlur(value)"
(focus)="inputFocus(value)"
style="outline:none" />
Expand Down
15 changes: 15 additions & 0 deletions components/input-item/input-item.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ describe('InputComponent', () => {
expect(fakeInput.innerText).toBe('23', 'type is money');
});

it('should input chinese character work', () => {
const inputModelEle = inputModel.nativeElement.querySelector('input');
inputModelEle.value = '哈哈';
inputModelEle.dispatchEvent(new Event('compositionstart'));
inputModelEle.dispatchEvent(new Event('input'));
fixture.detectChanges();
expect(component.modelValue).toBe(undefined);

inputModelEle.value = '哈哈';
inputModelEle.dispatchEvent(new Event('compositionend'));
inputModelEle.dispatchEvent(new Event('input'));
fixture.detectChanges();
expect(component.modelValue).toBe('哈哈');
});

it('should defaultValue work', () => {
component.defaultValue = 'test';
fixture.detectChanges();
Expand Down
12 changes: 12 additions & 0 deletions components/input-item/input-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class InputItem implements OnInit, OnChanges, ControlValueAccessor {
private _focus: boolean = false;
private _isClear: boolean = false;
private _fontColor: string;
private _inputLock = false;

@ViewChild('lableContent')
lableRef;
Expand Down Expand Up @@ -257,6 +258,9 @@ export class InputItem implements OnInit, OnChanges, ControlValueAccessor {
}

inputChange(e) {
if (this._inputLock && this.inputType === 'text') {
return;
}
let value = e;
switch (this.inputType) {
case 'text':
Expand Down Expand Up @@ -292,6 +296,14 @@ export class InputItem implements OnInit, OnChanges, ControlValueAccessor {
this.onChange.emit(this._value);
}

compositionStart() {
this._inputLock = true;
}

compositionEnd() {
this._inputLock = false;
}

inputFocus(value) {
setTimeout(() => {
this._focus = true;
Expand Down

0 comments on commit f421746

Please sign in to comment.