Skip to content

Fix/time tooltip overflow #8530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(time-tooltip): component overflow
  • Loading branch information
amtins committed Dec 15, 2023
commit 72b0c279aa51a494ccf7159dbbc5393242a9f3b1
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