fix(code): keep focus in popovers opened from command center cells#1916
fix(code): keep focus in popovers opened from command center cells#1916VojtechBartos wants to merge 2 commits intomainfrom
Conversation
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/components/CommandCenterGrid.tsx
Line: 10-11
Comment:
**`[tabindex]` missing from focusable selector**
`FOCUSABLE_SELECTOR` doesn't include `[tabindex]`, so custom interactive elements that rely solely on `tabindex="0"` (e.g. a `<div tabindex="0">` acting as a focusable control) won't be caught by the guard. If such an element is the *second* `[tabindex="0"]` node inside a cell, a click on it would still redirect focus to the *first* `[tabindex="0"]` instead. Adding `[tabindex]:not([tabindex="-1"])` to the selector closes that gap defensively.
```suggestion
const FOCUSABLE_SELECTOR =
'button, a, input, textarea, select, [tabindex]:not([tabindex="-1"]), [role="button"], [role="link"], [role="combobox"], [role="menuitem"], [contenteditable="true"], [data-interactive]';
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(code): keep focus in popovers opened..." | Re-trigger Greptile |
| const FOCUSABLE_SELECTOR = | ||
| 'button, a, input, textarea, select, [role="button"], [role="link"], [role="combobox"], [role="menuitem"], [contenteditable="true"], [data-interactive]'; |
There was a problem hiding this comment.
[tabindex] missing from focusable selector
FOCUSABLE_SELECTOR doesn't include [tabindex], so custom interactive elements that rely solely on tabindex="0" (e.g. a <div tabindex="0"> acting as a focusable control) won't be caught by the guard. If such an element is the second [tabindex="0"] node inside a cell, a click on it would still redirect focus to the first [tabindex="0"] instead. Adding [tabindex]:not([tabindex="-1"]) to the selector closes that gap defensively.
| const FOCUSABLE_SELECTOR = | |
| 'button, a, input, textarea, select, [role="button"], [role="link"], [role="combobox"], [role="menuitem"], [contenteditable="true"], [data-interactive]'; | |
| const FOCUSABLE_SELECTOR = | |
| 'button, a, input, textarea, select, [tabindex]:not([tabindex="-1"]), [role="button"], [role="link"], [role="combobox"], [role="menuitem"], [contenteditable="true"], [data-interactive]'; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/command-center/components/CommandCenterGrid.tsx
Line: 10-11
Comment:
**`[tabindex]` missing from focusable selector**
`FOCUSABLE_SELECTOR` doesn't include `[tabindex]`, so custom interactive elements that rely solely on `tabindex="0"` (e.g. a `<div tabindex="0">` acting as a focusable control) won't be caught by the guard. If such an element is the *second* `[tabindex="0"]` node inside a cell, a click on it would still redirect focus to the *first* `[tabindex="0"]` instead. Adding `[tabindex]:not([tabindex="-1"])` to the selector closes that gap defensively.
```suggestion
const FOCUSABLE_SELECTOR =
'button, a, input, textarea, select, [tabindex]:not([tabindex="-1"]), [role="button"], [role="link"], [role="combobox"], [role="menuitem"], [contenteditable="true"], [data-interactive]';
```
How can I resolve this? If you propose a fix, please make it concise.GridCell's onClick redirected focus to the cell's first tab stop on every click, including ones that bubbled in through React's synthetic event system from portaled popovers (BranchSelector, GitHubRepoPicker, etc.). Skip the redirect when the click already lands on a focusable control or bubbled from a target outside the cell's DOM. Generated-By: PostHog Code Task-Id: c9fad25f-633d-4125-af8b-2a6da16e859f
Active cell tracking previously keyed off activeTaskId, so cells without a task (empty or in the new-task flow) never lit up the red border. Track the active cell by index instead, and show the indicator whenever a cell is the active one regardless of whether it has a task. Generated-By: PostHog Code Task-Id: c9fad25f-633d-4125-af8b-2a6da16e859f
96d5377 to
1ef6963
Compare
|
Summary
GridCell'sonClickredirected focus to the cell's first[tabindex='0']element on every click, breaking popovers opened from a TaskInput cell (BranchSelector, GitHubRepoPicker, FolderPicker, WorkspaceModeSelect). React's synthetic events bubble through portals, so clicks inside the popover content reached the grid handler and pulled focus to the cell's workspace mode selector.TaskInputnow also focuses its prompt editor when you click empty space inside a cell. The sharedFOCUSABLE_SELECTORconstant lives in@utils/overlay.activeCellIndexinstead ofactiveTaskId, so empty and creating cells light up too.Showcase
code-focus.mov
Created with PostHog Code