diff --git a/components/dictation-language.tsx b/components/dictation-language.tsx index 5f6528b..eeec821 100644 --- a/components/dictation-language.tsx +++ b/components/dictation-language.tsx @@ -86,7 +86,12 @@ function DictationLanguagePicker({ preference, disabled }: { >
{ closeOnEscape(event); - if (event.key === "Enter") { event.preventDefault(); event.stopPropagation(); } + if (event.key === "Enter") { + // Empty search results must not submit the composer, but a + // focused option button still needs Enter's native click. + if (event.target instanceof HTMLInputElement) event.preventDefault(); + event.stopPropagation(); + } }}> {error &&
{error}
} { + const f = await fixture(); + await click(trigger()); + const option = byTest("dictation-language-multi"); + option.focus(); + let prevented = false; + await act(async () => { + const event = new window.Event("keydown", { bubbles: true, cancelable: true }); + Object.assign(event, { key: "Enter" }); + option.dispatchEvent(event); + prevented = event.defaultPrevented; + // linkedom does not implement native keyboard activation. Follow the + // browser's default action only if the handler left it uncancelled. + if (!prevented) option.click(); + }); + assert.equal(prevented, false, "focused option Enter must retain its native click"); + assert.deepEqual(f.state.writes, ["multi"]); + assert.equal(menu(), null); + assert.match(trigger().textContent!, /Multilingual/); +}); + test("empty results cannot save; Escape and outside click close the menu without closing settings", async () => { const f = await fixture(); await click(trigger());