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

Callers 2

highlightElementFunction · 0.85
highlightAllIssuesFunction · 0.85

Calls 2

startScrollListenerFunction · 0.85
calculateTooltipPositionFunction · 0.85

Tested by

no test coverage detected