fix(input): do not retarget from input/textarea/select to an ancestor button (#6036)
Although such markup is not expected, it happens in the wild. Retargeting in this case in unexpected, so we check/click/etc the control itself.
This commit is contained in:
parent
d71c147af7
commit
8f71f5971b
|
|
@ -330,7 +330,8 @@ export class InjectedScript {
|
||||||
let element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
let element = node.nodeType === Node.ELEMENT_NODE ? node as Element : node.parentElement;
|
||||||
if (!element)
|
if (!element)
|
||||||
return null;
|
return null;
|
||||||
element = element.closest('button, [role=button], [role=checkbox], [role=radio]') || element;
|
if (!element.matches('input, textarea, select'))
|
||||||
|
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('input, textarea, button, select, [role=button], [role=checkbox], [role=radio]') &&
|
||||||
!(element as any).isContentEditable) {
|
!(element as any).isContentEditable) {
|
||||||
|
|
|
||||||
|
|
@ -98,3 +98,11 @@ it('should throw when not a checkbox', async ({page}) => {
|
||||||
const error = await page.check('div').catch(e => e);
|
const error = await page.check('div').catch(e => e);
|
||||||
expect(error.message).toContain('Not a checkbox or radio button');
|
expect(error.message).toContain('Not a checkbox or radio button');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check the box inside a button', async ({page}) => {
|
||||||
|
await page.setContent(`<div role='button'><input type='checkbox'></div>`);
|
||||||
|
await page.check('input');
|
||||||
|
expect(await page.$eval('input', input => input.checked)).toBe(true);
|
||||||
|
expect(await page.isChecked('input')).toBe(true);
|
||||||
|
expect(await (await page.$('input')).isChecked()).toBe(true);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue