Skip to content

Commit 77aabff

Browse files
committed
fix(material/slider): handle null and undefined values in slider input
The slider values behaved inconsistently when we reset the formGroup. This MR will resolve that issue by setting `value` to default value when its `undefined` or `null` Fixes #30614
1 parent 810495c commit 77aabff

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/material/slider/slider-input.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export class MatSliderThumb implements _MatSliderThumb, OnDestroy, ControlValueA
9696
return numberAttribute(this._hostElement.value, 0);
9797
}
9898
set value(value: number) {
99-
value = isNaN(value) ? 0 : value;
99+
value = value && isNaN(value) ? 0 : value;
100+
if (value === null || value === undefined) {
101+
value = this._getDefaultValue();
102+
}
100103
const stringValue = value + '';
101104
if (!this._hasSetInitialValue) {
102105
this._initialValue = stringValue;

src/material/slider/slider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
140140
return this._min;
141141
}
142142
set min(v: number) {
143-
const min = isNaN(v) ? this._min : v;
143+
const min = !v || isNaN(v) ? this._min : v;
144144
if (this._min !== min) {
145145
this._updateMin(min);
146146
}
@@ -216,7 +216,7 @@ export class MatSlider implements AfterViewInit, OnDestroy, _MatSlider {
216216
return this._max;
217217
}
218218
set max(v: number) {
219-
const max = isNaN(v) ? this._max : v;
219+
const max = !v || isNaN(v) ? this._max : v;
220220
if (this._max !== max) {
221221
this._updateMax(max);
222222
}

0 commit comments

Comments
 (0)