Skip to content

Commit

Permalink
fix(ui5-slider): fire 'change' event on keyup (#10803)
Browse files Browse the repository at this point in the history
* fix(ui5-slider): fire 'change' event on keyup

fixes: #10770
  • Loading branch information
ndeshev authored Mar 10, 2025
1 parent f8df44f commit 078d44c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/main/cypress/specs/Slider.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Slider from "../../src/Slider.js";

describe("General interactions", () => {
it("Fire change event on keyup", () => {
let changeCount = 0;
cy.mount(
<Slider min={0} max={20}></Slider>
);

cy.get("[ui5-slider]").then($slider => {
$slider[0].addEventListener("ui5-change", () => {
changeCount++;
});
});

// First 'change' event is fired when the slider is clicked
cy.get("[ui5-slider]").click();

// Second 'change' event is fired on keyboard interaction
cy.get("[ui5-slider]").realPress("ArrowRight");

cy.then(() => {
expect(changeCount).to.equal(2);
});
});
});
12 changes: 12 additions & 0 deletions packages/main/src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ class Slider extends SliderBase implements IFormInputElement {
this._valueOnInteractionStart = undefined;
}

_onkeyup(e: KeyboardEvent) {
const isActionKey = SliderBase._isActionKey(e);

this._onKeyupBase();

if (isActionKey && this._valueOnInteractionStart !== this.value) {
this.fireDecoratorEvent("change");
}

this._valueOnInteractionStart = this.value;
}

_onInputFocusOut(e: FocusEvent) {
const tooltipInput = this.shadowRoot!.querySelector("[ui5-input]") as Input;

Expand Down
1 change: 1 addition & 0 deletions packages/main/src/SliderTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function handles(this: Slider) {
<div class="ui5-slider-handle"
onFocusOut={this._onfocusout}
onFocusIn={this._onfocusin}
onKeyUp={this._onkeyup}
role="slider"
tabIndex={this._tabIndex}
aria-orientation="horizontal"
Expand Down

0 comments on commit 078d44c

Please sign in to comment.