fix(webui): restore keyboard focus after pointer use (#6735)
* fix(webui): restore focus rings for file and image shortcuts * test(webui): wait for the welcome composer before opening model options
This commit is contained in:
1 parent
341fd37c0c
commit
3e9024ea04
6 files changed
+34
-5
No files matched your search
@@ -7,6 +7,7 @@ import { useFloatingPortal } from "@/components/ui/floating-portal";
|
||||
import { useToast } from "@/components/ui/toast";
|
||||
import { copyTextToClipboard } from "@/lib/clipboard";
|
||||
import { useOverlaySurfaceRef } from "@/lib/dom-overlays";
|
||||
import { markKeyboardFocus } from "@/lib/focus-modality";
|
||||
import type { FileReferenceMetadata, FilePreviewPayload } from "@/lib/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
@@ -104,6 +105,7 @@ export function FileActions({
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) {
|
||||
markKeyboardFocus(event.currentTarget.ownerDocument);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const bounds = event.currentTarget.getBoundingClientRect();
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState, type PointerEvent } from "rea
|
||||
import { Minus, Plus } from "lucide-react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { markKeyboardFocus } from "@/lib/focus-modality";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type Point = { x: number; y: number };
|
||||
@@ -136,6 +137,7 @@ export function ImageViewport({
|
||||
else if (panWithArrows && event.key === "ArrowUp") apply({ ...current, y: current.y + PAN_STEP });
|
||||
else if (panWithArrows && event.key === "ArrowDown") apply({ ...current, y: current.y - PAN_STEP });
|
||||
else return;
|
||||
markKeyboardFocus(event.currentTarget.ownerDocument);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}}>
|
||||
|
||||
@@ -50,6 +50,11 @@ interface InstalledModality {
|
||||
|
||||
const installedDocuments = new WeakMap<Document, InstalledModality>();
|
||||
|
||||
/** Mark a keyboard action handled by a control outside the shared navigation keys. */
|
||||
export function markKeyboardFocus(doc: Document): void {
|
||||
doc.documentElement.dataset.focusModality = "keyboard";
|
||||
}
|
||||
|
||||
/**
|
||||
* Track whether the user is navigating by keyboard or pointer on `html[data-focus-modality]`.
|
||||
*
|
||||
@@ -82,7 +87,7 @@ export function installFocusModality(doc: Document = document): () => void {
|
||||
root.dataset.focusModality = "pointer";
|
||||
};
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (isKeyboardFocusKey(event)) root.dataset.focusModality = "keyboard";
|
||||
if (isKeyboardFocusKey(event)) markKeyboardFocus(doc);
|
||||
};
|
||||
|
||||
doc.addEventListener("pointerdown", setPointer, { capture: true, passive: true });
|
||||
|
||||
Reference in new issue
Block a user