Skip to content

Commit 5abf5ef

Browse files
committed
fix(range): fixing case where step would break if set to undefined
1 parent e01c7d7 commit 5abf5ef

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

core/src/components/range/range.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ export class Range implements ComponentInterface {
159159
* Specifies the value granularity.
160160
*/
161161
@Prop() step = 1;
162+
@Watch('step')
163+
protected stepChanged(newValue: number) {
164+
if (!isSafeNumber(newValue)) {
165+
this.step = 1;
166+
}
167+
}
162168

163169
/**
164170
* If `true`, tick marks are displayed based on the step value.
@@ -312,6 +318,7 @@ export class Range implements ComponentInterface {
312318
// Our watch does this, but not before the initial load.
313319
this.min = isSafeNumber(this.min) ? this.min : 0;
314320
this.max = isSafeNumber(this.max) ? this.max : 100;
321+
this.step = isSafeNumber(this.step) ? this.step : 1;
315322
}
316323

317324
componentDidLoad() {

core/src/components/range/test/range.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ describe('Range', () => {
4040
// Here we have to cast this to any, but in its react wrapper it accepts undefined as a valid value
4141
range.min = undefined as any;
4242
range.max = undefined as any;
43+
range.step = undefined as any;
4344
await page.waitForChanges();
4445
expect(range.min).toBe(0);
4546
expect(range.max).toBe(100);
47+
expect(range.step).toBe(1);
4648
});
4749

4850
it('should return the clamped value for a range dual knob component', () => {

0 commit comments

Comments
 (0)