Skip to content

Commit 79a11bb

Browse files
fix(web): assistive activation answers an option while text is selected
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6498345 commit 79a11bb

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.browser.test.tsx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,36 @@ it("answers an option with Space on keyup, once per press, and not after focus l
236236
expect(modifiedEnter.defaultPrevented).toBe(false);
237237
expect(onToggleOption).toHaveBeenCalledTimes(2);
238238
});
239+
240+
it("ignores a pointer click that ends a text selection but still answers assistive activation", async () => {
241+
const onToggleOption = vi.fn();
242+
await using screen = await render(
243+
<ComposerPendingUserInputPanel
244+
pendingUserInputs={[
245+
{ ...prompt, questions: [{ ...prompt.questions[0]!, multiSelect: true }] },
246+
]}
247+
cwd={undefined}
248+
threadRef={threadRef}
249+
respondingRequestIds={[]}
250+
answers={{}}
251+
questionIndex={0}
252+
onToggleOption={onToggleOption}
253+
onAdvance={() => {}}
254+
onDismiss={() => {}}
255+
/>,
256+
);
257+
const option = screen.getByRole("button", { name: /Incremental/ }).element() as HTMLElement;
258+
const range = document.createRange();
259+
range.selectNodeContents(option);
260+
window.getSelection()!.removeAllRanges();
261+
window.getSelection()!.addRange(range);
262+
const click = (detail: number) =>
263+
act(() => {
264+
option.dispatchEvent(new MouseEvent("click", { detail, bubbles: true }));
265+
});
266+
267+
await click(1);
268+
expect(onToggleOption).not.toHaveBeenCalled();
269+
await click(0);
270+
expect(onToggleOption).toHaveBeenCalledTimes(1);
271+
});

‎apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,10 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
289289
aria-disabled={disabled || isResponding}
290290
onClick={(event) => {
291291
// A drag that selected text in the option ends in a click; it must not answer.
292+
// Assistive technology activates with detail 0 and still answers.
292293
const selection = window.getSelection();
293294
if (
295+
event.detail > 0 &&
294296
selection &&
295297
!selection.isCollapsed &&
296298
selection.containsNode(event.currentTarget, true)

0 commit comments

Comments
 (0)