Skip to content

Commit

Permalink
fix(input-number): fix input number display value error with suffix w…
Browse files Browse the repository at this point in the history
…hen delete #PJM-16714
  • Loading branch information
HandsomeButterball committed Dec 27, 2023
1 parent de7d4f1 commit 8e2b362
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/input-number/input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,17 @@ export class ThyInputNumberComponent
}

onModelChange(value: string): void {
const parseValue = this.parser(value);
if (this.isInputNumber(value)) {
this.activeValue = value;
} else {
this.displayValue = this.activeValue;
this.inputElement.nativeElement.value = this.displayValue;
this.displayValue = parseValue;
this.inputElement.nativeElement.value = parseValue;
}
const parseValue = this.parser(value);
const validValue = this.getCurrentValidValue(parseValue);
if (this.validValue !== validValue) {
if (`${this.validValue}` !== `${validValue}`) {
this.updateValidValue(validValue);
this.onChangeFn(this.validValue);
this.onChangeFn(validValue);
}
}

Expand Down
19 changes: 5 additions & 14 deletions src/input-number/test/input-number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,19 @@ describe('input-number component', () => {
it('should Only floating point numbers can be entered work', fakeAsync(() => {
const testValueToken = [
{ from: '-', to: '' },
{ from: '-3', to: '-3' },
{ from: '-3abc', to: '-3' },
{ from: '-3.1', to: '-3.1' }
{ from: '-3', to: '0' },
{ from: '-3abc', to: '0' },
{ from: '-3.1', to: '0' }
];
fixture.detectChanges();
testValueToken.forEach(item => {
inputElement.value = item.from;
const inputNumberComponent = inputNumberComponentInstance.inputNumberComponent;
inputNumberComponent.onModelChange(item.from);
dispatchKeyboardEvent(inputElement, 'keydown', keycodes.ENTER);
tick();
fixture.detectChanges();
flush();
expect(inputElement.value).toBe(item.to);
expect(inputNumberComponent.displayValue).toBe(item.to);
});
}));

Expand All @@ -603,19 +603,10 @@ describe('input-number component', () => {
it('should set activeValue to value if it is a number', () => {
fixture.detectChanges();
const component = inputNumberComponentInstance.inputNumberComponent;
console.log(inputNumberComponentInstance, component);
component.onModelChange('123');
expect(component.activeValue).toBe('123');
});

it('should set displayValue to activeValue if value is not a number', () => {
fixture.detectChanges();
const component = inputNumberComponentInstance.inputNumberComponent;
component.activeValue = '123';
component.onModelChange('abc');
expect(component.displayValue).toBe('123');
});

it('should call parser with value', () => {
fixture.detectChanges();
const component = inputNumberComponentInstance.inputNumberComponent;
Expand Down

0 comments on commit 8e2b362

Please sign in to comment.