diff --git a/src/event/behavior/keypress.ts b/src/event/behavior/keypress.ts index dd417ec3..11b6e541 100644 --- a/src/event/behavior/keypress.ts +++ b/src/event/behavior/keypress.ts @@ -15,9 +15,14 @@ behavior.keypress = (event, target, instance) => { } } else if (isElementType(target, 'input')) { const form = target.form - const submit = form?.querySelector( - 'input[type="submit"], button:not([type]), button[type="submit"]', - ) + const submit = + form?.querySelector( + 'input[type="submit"], button:not([type]), button[type="submit"]', + ) ?? + (form?.id && + document.querySelector( + `input[form="${form.id}"][type="submit"], button[form="${form.id}"]:not([type]), button[form="${form?.id}"][type="submit"]`, + )) if (submit) { return () => instance.dispatchUIEvent(submit, 'click') } else if ( diff --git a/tests/event/behavior/keypress.ts b/tests/event/behavior/keypress.ts index c4007bae..df57ddb1 100644 --- a/tests/event/behavior/keypress.ts +++ b/tests/event/behavior/keypress.ts @@ -127,9 +127,9 @@ cases( cases( 'submit form on [Enter]', async ({html, click, submit}) => { - const {eventWasFired, xpathNode} = render(html, {focus: 'form/*[2]'}) + const {eventWasFired, xpathNode} = render(html, {focus: '//form/*[2]'}) - setupInstance().dispatchUIEvent(xpathNode('form/*[2]'), 'keypress', { + setupInstance().dispatchUIEvent(xpathNode('//form/*[2]'), 'keypress', { key: 'Enter', }) @@ -142,21 +142,51 @@ cases( click: true, submit: true, }, + 'with `` outside the form': { + html: `
`, + click: true, + submit: true, + }, + 'with `` outside the form not linked by id': { + html: ``, + click: false, + submit: false, + }, 'with ``': { html: ``, click: true, submit: true, }, + 'with `` outside the form': { + html: ``, + click: true, + submit: true, + }, 'with ``': { html: ``, click: true, submit: true, }, + 'with `` outside the form': { + html: ``, + click: true, + submit: true, + }, 'with ``': { html: ``, click: false, submit: false, }, + 'with `