@@ -128,6 +128,35 @@ const hideTooltip = () => {
128128 tooltipStyle .value .visibility = ' hidden'
129129}
130130
131+ /**
132+ * Get container bounds for boundary detection
133+ * Works with both regular containers and sidepanel
134+ */
135+ const getContainerBounds = () => {
136+ const container = rootElement as HTMLElement
137+ if (! container || ! container .getBoundingClientRect ) {
138+ // Fallback to window bounds if container is not available
139+ return {
140+ left: 0 ,
141+ right: window .innerWidth ,
142+ top: 0 ,
143+ bottom: window .innerHeight ,
144+ width: window .innerWidth ,
145+ height: window .innerHeight ,
146+ }
147+ }
148+
149+ const containerRect = container .getBoundingClientRect ()
150+ return {
151+ left: containerRect .left ,
152+ right: containerRect .right ,
153+ top: containerRect .top ,
154+ bottom: containerRect .bottom ,
155+ width: containerRect .width ,
156+ height: containerRect .height ,
157+ }
158+ }
159+
131160/**
132161 * Update tooltip position
133162 * @param useEstimatedSize - Whether to use estimated size
@@ -136,6 +165,7 @@ const updateTooltipPosition = (useEstimatedSize = false) => {
136165 if (! triggerRef .value ) return
137166
138167 const triggerRect = triggerRef .value .getBoundingClientRect ()
168+ const containerBounds = getContainerBounds ()
139169
140170 // Get tooltip dimensions
141171 let tooltipWidth: number
@@ -202,23 +232,35 @@ const updateTooltipPosition = (useEstimatedSize = false) => {
202232 break
203233 }
204234
205- // Boundary checks
235+ // Boundary checks based on container bounds
206236 if ([' top' , ' bottom' , ' auto' ].includes (positionToUse )) {
207- if (left < BOUNDARY_PADDING ) left = BOUNDARY_PADDING
208- if (left + tooltipWidth / 2 > window .innerWidth - BOUNDARY_PADDING ) {
209- left = window .innerWidth - tooltipWidth / 2 - BOUNDARY_PADDING
237+ // For top/bottom positions with centered left: left value is center point
238+ const leftEdge = left - tooltipWidth / 2
239+ const rightEdge = left + tooltipWidth / 2
240+
241+ if (leftEdge < containerBounds .left + BOUNDARY_PADDING ) {
242+ left = containerBounds .left + BOUNDARY_PADDING + tooltipWidth / 2
243+ }
244+ if (rightEdge > containerBounds .right - BOUNDARY_PADDING ) {
245+ left = containerBounds .right - BOUNDARY_PADDING - tooltipWidth / 2
210246 }
211247 }
212248 else {
213- if (left < BOUNDARY_PADDING ) left = BOUNDARY_PADDING
214- if (left + tooltipWidth > window .innerWidth - BOUNDARY_PADDING ) {
215- left = window .innerWidth - tooltipWidth - BOUNDARY_PADDING
249+ // For left/right positions: left value is the actual left edge
250+ if (left < containerBounds .left + BOUNDARY_PADDING ) {
251+ left = containerBounds .left + BOUNDARY_PADDING
252+ }
253+ if (left + tooltipWidth > containerBounds .right - BOUNDARY_PADDING ) {
254+ left = containerBounds .right - tooltipWidth - BOUNDARY_PADDING
216255 }
217256 }
218257
219- if (top < BOUNDARY_PADDING ) top = BOUNDARY_PADDING
220- if (top + tooltipHeight > window .innerHeight - BOUNDARY_PADDING ) {
221- top = window .innerHeight - tooltipHeight - BOUNDARY_PADDING
258+ // Vertical boundary checks
259+ if (top < containerBounds .top + BOUNDARY_PADDING ) {
260+ top = containerBounds .top + BOUNDARY_PADDING
261+ }
262+ if (top + tooltipHeight > containerBounds .bottom - BOUNDARY_PADDING ) {
263+ top = containerBounds .bottom - tooltipHeight - BOUNDARY_PADDING
222264 }
223265
224266 tooltipStyle .value = {
0 commit comments