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 830d8dc
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 ||

Check warning on line 68 in src/js/control-bar/progress-control/time-tooltip.js

View check run for this annotation

Codecov / codecov/patch

src/js/control-bar/progress-control/time-tooltip.js#L67-L68

Added lines #L67 - L68 were not covered by tests
isSeekBarSmallerThanTimeTooltip
) {
this.el().style = '';

Check warning on line 71 in src/js/control-bar/progress-control/time-tooltip.js

View check run for this annotation

Codecov / codecov/patch

src/js/control-bar/progress-control/time-tooltip.js#L71

Added line #L71 was not covered by tests
return;
}

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

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

Check warning on line 79 in src/js/control-bar/progress-control/time-tooltip.js

View check run for this annotation

Codecov / codecov/patch

src/js/control-bar/progress-control/time-tooltip.js#L79

Added line #L79 was not covered by tests
}

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

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

Check warning on line 86 in src/js/control-bar/progress-control/time-tooltip.js

View check run for this annotation

Codecov / codecov/patch

src/js/control-bar/progress-control/time-tooltip.js#L86

Added line #L86 was not covered by tests
}
}

/**
Expand Down

0 comments on commit 830d8dc

Please sign in to comment.