Skip to content

Commit

Permalink
fix(time-tooltip): component overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
amtins committed Dec 15, 2023
1 parent b28bf97 commit 72b0c27
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/js/control-bar/progress-control/time-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ class TimeTooltip extends Component {
*/
update(seekBarRect, seekBarPoint, content) {
this.write(content);

const seekBarRectWidth = seekBarRect.width;
const position = seekBarRectWidth * seekBarPoint;
const timeTooltipWidth = parseFloat(Dom.computedStyle(this.el(), 'width'));
const timeTooltipPosition = position + timeTooltipWidth / 2;
const isSeekBarSmallerThanTimeTooltip = seekBarRectWidth < timeTooltipWidth;

// Keeps the component centered if were not reaching the far left/right
// of the seek bar or if the seek bar is smaller than the time tooltip
if (
timeTooltipPosition >= timeTooltipWidth &&
timeTooltipPosition <= seekBarRectWidth &&
this.el().style.length ||
isSeekBarSmallerThanTimeTooltip
) {
this.el().style = '';
return;
}

// Avoid component right overflow
const isOverflowingRight = timeTooltipPosition >= seekBarRectWidth;

if (isOverflowingRight) {
this.el().style.transform = `translateX(calc(50% - ${Math.abs(seekBarRectWidth - timeTooltipPosition)}px))`;
}

// Avoid component left overflow
const isOverflowingLeft = timeTooltipPosition <= timeTooltipWidth;

if (isOverflowingLeft) {
this.el().style.transform = `translateX(calc(50% + ${Math.abs(timeTooltipPosition - timeTooltipWidth)}px))`;
}
}

/**
Expand Down

0 comments on commit 72b0c27

Please sign in to comment.