fix: gate auto-focus behavior with preventFocusDisruption experiment

This addresses the focus-stealing behavior on initial load that violates
WCAG 3.2.1 and 3.2.2 accessibility criteria.

Changes:
- ChatTextArea.tsx: autoFocus now respects preventFocusDisruption flag
- ChatView.tsx: didBecomeVisible focus call gated by flag
- ChatView.tsx: useDebounceEffect focus call gated by flag

The fix uses the existing preventFocusDisruption experiment flag which
users can enable in Settings > Experimental to prevent focus disruption.

Closes #10492
This commit is contained in:
Roo Code 2026-01-07 23:08:55 +00:00
parent e3b90fb182
commit 6a315cd7b3
2 changed files with 12 additions and 4 deletions

View file

@ -95,6 +95,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
commands,
cloudUserInfo,
enterBehavior,
experiments,
} = useExtensionState()
// Find the ID and display text for the currently selected API configuration.
@ -1080,7 +1081,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
placeholder={placeholderText}
minRows={3}
maxRows={15}
autoFocus={true}
autoFocus={!experiments?.preventFocusDisruption}
className={cn(
"w-full",
"text-vscode-input-foreground",

View file

@ -96,6 +96,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
cloudIsAuthenticated,
messageQueue = [],
isBrowserSessionActive,
experiments,
} = useExtensionState()
const messagesRef = useRef(messages)
@ -803,7 +804,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
case "action":
switch (message.action!) {
case "didBecomeVisible":
if (!isHidden && !sendingDisabled && !enableButtons) {
if (
!isHidden &&
!sendingDisabled &&
!enableButtons &&
!experiments?.preventFocusDisruption
) {
textAreaRef.current?.focus()
}
break
@ -877,6 +883,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
isHidden,
sendingDisabled,
enableButtons,
experiments?.preventFocusDisruption,
handleChatReset,
handleSendMessage,
handleSetChatBoxMessage,
@ -1003,12 +1010,12 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
useDebounceEffect(
() => {
if (!isHidden && !sendingDisabled && !enableButtons) {
if (!isHidden && !sendingDisabled && !enableButtons && !experiments?.preventFocusDisruption) {
textAreaRef.current?.focus()
}
},
50,
[isHidden, sendingDisabled, enableButtons],
[isHidden, sendingDisabled, enableButtons, experiments?.preventFocusDisruption],
)
useEffect(() => {