Skip to content

Commit

Permalink
fix: slider touch handlers should be passive (microsoft#5692)
Browse files Browse the repository at this point in the history
* passive handlers

* Change files
  • Loading branch information
Stephane Comeau authored Mar 4, 2022
1 parent bdeeb23 commit 0a25cee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "passive handlers",
"packageName": "@microsoft/fast-foundation",
"email": "scomea@microsoft.com",
"dependentChangeType": "patch"
}
13 changes: 8 additions & 5 deletions packages/web-components/fast-foundation/src/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,12 @@ export class Slider extends FormAssociatedSlider implements SliderConfiguration
const eventAction = `${remove ? "remove" : "add"}EventListener`;
this[eventAction]("keydown", this.keypressHandler);
this[eventAction]("mousedown", this.handleMouseDown);
this.thumb[eventAction]("mousedown", this.handleThumbMouseDown);
this.thumb[eventAction]("touchstart", this.handleThumbMouseDown);
this.thumb[eventAction]("mousedown", this.handleThumbMouseDown, {
passive: true,
});
this.thumb[eventAction]("touchstart", this.handleThumbMouseDown, {
passive: true,
});
// removes handlers attached by mousedown handlers
if (remove) {
this.handleMouseDown(null);
Expand Down Expand Up @@ -415,13 +419,12 @@ export class Slider extends FormAssociatedSlider implements SliderConfiguration
if (this.readOnly || this.disabled || event.defaultPrevented) {
return;
}
event.preventDefault();
(event.target as HTMLElement).focus();
}
const eventAction = `${event !== null ? "add" : "remove"}EventListener`;
window[eventAction]("mouseup", this.handleWindowMouseUp);
window[eventAction]("mousemove", this.handleMouseMove);
window[eventAction]("touchmove", this.handleMouseMove);
window[eventAction]("mousemove", this.handleMouseMove, { passive: true });
window[eventAction]("touchmove", this.handleMouseMove, { passive: true });
window[eventAction]("touchend", this.handleWindowMouseUp);
this.isDragging = event !== null;
};
Expand Down

0 comments on commit 0a25cee

Please sign in to comment.