fix(range): fixing case where step would break if set to undefined

This commit is contained in:
ShaneK
2025-03-07 13:50:41 -08:00
parent e01c7d7285
commit 5abf5ef752
2 changed files with 9 additions and 0 deletions

View File

@ -159,6 +159,12 @@ export class Range implements ComponentInterface {
* Specifies the value granularity. * Specifies the value granularity.
*/ */
@Prop() step = 1; @Prop() step = 1;
@Watch('step')
protected stepChanged(newValue: number) {
if (!isSafeNumber(newValue)) {
this.step = 1;
}
}
/** /**
* If `true`, tick marks are displayed based on the step value. * If `true`, tick marks are displayed based on the step value.
@ -312,6 +318,7 @@ export class Range implements ComponentInterface {
// Our watch does this, but not before the initial load. // Our watch does this, but not before the initial load.
this.min = isSafeNumber(this.min) ? this.min : 0; this.min = isSafeNumber(this.min) ? this.min : 0;
this.max = isSafeNumber(this.max) ? this.max : 100; this.max = isSafeNumber(this.max) ? this.max : 100;
this.step = isSafeNumber(this.step) ? this.step : 1;
} }
componentDidLoad() { componentDidLoad() {

View File

@ -40,9 +40,11 @@ describe('Range', () => {
// Here we have to cast this to any, but in its react wrapper it accepts undefined as a valid value // Here we have to cast this to any, but in its react wrapper it accepts undefined as a valid value
range.min = undefined as any; range.min = undefined as any;
range.max = undefined as any; range.max = undefined as any;
range.step = undefined as any;
await page.waitForChanges(); await page.waitForChanges();
expect(range.min).toBe(0); expect(range.min).toBe(0);
expect(range.max).toBe(100); expect(range.max).toBe(100);
expect(range.step).toBe(1);
}); });
it('should return the clamped value for a range dual knob component', () => { it('should return the clamped value for a range dual knob component', () => {