mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-14 16:52:26 +08:00
fix(range): fixing case where step would break if set to undefined
This commit is contained in:
@ -159,6 +159,12 @@ export class Range implements ComponentInterface {
|
||||
* Specifies the value granularity.
|
||||
*/
|
||||
@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.
|
||||
@ -312,6 +318,7 @@ export class Range implements ComponentInterface {
|
||||
// Our watch does this, but not before the initial load.
|
||||
this.min = isSafeNumber(this.min) ? this.min : 0;
|
||||
this.max = isSafeNumber(this.max) ? this.max : 100;
|
||||
this.step = isSafeNumber(this.step) ? this.step : 1;
|
||||
}
|
||||
|
||||
componentDidLoad() {
|
||||
|
@ -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
|
||||
range.min = undefined as any;
|
||||
range.max = undefined as any;
|
||||
range.step = undefined as any;
|
||||
await page.waitForChanges();
|
||||
expect(range.min).toBe(0);
|
||||
expect(range.max).toBe(100);
|
||||
expect(range.step).toBe(1);
|
||||
});
|
||||
|
||||
it('should return the clamped value for a range dual knob component', () => {
|
||||
|
Reference in New Issue
Block a user