getAntdSelector function infrastructure exported ✓ 100.0%

Last updated: 2026-03-04T23:21:38.390Z

Metrics

LOC: 10 Complexity: 3 Params: 1 Coverage: 100.0% (4/4 lines, 61x executed)

Signature

getAntdSelector(wrapper: HTMLElement): : string

Summary

Returns a stable CSS selector for an Ant Design wrapper element. Prefers anchoring on a stable inner input id (e.g. "rc_select_0") over a positional CSS path. In React/antd apps, re-renders can change sibling order and invalidate nth-of-type selectors, causing ignored-field checks to silently fail. Using the inner input's id avoids this problem. Priority: 1. wrapper.id → #wrapperId 2. inner input/control id → #innerId 3. CSS path → getUniqueSelector(wrapper) (fallback)

Source Code

export function getAntdSelector(wrapper: HTMLElement): string {
  if (wrapper.id) return `#${CSS.escape(wrapper.id)}`;

  const inner = wrapper.querySelector<HTMLElement>(
    "input[id], textarea[id], [role='combobox'][id], [role='listbox'][id]",
  );
  if (inner?.id) return `#${CSS.escape(inner.id)}`;

  return getUniqueSelector(wrapper);
}

No outgoing dependencies.

Impact (Incoming)

graph LR getAntdSelector["getAntdSelector"] matches["matches"] buildField["buildField"] matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector matches -->|uses| getAntdSelector buildField -->|calls| getAntdSelector style getAntdSelector fill:#dbeafe,stroke:#2563eb,stroke-width:2px click getAntdSelector "707eae1ed4437c8e.html" click matches "697a9d97bb027c9d.html" click buildField "04978f0607436868.html"
SourceType
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls
matches uses
buildField calls