Skip to content

Commit

Permalink
fix(slider): allow pointer interactions that start at the very begin/…
Browse files Browse the repository at this point in the history
…end to be tracked
  • Loading branch information
Westbrook Johnson authored and Westbrook committed Dec 8, 2020
1 parent 7bf317e commit 28c5ef4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions packages/slider/src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,14 @@ export class Slider extends Focusable {
private renderTrack(): TemplateResult {
return html`
<div
id="controls"
@pointerdown=${this.onTrackPointerDown}
@mousedown=${this.onTrackMouseDown}
>
${this.renderTrackLeft()} ${this.renderRamp()}
${this.renderTicks()} ${this.renderHandle()}
${this.renderTrackRight()}
<div id="controls">
${this.renderTrackLeft()} ${this.renderRamp()}
${this.renderTicks()} ${this.renderHandle()}
${this.renderTrackRight()}
</div>
</div>
`;
}
Expand Down
16 changes: 11 additions & 5 deletions packages/slider/test/slider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,23 @@ describe('Slider', () => {

controls.dispatchEvent(
new PointerEvent('pointerdown', {
clientX: 50,
// account for 8px <body> margin by default
clientX: 9,
pointerId: 4,
bubbles: true,
})
);
controls.dispatchEvent(
new MouseEvent('mousedown', {
clientX: 50,
// account for 8px <body> margin by default
clientX: 9,
bubbles: true,
})
);
await elementUpdated(el);

expect(pointerId).to.equal(4);
expect(el.value).to.equal(1);
expect(el.value).to.equal(0);
});
it('will fallback to `trackMouseDown` on `#controls`', async () => {
const el = await fixture<Slider>(
Expand All @@ -276,12 +280,14 @@ describe('Slider', () => {

controls.dispatchEvent(
new MouseEvent('mousedown', {
clientX: 50,
// account for 8px <body> margin by default
clientX: 9,
bubbles: true,
})
);
await elementUpdated(el);

expect(el.value).to.equal(1);
expect(el.value).to.equal(0);
((el as unknown) as TestableSliderType).supportsPointerEvent = supportsPointerEvent;
});
it('can be disabled', async () => {
Expand Down

0 comments on commit 28c5ef4

Please sign in to comment.