Preserve native Enter activation on dictation language options

This commit is contained in:
amosblomqvist
2026-10-27 22:01:16 +02:00
parent fbafc5e53a
commit f5a655b2f9
2 changed files with 27 additions and 1 deletions
+6 -1
View File
@@ -86,7 +86,12 @@ function DictationLanguagePicker({ preference, disabled }: {
>
<div onKeyDown={(event) => {
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 && <div role="alert" className="mb-1.5 text-destructive">{error}</div>}
<SearchMenuList
+21
View File
@@ -127,6 +127,27 @@ test("the real picker searches by language, chooses with Arrow/Enter, and restor
assert.match(trigger().textContent!, /Polish/);
});
test("Enter on a focused option preserves native button activation", async () => {
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());