Skip to content

Commit 383f7b6

Browse files
crisbetowagnermaciel
authored andcommitted
fix(material/slider): make value non-nullable (#22912)
Makes the value of the slider a `number`, rather than `number | null` in order to make it easier to use. Fixes #22444. (cherry picked from commit 71afc46)
1 parent db855c2 commit 383f7b6

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/material/slider/slider.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ export class MatSlider extends _MatSliderMixinBase
190190
get min(): number { return this._min; }
191191
set min(v: number) {
192192
this._min = coerceNumberProperty(v, this._min);
193-
194-
// If the value wasn't explicitly set by the user, set it to the min.
195-
if (this._value === null) {
196-
this.value = this._min;
197-
}
198193
this._percent = this._calculatePercentage(this._value);
199194

200195
// Since this also modifies the percentage, we need to let the change detection know.
@@ -242,16 +237,16 @@ export class MatSlider extends _MatSliderMixinBase
242237

243238
/** Value of the slider. */
244239
@Input()
245-
get value(): number | null {
240+
get value(): number {
246241
// If the value needs to be read and it is still uninitialized, initialize it to the min.
247242
if (this._value === null) {
248243
this.value = this._min;
249244
}
250-
return this._value;
245+
return this._value as number;
251246
}
252-
set value(v: number | null) {
247+
set value(v: number) {
253248
if (v !== this._value) {
254-
let value = coerceNumberProperty(v);
249+
let value = coerceNumberProperty(v, 0);
255250

256251
// While incrementing by a decimal we can end up with values like 33.300000000000004.
257252
// Truncate it to ensure that it matches the label and to make it easier to work with.

tools/public_api_guard/material/slider.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export declare class MatSlider extends _MatSliderMixinBase implements ControlVal
2323
set thumbLabel(value: boolean);
2424
get tickInterval(): 'auto' | number;
2525
set tickInterval(value: 'auto' | number);
26-
get value(): number | null;
27-
set value(v: number | null);
26+
get value(): number;
27+
set value(v: number);
2828
readonly valueChange: EventEmitter<number | null>;
2929
valueText: string;
3030
get vertical(): boolean;

0 commit comments

Comments
 (0)