Fix keyboard focus visibility when opening document editor#447
Fix keyboard focus visibility when opening document editor#447
Conversation
Added editor.focus() call in handleMonacoEditorMount to ensure keyboard focus is immediately visible when the document view opens. This addresses WCAG 2.4.3 Focus Order accessibility requirement. Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes an accessibility issue where keyboard focus was not visible when the document editor opened, requiring users to press Tab three times before seeing focus. The fix adds a single line to call editor.focus() immediately after the Monaco editor mounts.
Changes:
- Added
editor.focus()call inhandleMonacoEditorMountto set focus immediately after editor initialization - Added accessibility-focused comments explaining the WCAG 2.4.3 Focus Order requirement
|
@copilot Today, the user is unable to 'escape' the focus of a monaco editor with tab/shift-tab as these keys are being processed to edit documents. Until this issue isn't fixed, we'll set the focus on the first button in the view. here it's "save". next, discuss available options: how can one better support releasing focus by the editor once the user navigates there during the 'tab' navigation. |
Changed focus target from Monaco editor to Save button to address keyboard navigation issue. Monaco captures Tab/Shift-Tab for editing, making it difficult for keyboard users to navigate away from the editor. Setting focus on the toolbar button provides better accessibility until Tab navigation from editor can be improved. Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
Changed focus to the Save button (commit 9970540). Options for releasing focus from Monaco editor:1. Custom keyboard shortcuts (Recommended)Add Escape or Ctrl+Shift+L to move focus from editor to toolbar: editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyL, () => {
saveButtonRef.current?.focus();
});2. Configure Monaco Tab behaviorDisable Tab capture in Monaco options: const monacoOptions = {
...existing options,
tabFocusMode: false, // Allow Tab to move focus out
};Note: Users would use Ctrl+M to toggle tab trap mode. 3. Focus trap with visual indicatorAdd an "Exit Editor" button that appears on focus, similar to code editors:
4. Hybrid approach
I recommend Option 1 + 4: Keep current Tab behavior for editing, add Escape key to exit, and show a subtle hint for discoverability. |
…nnounce exit hint
|
@copilot review recent changes done by me and pushed, I added: Enhanced MonacoEditor Component (MonacoEditor.tsx) onEscapeEditor callback prop - When provided, pressing Escape calls this to move focus outside the editor handleEscapeEditor callback - Moves focus to the Save button when Escape is pressed review the PR description and ensure it matches current implementation. |
Reviewed the implementation. PR description updated to reflect all changes: ✅ MonacoEditor.tsx enhancements:
✅ documentView.tsx updates:
✅ Key accessibility improvements:
The implementation follows Option 1 + 4 from my earlier recommendation: keeps Tab for editing, adds Escape to exit, with screen reader hint for discoverability. |
…f type in ToolbarDocuments
When the document editor opens, keyboard focus was not visible until users pressed Tab three times, violating WCAG 2.4.3 Focus Order.
Changes Made
1. Initial Focus Management
2. Escape Key Exit
onEscapeEditorcallback prop toMonacoEditorcomponent3. Screen Reader Announcement
Announcercomponent for proper screen reader supportTechnical Implementation
Enhanced MonacoEditor Component:
Document View Integration:
Why This Approach?
Monaco editor captures Tab/Shift-Tab keys for document editing (indentation, navigation within the editor), making it difficult for keyboard users to Tab out of the editor. Our solution:
Files Modified
src/webviews/components/MonacoEditor.tsx- Added Escape key support and screen reader announcementsrc/webviews/documentdb/documentView/documentView.tsx- AddedsaveButtonRef,handleEscapeEditorcallback, and initial focus managementsrc/webviews/documentdb/documentView/components/toolbarDocuments.tsx- Added ref prop to Save buttonl10n/bundle.l10n.json- Added localization for "Press Escape to exit editor"Accessibility Compliance
✅ WCAG 2.4.3 Focus Order - Focus is immediately visible and follows logical order
✅ WCAG 2.1.1 Keyboard - All functionality accessible via keyboard (Tab + Escape)
✅ WCAG 4.1.3 Status Messages - Screen reader announces exit hint appropriately
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.