Skip to content

Commit

Permalink
fix(slider): response to orientation changes when measuring the bound…
Browse files Browse the repository at this point in the history
…ing box
  • Loading branch information
Westbrook committed Nov 12, 2021
1 parent 94891eb commit c1412f1
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/slider/src/HandleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,42 @@ export class HandleController implements Controller {
return input;
}

protected handleOrientation = (): void => {
this.updateBoundingRect();
};

public hostConnected(): void {
if (!this.observer) {
this.observer = new MutationObserver(this.extractModelFromLightDom);
}
this.observer.observe(this.host, { subtree: true, childList: true });
this.extractModelFromLightDom();
if ('orientation' in screen) {
screen.orientation.addEventListener(
'change',
this.handleOrientation
);
} else {
window.addEventListener(
'orientationchange',
this.handleOrientation
);
}
}

public hostDisconnected(): void {
this.observer.disconnect();
if ('orientation' in screen) {
screen.orientation.removeEventListener(
'change',
this.handleOrientation
);
} else {
window.removeEventListener(
'orientationchange',
this.handleOrientation
);
}
}

public hostUpdate(): void {
Expand Down Expand Up @@ -241,6 +267,8 @@ export class HandleController implements Controller {
delete this.handleRefMap;
}

private _boundingClientRect?: DOMRect;

private get boundingClientRect(): DOMRect {
if (!this._boundingClientRect) {
this._boundingClientRect = this.host.track.getBoundingClientRect();
Expand All @@ -252,8 +280,6 @@ export class HandleController implements Controller {
delete this._boundingClientRect;
}

private _boundingClientRect?: DOMRect;

/**
* Receives an event from a track click and turns it into a drag
* of the active handle
Expand Down

0 comments on commit c1412f1

Please sign in to comment.