Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui5-range-slider): fire input event with correct values after swapping #6385

Merged
merged 9 commits into from
Feb 8, 2023
Merged
16 changes: 13 additions & 3 deletions packages/main/src/RangeSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ class RangeSlider extends SliderBase {
*
*/
onBeforeRendering() {
if (this.startValue > this.endValue) {
const affectedValue = this._valueAffected === "startValue" ? "endValue" : "startValue";

this._swapValues();
this._setAffectedValue(affectedValue);
}

if (!this.isCurrentStateOutdated()) {
return;
}
Expand Down Expand Up @@ -311,8 +318,6 @@ class RangeSlider extends SliderBase {
*/
_onkeyup() {
super._onkeyup();

this._swapValues();
this._setAffectedValue(undefined);
}

Expand Down Expand Up @@ -535,7 +540,6 @@ class RangeSlider extends SliderBase {
}

_handleUp() {
this._swapValues();
this._setAffectedValueByFocusedElement();
this._setAffectedValue(undefined);

Expand Down Expand Up @@ -784,6 +788,9 @@ class RangeSlider extends SliderBase {
*/
_swapValues() {
const affectedValue = this._valueAffected;
if (!affectedValue) {
return;
}

if (affectedValue === "startValue" && this.startValue > this.endValue) {
const prevEndValue = this.endValue;
Expand All @@ -802,6 +809,9 @@ class RangeSlider extends SliderBase {
this._setValuesAreReversed();
this.focusInnerElement();
}

this._updateHandlesAndRange(this[affectedValue]);
this.syncUIAndState();
}

/**
Expand Down
13 changes: 12 additions & 1 deletion packages/main/test/pages/RangeSlider.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ <h2>Event Testing Slider</h2>
<span>endValue in the change event: </span>
<span id="change-event-endValue"></span>
</div>

<div>
<span>startValue in the input event: </span>
<span id="input-event-startValue"></span>
</div>
<div>
<span>endValue in the input event: </span>
<span id="input-event-endValue"></span>
</div>
<h2>Event Testing Result Slider</h2>
<ui5-range-slider id="test-result-slider" start-value="1" end-value="2"></ui5-range-slider>
</section>
Expand All @@ -76,7 +83,11 @@ <h2>Event Testing Result Slider</h2>
eventTargetSlider.addEventListener("ui5-change", (e) => {
document.getElementById("change-event-startValue").innerText = e.target.startValue;
document.getElementById("change-event-endValue").innerText = e.target.endValue;
});

eventTargetSlider.addEventListener("ui5-input", (e) => {
document.getElementById("input-event-startValue").innerText = e.target.startValue;
document.getElementById("input-event-endValue").innerText = e.target.endValue;
});
</script>
</body>
Expand Down
16 changes: 16 additions & 0 deletions packages/main/test/specs/RangeSlider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ describe("Testing events", () => {
assert.strictEqual(changeEventEndValue, "4", "Values are swapped prior to the firing of change event");
});

it("Should fire input event with correctly swiped values", async () => {
await browser.url(`test/pages/RangeSlider.html`);

const rangeSlider = await browser.$("#test-slider");
const firstHandle = await rangeSlider.shadow$(".ui5-slider-handle--start");

await rangeSlider.setProperty("endValue", 3);
await firstHandle.dragAndDrop({ x: 300, y: 1 });

const inputEventStartValue = await browser.execute(() => document.querySelector("#input-event-startValue").innerText);
const inputEventEndValue = await browser.execute(() => document.querySelector("#input-event-endValue").innerText);

assert.strictEqual(inputEventStartValue, "3", "The input event is fired with the correct values");
assert.strictEqual(inputEventEndValue, "4", "The input event is fired with the correct values");
});

it("Should not fire change event after user interaction is finished if the current value is the same as the one at the start of the action", async () => {
await browser.url(`test/pages/RangeSlider.html`);

Expand Down