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

Commit

Permalink
fix(slider): Visual bug when slider value is displayed as "-0"
Browse files Browse the repository at this point in the history
Co-authored-by: Abhinay Omkar <abhiomkar@gmail.com>
  • Loading branch information
2 people authored and asyncLiz committed Jan 24, 2020
1 parent 7f5e0c2 commit 3fc3ab5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/mdc-slider/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
} else if (value > max) {
value = max;
}
value = value || 0; // coerce -0 to 0
this.value_ = value;
this.adapter_.setAttribute(strings.ARIA_VALUENOW, String(this.value_));
this.updateUIForCurrentValue_();
Expand Down
26 changes: 26 additions & 0 deletions packages/mdc-slider/test/foundation-pointer-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,5 +390,31 @@ describe('MDCSliderFoundation - pointer events', () => {

expect(mockAdapter.notifyChange).toHaveBeenCalled();
});

it(`on body ${
moveEvt} discrete slider avoids "-0" pin value marker`,
() => {
const {foundation, mockAdapter, rootHandlers, bodyHandlers} =
setupTest();

mockAdapter.computeBoundingRect.and.returnValue({left: 0, width: 100});
mockAdapter.hasClass.withArgs(cssClasses.IS_DISCRETE)
.and.returnValue(true);
foundation.init();
foundation.setMin(-50);
foundation.setMax(50);
jasmine.clock().tick(1);

// Simulate barely moving the pointer to the left of "0"
rootHandlers[downEvt](clientXObj(50));
bodyHandlers[moveEvt]({
preventDefault: () => {},
...clientXObj(49.9),
});
jasmine.clock().tick(1);

const stringValue = mockAdapter.setMarkerValue.calls.mostRecent().args[0].toLocaleString();
expect(stringValue).toEqual('0');
});
}
});

0 comments on commit 3fc3ab5

Please sign in to comment.