MCPcopy Create free account
hub / github.com/TanStack/devtools / createTooltip

Function createTooltip

packages/devtools-a11y/src/core/utils/ui.utils.ts:285–337  ·  view source on GitHub ↗

* Create a tooltip element for issues and position it above the target element

(
  issues: Array<TooltipIssue>,
  targetElement: Element,
)

Source from the content-addressed store, hash-verified

283 tooltip.className = `${TOOLTIP_CLASS} ${TOOLTIP_CLASS}--${mostSevere}`
284
285 // Build tooltip content showing all issues
286 if (sortedIssues.length === 1) {
287 tooltip.textContent = `${SEVERITY_LABELS[mostSevere]}: ${firstIssue.ruleId}`
288 } else {
289 // Multiple issues - show count and list
290 const issueList = sortedIssues
291 .map((issue) => `${SEVERITY_LABELS[issue.impact]}: ${issue.ruleId}`)
292 .join(' | ')
293 tooltip.textContent = `${sortedIssues.length} issues: ${issueList}`
294 }
295
296 // Mark as overlay element so it's excluded from a11y scans
297 tooltip.setAttribute('data-a11y-overlay', 'true')
298
299 // Track this tooltip for scroll updates (need to add before positioning)
300 activeTooltips.set(tooltip, targetElement)
301
302 // Start scroll listener if not already running
303 if (activeTooltips.size === 1) {
304 startScrollListener()
305 }
306
307 // Position the tooltip - will flip below element if above viewport
308 const { top, left } = calculateTooltipPosition(targetElement, tooltip)
309 tooltip.style.top = `${top}px`
310 tooltip.style.left = `${left}px`
311
312 return tooltip
313}
314
315/**
316 * Highlight a single element with the specified severity
317 */
318export function highlightElement(
319 selector: string,
320 impact: SeverityThreshold = 'serious',
321 options: {
322 showTooltip?: boolean
323 ruleId?: string
324 theme?: TanStackDevtoolsTheme
325 } = {},
326): void {
327 const { showTooltip = true, ruleId, theme = 'dark' } = options
328
329 try {
330 injectStyles(theme)
331
332 const elements = document.querySelectorAll(selector)
333 if (elements.length === 0) {
334 console.warn(`[A11y Overlay] No elements found for selector: ${selector}`)
335 return
336 }
337
338 let highlightedCount = 0
339 elements.forEach((el) => {
340 // Skip elements inside devtools

Callers 2

highlightElementFunction · 0.85
highlightAllIssuesFunction · 0.85

Calls 2

startScrollListenerFunction · 0.85
calculateTooltipPositionFunction · 0.85

Tested by

no test coverage detected