Skip to content

Commit

Permalink
fix: text selected while sliding in ipad safari
Browse files Browse the repository at this point in the history
fix #127
  • Loading branch information
sneas committed Nov 26, 2023
1 parent 8d68984 commit bad8ca2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/img-comparison-slider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {
};

private bodyUserSelectStyle = '';
private bodyWebkitUserSelectStyle = '';

private onMouseDown = (e: MouseEvent) => {
if (this.slideOnHover) {
Expand All @@ -255,12 +256,17 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {

this.focus();
this.bodyUserSelectStyle = window.document.body.style.userSelect;
this.bodyWebkitUserSelectStyle =
window.document.body.style.webkitUserSelect;
window.document.body.style.userSelect = 'none';
window.document.body.style.webkitUserSelect = 'none';
};

private onWindowMouseUp = () => {
this.isMouseDown = false;
window.document.body.style.userSelect = this.bodyUserSelectStyle;
window.document.body.style.webkitUserSelect =
this.bodyWebkitUserSelectStyle;
window.removeEventListener('mousemove', this.onMouseMove);
window.removeEventListener('mouseup', this.onWindowMouseUp);
};
Expand Down

0 comments on commit bad8ca2

Please sign in to comment.