Preserve native Enter activation on dictation language options
This commit is contained in:
@@ -86,7 +86,12 @@ function DictationLanguagePicker({ preference, disabled }: {
|
|||||||
>
|
>
|
||||||
<div onKeyDown={(event) => {
|
<div onKeyDown={(event) => {
|
||||||
closeOnEscape(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>}
|
{error && <div role="alert" className="mb-1.5 text-destructive">{error}</div>}
|
||||||
<SearchMenuList
|
<SearchMenuList
|
||||||
|
|||||||
@@ -127,6 +127,27 @@ test("the real picker searches by language, chooses with Arrow/Enter, and restor
|
|||||||
assert.match(trigger().textContent!, /Polish/);
|
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 () => {
|
test("empty results cannot save; Escape and outside click close the menu without closing settings", async () => {
|
||||||
const f = await fixture();
|
const f = await fixture();
|
||||||
await click(trigger());
|
await click(trigger());
|
||||||
|
|||||||
Reference in New Issue
Block a user