mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-06 13:45:35 +02:00
Revert "fix: snapshot -i auto-detects dropdown/popover interactive elements (#844)"
This reverts commit 542e7836d0.
This commit is contained in:
+4
-39
@@ -233,12 +233,7 @@ export async function handleSnapshot(
|
||||
output.push(outputLine);
|
||||
}
|
||||
|
||||
// ─── Cursor-interactive scan (-C, or auto with -i) ────────
|
||||
// Auto-enable cursor scan when interactive mode is on — agents asking for
|
||||
// interactive elements should always see clickable non-ARIA items too.
|
||||
if (opts.interactive && !opts.cursorInteractive) {
|
||||
opts.cursorInteractive = true;
|
||||
}
|
||||
// ─── Cursor-interactive scan (-C) ─────────────────────────
|
||||
if (opts.cursorInteractive) {
|
||||
try {
|
||||
const cursorElements = await target.evaluate(() => {
|
||||
@@ -261,37 +256,9 @@ export async function handleSnapshot(
|
||||
const hasTabindex = el.hasAttribute('tabindex') && parseInt(el.getAttribute('tabindex')!, 10) >= 0;
|
||||
const hasRole = el.hasAttribute('role');
|
||||
|
||||
// Check if element is inside a floating container (portal/popover/dropdown)
|
||||
const isInFloating = (() => {
|
||||
let parent: Element | null = el;
|
||||
while (parent && parent !== document.documentElement) {
|
||||
const pStyle = getComputedStyle(parent);
|
||||
const isFloating = (pStyle.position === 'fixed' || pStyle.position === 'absolute') &&
|
||||
parseInt(pStyle.zIndex || '0', 10) >= 10;
|
||||
const hasPortalAttr = parent.hasAttribute('data-floating-ui-portal') ||
|
||||
parent.hasAttribute('data-radix-popper-content-wrapper') ||
|
||||
parent.hasAttribute('data-radix-portal') ||
|
||||
parent.hasAttribute('data-popper-placement') ||
|
||||
parent.getAttribute('role') === 'listbox' ||
|
||||
parent.getAttribute('role') === 'menu';
|
||||
if (isFloating || hasPortalAttr) return true;
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
|
||||
if (!hasCursorPointer && !hasOnclick && !hasTabindex) {
|
||||
// For elements inside floating containers, also check for role="option"/"menuitem"
|
||||
if (isInFloating && hasRole) {
|
||||
const role = el.getAttribute('role');
|
||||
if (role !== 'option' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio') continue;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Skip elements with ARIA roles UNLESS they're inside a floating container
|
||||
// (floating container items may be missed by the accessibility tree)
|
||||
if (hasRole && !isInFloating) continue;
|
||||
if (!hasCursorPointer && !hasOnclick && !hasTabindex) continue;
|
||||
// Skip if it has an ARIA role (likely already captured)
|
||||
if (hasRole) continue;
|
||||
|
||||
// Build deterministic nth-child CSS path
|
||||
const parts: string[] = [];
|
||||
@@ -308,11 +275,9 @@ export async function handleSnapshot(
|
||||
|
||||
const text = (el as HTMLElement).innerText?.trim().slice(0, 80) || el.tagName.toLowerCase();
|
||||
const reasons: string[] = [];
|
||||
if (isInFloating) reasons.push('popover-child');
|
||||
if (hasCursorPointer) reasons.push('cursor:pointer');
|
||||
if (hasOnclick) reasons.push('onclick');
|
||||
if (hasTabindex) reasons.push(`tabindex=${el.getAttribute('tabindex')}`);
|
||||
if (hasRole) reasons.push(`role=${el.getAttribute('role')}`);
|
||||
|
||||
results.push({ selector, text, reason: reasons.join(', ') });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user