mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(click): do not retarget <a> to the parent <label> (#31368)
Fixes #31359.
This commit is contained in:
parent
f6972c1e23
commit
ac90a47b73
@ -478,7 +478,7 @@ export class InjectedScript {
|
|||||||
element = element.closest('button, [role=button], [role=checkbox], [role=radio]') || element;
|
element = element.closest('button, [role=button], [role=checkbox], [role=radio]') || element;
|
||||||
}
|
}
|
||||||
if (behavior === 'follow-label') {
|
if (behavior === 'follow-label') {
|
||||||
if (!element.matches('input, textarea, button, select, [role=button], [role=checkbox], [role=radio]') &&
|
if (!element.matches('a, input, textarea, button, select, [role=link], [role=button], [role=checkbox], [role=radio]') &&
|
||||||
!(element as any).isContentEditable) {
|
!(element as any).isContentEditable) {
|
||||||
// Go up to the label that might be connected to the input/textarea.
|
// Go up to the label that might be connected to the input/textarea.
|
||||||
element = element.closest('label') || element;
|
element = element.closest('label') || element;
|
||||||
|
@ -377,3 +377,18 @@ it('check retargeting', async ({ page, asset }) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not retarget anchor into parent label', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<label disabled>Text<a href='#' onclick='window.__clicked=1'>Target</a></label>
|
||||||
|
`);
|
||||||
|
await page.locator('a').click();
|
||||||
|
expect(await page.evaluate('window.__clicked')).toBe(1);
|
||||||
|
|
||||||
|
await page.setContent(`
|
||||||
|
<input type="radio" id="input-id" checked disabled />
|
||||||
|
<label for="input-id">Text<a href='#' onclick='window.__clicked=2'>Target</a></label>
|
||||||
|
`);
|
||||||
|
await page.locator('a').click();
|
||||||
|
expect(await page.evaluate('window.__clicked')).toBe(2);
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user