🐛 Dismiss focused dictionaries when keyboard focus leaves
This commit is contained in:
parent
1de1d85b14
commit
6c76e5d2ca
@ -3008,6 +3008,7 @@ export function CaptureAnnotationWorkbench({
|
||||
if (item) chooseTemplate(item);
|
||||
}}
|
||||
onClose={closeDescriptionDictionary}
|
||||
onDismiss={() => setShowDictionary(false)}
|
||||
/>
|
||||
) : null}
|
||||
{readOnly && !isQualityReview ? (
|
||||
|
||||
@ -131,6 +131,7 @@ export function SliceNameDictionaryPicker({
|
||||
close();
|
||||
}}
|
||||
onClose={close}
|
||||
onDismiss={() => setOpen(false)}
|
||||
/>
|
||||
) : (
|
||||
open &&
|
||||
|
||||
@ -11,6 +11,7 @@ export function WorkspaceDictionaryPanel({
|
||||
status,
|
||||
onSelect,
|
||||
onClose,
|
||||
onDismiss,
|
||||
}: {
|
||||
title: string;
|
||||
searchLabel: string;
|
||||
@ -19,6 +20,7 @@ export function WorkspaceDictionaryPanel({
|
||||
status?: ReactNode;
|
||||
onSelect: (id: string) => void;
|
||||
onClose: () => void;
|
||||
onDismiss: () => void;
|
||||
}) {
|
||||
const [search, setSearch] = useState("");
|
||||
const [page, setPage] = useState(0);
|
||||
@ -33,6 +35,10 @@ export function WorkspaceDictionaryPanel({
|
||||
aria-label={title}
|
||||
className="workspace-dictionary-panel"
|
||||
onKeyDown={(event) => dictionaryKeyDown(event, onClose)}
|
||||
onBlur={(event) => {
|
||||
// Preserve the caller's selection focus; only explicit return/Esc moves it.
|
||||
if (!event.currentTarget.contains(event.relatedTarget as Node)) onDismiss();
|
||||
}}
|
||||
>
|
||||
<div className="workspace-dictionary-heading">
|
||||
<strong>{title}</strong>
|
||||
|
||||
@ -42,6 +42,7 @@ const open = async (task) => {
|
||||
await page.goto(
|
||||
`http://127.0.0.1:5173/plugins/annotation-qa/workflows/all/work?projectId=project-workspace-layout-acceptance&taskId=${task}`,
|
||||
);
|
||||
await page.getByRole("button", { name: new RegExp(task) }).click();
|
||||
await button("继续工作").click();
|
||||
if (await button("进入专注视图").count()) await button("进入专注视图").click();
|
||||
await page.waitForFunction(
|
||||
@ -101,7 +102,13 @@ try {
|
||||
await dialog.waitFor({ state: "detached" });
|
||||
assert.equal((await read(task)).version, old.version, "dictionary does not save");
|
||||
if (stage === "slice") assert.equal(await page.getByLabel("切片名称:").inputValue(), chosen.trim());
|
||||
else assert.equal(await page.getByRole("textbox", { name: "动作描述", exact: true }).inputValue(), chosen.trim());
|
||||
else {
|
||||
assert.equal(await page.getByRole("textbox", { name: "动作描述", exact: true }).inputValue(), chosen.trim());
|
||||
assert.ok(
|
||||
await editor.evaluate((e) => e === document.activeElement),
|
||||
"template selection retains existing editor focus",
|
||||
);
|
||||
}
|
||||
await bench.focus();
|
||||
await page.keyboard.press("d");
|
||||
await dialog.waitFor();
|
||||
@ -112,6 +119,40 @@ try {
|
||||
await page.waitForFunction(() => !document.querySelector("video").paused);
|
||||
assert.equal(await dialog.count(), 0);
|
||||
await page.keyboard.press("Space");
|
||||
for (const exit of ["Tab", "outside pointer"]) {
|
||||
await bench.focus();
|
||||
await page.keyboard.press("f");
|
||||
await dialog.waitFor();
|
||||
if (exit === "Tab") {
|
||||
await dialog.getByRole("button", { name: "下一页", exact: true }).focus();
|
||||
await page.keyboard.press("Tab");
|
||||
} else {
|
||||
await page
|
||||
.locator("video")
|
||||
.first()
|
||||
.click({ position: { x: 12, y: 12 } });
|
||||
}
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await dialog.count(), 0, `${stage} dictionary exits after ${exit} and one Escape`);
|
||||
assert.ok(
|
||||
await bench.evaluate((e) => e === document.activeElement),
|
||||
"escaped dictionary returns playback keyboard ownership",
|
||||
);
|
||||
await page.keyboard.press("Space");
|
||||
await page.waitForFunction(() => !document.querySelector("video").paused);
|
||||
await page.keyboard.press("Space");
|
||||
assert.deepEqual(await rects(), before, "focus dismissal cannot displace media");
|
||||
assert.equal((await read(task)).version, old.version);
|
||||
assert.equal(writes.length, 0, "focus dismissal does not save or claim");
|
||||
}
|
||||
if (stage === "annotate")
|
||||
assert.equal(
|
||||
await page.getByRole("textbox", { name: "动作描述", exact: true }).inputValue(),
|
||||
chosen.trim(),
|
||||
"focus dismissal preserves the selected unsaved draft",
|
||||
);
|
||||
console.log("PASS dictionary focus escape via Tab/outside pointer, one Escape and Space", stage);
|
||||
if (process.env.ANNOTATION_DICTIONARY_FOCUS_ONLY === "1") continue;
|
||||
// Read the entire long option inside the list, with controls outside its scroll area.
|
||||
await bench.focus();
|
||||
await page.keyboard.press("f");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user