Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions core/src/components/range/range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ export class Range implements ComponentInterface {
*/
@Prop({ mutable: true }) value: RangeValue = 0;
@Watch('value')
protected valueChanged() {
protected valueChanged(newVlue: RangeValue, oldValue: RangeValue) {
// The check is necessary because the value can be an object.
if (JSON.stringify(newVlue) !== JSON.stringify(oldValue)) {
this.ionInput.emit({ value: this.value });
}

if (!this.noUpdate) {
this.updateRatio();
}
Expand Down Expand Up @@ -591,8 +596,6 @@ export class Range implements ComponentInterface {
upper: Math.max(valA, valB),
};

this.ionInput.emit({ value: this.value });

this.noUpdate = false;
}

Expand Down
36 changes: 36 additions & 0 deletions core/src/components/range/test/range-events.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,42 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
expect(ionInputSpy).toHaveReceivedEvent();
});

test('should not emit when the value does not change', async ({ page }, testInfo) => {
testInfo.annotations.push({
type: 'issue',
description: 'https://github.com/ionic-team/ionic-framework/issues/29619',
});

/**
* Requires padding to prevent the knob from being clipped.
* If it's clipped, then the value might be one off.
* For example, if the knob is clipped on the right, then the value
* will be 99 instead of 100.
*/
await page.setContent(
`
<div style="padding: 0 20px">
<ion-range aria-label="range"></ion-range>
</div>
`,
config
);

const rangeHandle = page.locator('ion-range .range-knob-handle');
const ionInputSpy = await page.spyOnEvent('ionInput');

const rangeHandleBoundingBox = await rangeHandle.boundingBox();
const x = rangeHandleBoundingBox!.width / 2;
const y = rangeHandleBoundingBox!.height / 2;

// Click in the middle of the knob to prevent the knob from moving.
await rangeHandle.click({
position: { x, y },
});

expect(ionInputSpy).not.toHaveReceivedEvent();
});

test('should emit when the knob is moved with the keyboard', async ({ page }) => {
await page.setContent(`<ion-range aria-label="range" value="50"></ion-range>`, config);

Expand Down
Loading