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

Function highlightElement

packages/devtools-a11y/src/core/utils/ui.utils.ts:342–386  ·  view source on GitHub ↗
(
  selector: string,
  impact: SeverityThreshold = 'serious',
  options: { showTooltip?: boolean; ruleId?: string } = {},
)

Source from the content-addressed store, hash-verified

340 // Skip elements inside devtools
341 if (isInsideDevtools(el)) {
342 return
343 }
344
345 el.classList.add(HIGHLIGHT_CLASS, `${HIGHLIGHT_CLASS}--${impact}`)
346
347 // Add tooltip to first highlighted element only
348 if (showTooltip && highlightedCount === 0 && ruleId) {
349 const tooltip = createTooltip([{ ruleId, impact }], el)
350 if (tooltip) {
351 document.body.appendChild(tooltip)
352 }
353 }
354
355 highlightedCount++
356 })
357
358 if (highlightedCount > 0) {
359 console.log(
360 `[A11y Overlay] Highlighted ${highlightedCount} element(s) with selector: ${selector}`,
361 )
362 }
363 } catch (error) {
364 console.error('[A11y Overlay] Error highlighting element:', error)
365 }
366}
367
368/**
369 * Highlight all elements with issues.
370 * Shows all issues per element in the tooltip, using the most severe for highlighting.
371 */
372export function highlightAllIssues(
373 issues: Array<A11yIssue>,
374 theme: TanStackDevtoolsTheme = 'dark',
375): void {
376 injectStyles(theme)
377 clearHighlights()
378
379 // Track ALL issues for each selector
380 // Map: selector -> Array<{ ruleId, impact }>
381 const selectorIssues = new Map<string, Array<TooltipIssue>>()
382
383 // Collect all issues per selector
384 for (const issue of issues) {
385 for (const node of issue.nodes) {
386 const selector = node.selector
387 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
388 const impact = issue.impact ?? 'minor'
389

Callers 1

handleIssueClickFunction · 0.90

Calls 3

injectStylesFunction · 0.85
createTooltipFunction · 0.85
isInsideDevtoolsFunction · 0.70

Tested by

no test coverage detected