mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-05-08 23:03:13 -04:00
Fix number input eager clamping on keystrokes (#583)
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
[step]="step()"
|
||||
[value]="value()"
|
||||
(input)="onInput($event)"
|
||||
(blur)="blurred.emit($event)"
|
||||
(blur)="onBlur($event)"
|
||||
/>
|
||||
@if (suffix()) {
|
||||
<span class="number-suffix">{{ suffix() }}</span>
|
||||
|
||||
@@ -34,21 +34,22 @@ export class NumberInputComponent {
|
||||
this.value.set(null);
|
||||
return;
|
||||
}
|
||||
this.value.set(Number(target.value));
|
||||
}
|
||||
|
||||
let num = Number(target.value);
|
||||
const minVal = this.min();
|
||||
const maxVal = this.max();
|
||||
|
||||
if (minVal != null) {
|
||||
num = Math.max(num, minVal);
|
||||
onBlur(event: FocusEvent): void {
|
||||
const current = this.value();
|
||||
if (current != null) {
|
||||
let clamped = current;
|
||||
const minVal = this.min();
|
||||
const maxVal = this.max();
|
||||
if (minVal != null) { clamped = Math.max(clamped, minVal); }
|
||||
if (maxVal != null) { clamped = Math.min(clamped, maxVal); }
|
||||
if (clamped !== current) {
|
||||
this.value.set(clamped);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxVal != null) {
|
||||
num = Math.min(num, maxVal);
|
||||
}
|
||||
|
||||
target.value = String(num);
|
||||
this.value.set(num);
|
||||
this.blurred.emit(event);
|
||||
}
|
||||
|
||||
increment(): void {
|
||||
|
||||
Reference in New Issue
Block a user