diff --git a/chatbot/src/App.jsx b/chatbot/src/App.jsx index 0c1daf0fe..103ac7703 100644 --- a/chatbot/src/App.jsx +++ b/chatbot/src/App.jsx @@ -2130,7 +2130,7 @@ export default function App() { e.target.value = ""; }} /> - {chat.executors.length > 1 && !pinnedExecutor ? ( + {chat.executors.length > 1 ? ( { @@ -2142,7 +2142,11 @@ export default function App() { : null, }; })} - value={chat.executor} + value={pinnedExecutor ? pinnedExecutor.id : chat.executor} + disabled={Boolean(pinnedExecutor)} + title={pinnedExecutor + ? `当前对话已绑定 ${pinnedExecutor.label},对话开始后不能切换 CLI;换 CLI 请新建对话` + : undefined} onSelect={(id) => { chat.setExecutor(id); input.current?.focus(); diff --git a/chatbot/src/PermissionPicker.jsx b/chatbot/src/PermissionPicker.jsx index 0a37c8305..b247b5156 100644 --- a/chatbot/src/PermissionPicker.jsx +++ b/chatbot/src/PermissionPicker.jsx @@ -24,14 +24,16 @@ export function rememberApprovalMode(userId, value) { } // `glyph` is a rendered brand mark. Options that only set `icon` keep the Harness icon. -export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes }) { +export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes, disabled = false, title }) { const trigger = useRef(null); const panel = useRef(null); const initialFocus = useRef(null); const callbacks = useRef(null); callbacks.current = { onSelect, onOpenChange }; const identity = `permission-picker-${useId().replaceAll(":", "")}`; - const presence = usePanelPresence(open, 160); + // A disabled picker keeps its current value visible but must never open its menu. + const effectiveOpen = disabled ? false : open; + const presence = usePanelPresence(effectiveOpen, 160); const [position, setPosition] = useState({ top: 0, left: 0, width: 260, maxHeight: 360, placement: "top" }); const current = options.find((mode) => mode.id === value) || options[0]; @@ -65,7 +67,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, }, [presence.mounted, options.length, place]); useEffect(() => { - if (!open || !presence.mounted) return; + if (!effectiveOpen || !presence.mounted) return; const frame = requestAnimationFrame(() => { const items = [...(panel.current?.querySelectorAll('[role="menuitemradio"]') || [])]; const selected = initialFocus.current === "first" ? items[0] : @@ -75,7 +77,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, selected?.focus({ preventScroll: true }); }); return () => cancelAnimationFrame(frame); - }, [open, presence.mounted]); + }, [effectiveOpen, presence.mounted]); useEffect(() => { if (!presence.mounted) return; @@ -99,7 +101,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, }, [presence.mounted, place]); useEffect(() => { - if (!open) return; + if (!effectiveOpen) return; const inside = (target) => trigger.current?.contains(target) || panel.current?.contains(target); const outside = (event) => { if (!inside(event.target)) callbacks.current.onOpenChange(false); @@ -125,13 +127,20 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, parentDocument?.removeEventListener("pointerdown", parentOutside, true); parentDocument?.removeEventListener("focusin", parentOutside, true); }; - }, [open]); + }, [effectiveOpen]); + + // A picker that becomes disabled while its menu is open must close it, so + // re-enabling later cannot reopen a menu the user did not ask for. + useEffect(() => { + if (disabled && open) callbacks.current.onOpenChange(false); + }, [disabled, open]); function close(returnFocus = false) { if (returnFocus) trigger.current?.focus({ preventScroll: true }); callbacks.current.onOpenChange(false); } function choose(id) { + if (disabled) return; callbacks.current.onSelect(id); close(true); } @@ -169,19 +178,22 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, className="permission-selector" data-tone={current.tone} aria-label={label} + aria-disabled={disabled || undefined} aria-haspopup="menu" - aria-expanded={open} + aria-expanded={effectiveOpen} aria-controls={identity} - onClick={() => onOpenChange(!open)} + title={title} + disabled={disabled} + onClick={() => onOpenChange(!effectiveOpen)} onKeyDown={(event) => { if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { - if (open && presence.mounted) keyDown(event); + if (effectiveOpen && presence.mounted) keyDown(event); else { event.preventDefault(); initialFocus.current = ["ArrowUp", "End"].includes(event.key) ? "last" : "first"; onOpenChange(true); } - } else if (open && ["Escape", "Tab"].includes(event.key)) keyDown(event); + } else if (effectiveOpen && ["Escape", "Tab"].includes(event.key)) keyDown(event); }} > {current.glyph ||