Skip to content

Commit

Permalink
fix(slider): reflect to old value on empty input value (#1196)
Browse files Browse the repository at this point in the history
* fix(slider): use old value when input is empty

* refactor(slider): rename variable and remove unnecessary condition

* refactor(slider): rearrange condition and remove prevent default

---------

Co-authored-by: Napat Bualoy <[email protected]>
  • Loading branch information
prima-lseg and bualoy-napat authored Jul 15, 2024
1 parent 46a6c62 commit 53e30de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/elements/src/slider/elements/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,17 +897,18 @@ export class Slider extends FormFieldElement {
return;
}

const { value, name } = event.target as NumberField;
const inputEl = event.target as NumberField;
const { value, name } = inputEl;

const currentData = name as SliderDataName;
const previousData = `${name}Previous` as SliderPreviousDataName;

if (value && this[currentData] !== value) {
if (!value) {
inputEl.value = this[currentData];
} else if (this[currentData] !== value) {
this.updateNotifyProperty(currentData, value);
this[previousData] = value;
}

event.preventDefault();
}

/**
Expand Down Expand Up @@ -1297,6 +1298,7 @@ export class Slider extends FormFieldElement {
if (this.minNumber > this.maxNumber) {
return false;
}

// Check if value is in range
if (value < this.minNumber || value > this.maxNumber) {
return false;
Expand Down

0 comments on commit 53e30de

Please sign in to comment.