Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(capture): keep a selected radio selected while its label is read

davbio9ecb69dbdbdf
diff --git a/src/core/capture/__tests__/element-meta.test.ts b/src/core/capture/__tests__/element-meta.test.ts
index fd6ce48..d9dd23e 100644
--- a/src/core/capture/__tests__/element-meta.test.ts
+++ b/src/core/capture/__tests__/element-meta.test.ts
@@ -47,4 +47,24 @@ describe('extractElementMeta', () => {
expect(meta.ariaLabel).toBe('Copy link');
expect(meta.rect).toEqual({ x: 12, y: 34, width: 100, height: 20 });
});
+
+ it('never attaches a copy of an input to the page, where a checked radio would steal the selection', () => {
+ const option = document.createElement('div');
+ option.setAttribute('role', 'button');
+ option.innerHTML = '<input type="radio" name="size" id="large" checked> Large';
+ document.body.appendChild(option);
+ const attached: Node[] = [];
+ const observer = new MutationObserver(() => {});
+ observer.observe(document.body, { childList: true });
+
+ extractElementMeta(option);
+ extractElementMeta(option.querySelector('input') as HTMLInputElement);
+ for (const record of observer.takeRecords()) attached.push(...record.addedNodes);
+ observer.disconnect();
+
+ expect(attached.length).toBeGreaterThan(0);
+ for (const node of attached) {
+ expect(node instanceof HTMLInputElement || (node as Element).querySelector?.('input')).toBeFalsy();
+ }
+ });
});
diff --git a/src/core/capture/dom/element-meta.ts b/src/core/capture/dom/element-meta.ts
index 5b4ac41..e0d6712 100644
--- a/src/core/capture/dom/element-meta.ts
+++ b/src/core/capture/dom/element-meta.ts
@@ -2,7 +2,9 @@ import { getCssSelector } from 'css-selector-generator';
import type { ElementMeta } from '@/core/guides/types';
function getCleanText(el: HTMLElement): string | null {
+ if (el instanceof HTMLInputElement) return null;
const clone = el.cloneNode(true) as HTMLElement;
+ for (const input of clone.querySelectorAll('input')) input.remove();
clone.style.position = 'absolute';
clone.style.left = '-9999px';
clone.style.pointerEvents = 'none';