Commit 49b7f7506c

49b7f7506c8d5c9f3866809291fcfbbd2846375c

parent: 30e1979adb

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-05-21 02:37 UTC

Fix icon tooltips cut-off issue

Layout: unified · split

docs/.vitepress/theme/Layout.vue +41 −1
@@ -283,6 +283,46 @@ const reloadTakodachi = () => {
283283onMounted(() => {
284284 if (import.meta.env.SSR) return
285285
286 // Icon tooltip: fixed-position popup appended to <body> to escape table overflow clipping
287 const tooltipEl = document.createElement('div')
288 tooltipEl.className = 'icon-tip-popup'
289 document.body.appendChild(tooltipEl)
290
291 const showTooltip = (e: MouseEvent) => {
292 const target = (e.target as HTMLElement).closest('.icon-tip') as HTMLElement | null
293 if (!target) return
294 const tip = target.dataset.tip
295 if (!tip) return
296
297 tooltipEl.textContent = tip
298 tooltipEl.classList.add('visible')
299
300 const rect = target.getBoundingClientRect()
301 const tipWidth = tooltipEl.offsetWidth
302 const tipHeight = tooltipEl.offsetHeight
303 let left = rect.left + rect.width / 2 - tipWidth / 2
304 left = Math.max(8, Math.min(left, window.innerWidth - tipWidth - 8))
305 const top = rect.top - tipHeight - 6
306
307 tooltipEl.style.left = `${left}px`
308 tooltipEl.style.top = `${top}px`
309 }
310
311 const hideTooltip = () => {
312 tooltipEl.classList.remove('visible')
313 }
314
315 document.addEventListener('mouseover', showTooltip)
316 document.addEventListener('mouseout', hideTooltip)
317 document.addEventListener('scroll', hideTooltip, true)
318
319 onUnmounted(() => {
320 document.removeEventListener('mouseover', showTooltip)
321 document.removeEventListener('mouseout', hideTooltip)
322 document.removeEventListener('scroll', hideTooltip, true)
323 tooltipEl.remove()
324 })
325
286326 // Arrow key scrolling + Escape close for sidebars and content
287327 let activeScrollTarget: HTMLElement | Window = window
288328
@@ -487,4 +527,4 @@ onUnmounted(() => {
487527 </span>
488528 </template>
489529 </Layout>
490</template>
530</template>
\ No newline at end of file
docs/.vitepress/theme/styles/style.scss +18 −22
@@ -1471,29 +1471,25 @@ html.reduce-blur-effects {
14711471 display: inline-block;
14721472 vertical-align: -0.125em;
14731473 cursor: help;
1474}
14741475
1475 &::after {
1476 content: attr(data-tip);
1477 position: absolute;
1478 bottom: calc(100% + 6px);
1479 left: 50%;
1480 transform: translateX(-50%);
1481 padding: 4px 8px;
1482 border-radius: 6px;
1483 background: var(--vp-c-bg-elv);
1484 color: var(--vp-c-text-1);
1485 font-size: 12px;
1486 line-height: 1.4;
1487 white-space: nowrap;
1488 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
1489 pointer-events: none;
1490 opacity: 0;
1491 transition: opacity 0.15s;
1492 z-index: 10;
1493 }
1494
1495 &:hover::after,
1496 &:focus::after {
1476/* Fixed-position tooltip rendered into <body> by JS to escape table overflow clipping */
1477.icon-tip-popup {
1478 position: fixed;
1479 padding: 4px 8px;
1480 border-radius: 6px;
1481 background: var(--vp-c-bg-elv);
1482 color: var(--vp-c-text-1);
1483 font-size: 12px;
1484 line-height: 1.4;
1485 white-space: nowrap;
1486 box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
1487 pointer-events: none;
1488 z-index: 9999;
1489 opacity: 0;
1490 transition: opacity 0.15s;
1491
1492 &.visible {
14971493 opacity: 1;
14981494 }
14991495}