Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions webview-ui/src/components/chat/AutoApproveMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
cursor: "pointer",
}}
onClick={toggleExpanded}>
<div onClick={(e) => e.stopPropagation()}>
<div
onClick={(e) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this with keyboard navigation? The click handler on the div wrapper could potentially interfere with keyboard accessibility or screen reader interactions. It might be worth verifying that the checkbox remains fully accessible.

e.stopPropagation()
// If no options are selected, clicking the checkbox area should expand the menu
if (!hasEnabledOptions) {
setIsExpanded(true)
}
}}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested click handlers with stopPropagation() create a somewhat complex event flow. Could we simplify this by having a single click handler that checks both conditions? Something like:

Suggested change
}}>
onClick={(e) => {
e.stopPropagation()
// If no options are selected, clicking the checkbox area should expand the menu
if (!hasEnabledOptions) {
setIsExpanded(true)
} else {
// Handle normal checkbox toggle
const newValue = !(autoApprovalEnabled ?? false)
setAutoApprovalEnabled(newValue)
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
}
}}>

<StandardTooltip
content={!hasEnabledOptions ? t("chat:autoApprove.selectOptionsFirst") : undefined}>
<VSCodeCheckbox
Expand All @@ -202,7 +209,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
setAutoApprovalEnabled(newValue)
vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue })
}
// If no options enabled, do nothing
// If no options enabled, the onClick handler above will expand the menu
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment might be clearer if it mentioned this is the fallback behavior:

Suggested change
// If no options enabled, the onClick handler above will expand the menu
// If no options enabled, the onClick handler above will expand the menu
// (since onChange won't fire for a disabled checkbox)

}}
/>
</StandardTooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("AutoApproveMenu", () => {
expect(screen.getByText("Read-only operations")).toBeInTheDocument()
})

it("should not allow toggling master checkbox when no options are selected", () => {
it("should expand menu when clicking checkbox area with no options selected", async () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultExtensionState,
autoApprovalEnabled: false,
Expand All @@ -124,12 +124,18 @@ describe("AutoApproveMenu", () => {

render(<AutoApproveMenu />)

// Click on the master checkbox
// Click on the checkbox container (since the checkbox itself is disabled)
const masterCheckbox = screen.getByRole("checkbox")
fireEvent.click(masterCheckbox)
const checkboxContainer = masterCheckbox.parentElement
fireEvent.click(checkboxContainer!)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using parentElement without null checking could be fragile. Consider adding a null check or using a more specific selector:

Suggested change
fireEvent.click(checkboxContainer!)
const checkboxContainer = masterCheckbox.parentElement
if (!checkboxContainer) {
throw new Error('Checkbox container not found')
}
fireEvent.click(checkboxContainer)


// Should not send any message since no options are selected
expect(mockPostMessage).not.toHaveBeenCalled()

// But should expand the menu to show options
await waitFor(() => {
expect(screen.getByTestId("always-allow-readonly-toggle")).toBeInTheDocument()
})
})

it("should toggle master checkbox when options are selected", () => {
Expand Down
Loading