Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 07deaec

Browse files
joyzhongcopybara-github
authored andcommitted
fix(slider): Fire custom change event on input change.
PiperOrigin-RevId: 353250140
1 parent 3fb3a02 commit 07deaec

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/mdc-slider/foundation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
498498
} else {
499499
this.setValue(value);
500500
}
501+
502+
this.adapter.emitChangeEvent(
503+
thumb === Thumb.START ? this.valueStart : this.value, thumb);
501504
}
502505

503506
/** Shows value indicator on thumb(s). */

packages/mdc-slider/test/foundation.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,23 @@ describe('MDCSliderFoundation', () => {
12061206
expect(mockAdapter.emitChangeEvent).toHaveBeenCalledWith(77, Thumb.END);
12071207
});
12081208

1209+
it('fires `change` event on input change', () => {
1210+
const {foundation, mockAdapter} = setUpAndInit({
1211+
valueStart: 20,
1212+
value: 50,
1213+
isRange: true,
1214+
isDiscrete: true,
1215+
});
1216+
1217+
mockAdapter.getInputValue.withArgs(Thumb.START).and.returnValue(5);
1218+
foundation.handleInputChange(Thumb.START);
1219+
expect(mockAdapter.emitChangeEvent).toHaveBeenCalledWith(5, Thumb.START);
1220+
1221+
mockAdapter.getInputValue.withArgs(Thumb.END).and.returnValue(60);
1222+
foundation.handleInputChange(Thumb.END);
1223+
expect(mockAdapter.emitChangeEvent).toHaveBeenCalledWith(60, Thumb.END);
1224+
});
1225+
12091226
it('fires `dragStart`/`dragEnd` events across drag interaction', () => {
12101227
const {foundation, mockAdapter} = setUpAndInit({
12111228
valueStart: 20,

0 commit comments

Comments
 (0)