Skip to content

Commit 72b0c27

Browse files
committed
fix(time-tooltip): component overflow
1 parent b28bf97 commit 72b0c27

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ class TimeTooltip extends Component {
5353
*/
5454
update(seekBarRect, seekBarPoint, content) {
5555
this.write(content);
56+
57+
const seekBarRectWidth = seekBarRect.width;
58+
const position = seekBarRectWidth * seekBarPoint;
59+
const timeTooltipWidth = parseFloat(Dom.computedStyle(this.el(), 'width'));
60+
const timeTooltipPosition = position + timeTooltipWidth / 2;
61+
const isSeekBarSmallerThanTimeTooltip = seekBarRectWidth < timeTooltipWidth;
62+
63+
// Keeps the component centered if were not reaching the far left/right
64+
// of the seek bar or if the seek bar is smaller than the time tooltip
65+
if (
66+
timeTooltipPosition >= timeTooltipWidth &&
67+
timeTooltipPosition <= seekBarRectWidth &&
68+
this.el().style.length ||
69+
isSeekBarSmallerThanTimeTooltip
70+
) {
71+
this.el().style = '';
72+
return;
73+
}
74+
75+
// Avoid component right overflow
76+
const isOverflowingRight = timeTooltipPosition >= seekBarRectWidth;
77+
78+
if (isOverflowingRight) {
79+
this.el().style.transform = `translateX(calc(50% - ${Math.abs(seekBarRectWidth - timeTooltipPosition)}px))`;
80+
}
81+
82+
// Avoid component left overflow
83+
const isOverflowingLeft = timeTooltipPosition <= timeTooltipWidth;
84+
85+
if (isOverflowingLeft) {
86+
this.el().style.transform = `translateX(calc(50% + ${Math.abs(timeTooltipPosition - timeTooltipWidth)}px))`;
87+
}
5688
}
5789

5890
/**

0 commit comments

Comments
 (0)