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

Commit 3fc3ab5

Browse files
Tester798abhiomkar
authored andcommitted
fix(slider): Visual bug when slider value is displayed as "-0"
Co-authored-by: Abhinay Omkar <[email protected]>
1 parent 7f5e0c2 commit 3fc3ab5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/mdc-slider/foundation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
467467
} else if (value > max) {
468468
value = max;
469469
}
470+
value = value || 0; // coerce -0 to 0
470471
this.value_ = value;
471472
this.adapter_.setAttribute(strings.ARIA_VALUENOW, String(this.value_));
472473
this.updateUIForCurrentValue_();

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,31 @@ describe('MDCSliderFoundation - pointer events', () => {
390390

391391
expect(mockAdapter.notifyChange).toHaveBeenCalled();
392392
});
393+
394+
it(`on body ${
395+
moveEvt} discrete slider avoids "-0" pin value marker`,
396+
() => {
397+
const {foundation, mockAdapter, rootHandlers, bodyHandlers} =
398+
setupTest();
399+
400+
mockAdapter.computeBoundingRect.and.returnValue({left: 0, width: 100});
401+
mockAdapter.hasClass.withArgs(cssClasses.IS_DISCRETE)
402+
.and.returnValue(true);
403+
foundation.init();
404+
foundation.setMin(-50);
405+
foundation.setMax(50);
406+
jasmine.clock().tick(1);
407+
408+
// Simulate barely moving the pointer to the left of "0"
409+
rootHandlers[downEvt](clientXObj(50));
410+
bodyHandlers[moveEvt]({
411+
preventDefault: () => {},
412+
...clientXObj(49.9),
413+
});
414+
jasmine.clock().tick(1);
415+
416+
const stringValue = mockAdapter.setMarkerValue.calls.mostRecent().args[0].toLocaleString();
417+
expect(stringValue).toEqual('0');
418+
});
393419
}
394420
});

0 commit comments

Comments
 (0)