Skip to content

Commit

Permalink
fix: dynamic handle attribute
Browse files Browse the repository at this point in the history
re #99
  • Loading branch information
sneas committed Nov 10, 2023
1 parent 427e697 commit e6c2399
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/img-comparison-slider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const slideAnimationPeriod = 1000 / 60;

export class HTMLImgComparisonSliderElement extends HTMLElement {
private firstElement: HTMLElement;
private secondElement: HTMLElement;
private handleElement: HTMLElement;

private imageWidth: number;
Expand All @@ -60,7 +59,15 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {

private isFocused = false;

public handle = false;
private dragByHandle = false;

public set handle(newValue: any) {
this.dragByHandle = !!newValue;
}

public get handle() {
return this.dragByHandle;
}

public get value() {
return this.exposure;
Expand Down Expand Up @@ -128,7 +135,6 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {
shadowRoot.appendChild(templateElement.content.cloneNode(true));

this.firstElement = shadowRoot.getElementById('first');
this.secondElement = shadowRoot.getElementById('second');
this.handleElement = shadowRoot.getElementById('handle');
}

Expand Down Expand Up @@ -167,7 +173,9 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {
this.addEventListener('touchend', this.onTouchEnd);
this.addEventListener('mousedown', this.onMouseDown);

this.handle = this.hasAttribute('handle');
this.handle = this.hasAttribute('handle')
? this.getAttribute('handle')
: this.dragByHandle;

this.hover = this.hasAttribute('hover')
? this.getAttribute('hover')
Expand Down Expand Up @@ -264,7 +272,7 @@ export class HTMLImgComparisonSliderElement extends HTMLElement {
private hasTouchMoved = false;

private onTouchStart = (e: TouchEvent) => {
if (this.handle && !isElementAffected(this.handleElement, e)) {
if (this.dragByHandle && !isElementAffected(this.handleElement, e)) {
return;
}

Expand Down

0 comments on commit e6c2399

Please sign in to comment.