Skip to content

Commit 71afc46

Browse files
authored
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.
1 parent 0431d81 commit 71afc46

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
@@ -181,11 +181,6 @@ export class MatSlider extends _MatSliderBase
181181
get min(): number { return this._min; }
182182
set min(v: number) {
183183
this._min = coerceNumberProperty(v, this._min);
184-
185-
// If the value wasn't explicitly set by the user, set it to the min.
186-
if (this._value === null) {
187-
this.value = this._min;
188-
}
189184
this._percent = this._calculatePercentage(this._value);
190185

191186
// Since this also modifies the percentage, we need to let the change detection know.
@@ -233,16 +228,16 @@ export class MatSlider extends _MatSliderBase
233228

234229
/** Value of the slider. */
235230
@Input()
236-
get value(): number | null {
231+
get value(): number {
237232
// If the value needs to be read and it is still uninitialized, initialize it to the min.
238233
if (this._value === null) {
239234
this.value = this._min;
240235
}
241-
return this._value;
236+
return this._value as number;
242237
}
243-
set value(v: number | null) {
238+
set value(v: number) {
244239
if (v !== this._value) {
245-
let value = coerceNumberProperty(v);
240+
let value = coerceNumberProperty(v, 0);
246241

247242
// While incrementing by a decimal we can end up with values like 33.300000000000004.
248243
// 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 _MatSliderBase implements ControlValueAcc
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)