@@ -8,6 +8,7 @@ import { createInitialUserMessageHandoff } from "../../app/initial-user-message-
88import { t } from "../../i18n/index.ts" ;
99import { showToast } from "../../lib/toast.ts" ;
1010import {
11+ getRenderedModalDialog ,
1112 installDialogPolyfill ,
1213 waitForConfirmDialogActions ,
1314} from "../../test-helpers/modal-dialog.ts" ;
@@ -693,6 +694,62 @@ describe("chat pane initialization", () => {
693694} ) ;
694695
695696describe ( "chat pane keyboard shortcuts" , ( ) => {
697+ it ( "does not steal typing focus from a shadow-root confirmation" , async ( ) => {
698+ const restoreDialogPolyfill = installDialogPolyfill ( ) ;
699+ const { pane } = createTestChatPane ( {
700+ client : createGatewayBrowserClientFixture ( ) ,
701+ sessions : createSessionCapabilityFixture ( ) ,
702+ } ) ;
703+ pane . active = true ;
704+ pane . presented = true ;
705+ const composer = document . createElement ( "div" ) ;
706+ composer . className = "agent-chat__composer-combobox" ;
707+ const textarea = composer . appendChild ( document . createElement ( "textarea" ) ) ;
708+ pane . append ( composer ) ;
709+ const focus = vi . spyOn ( textarea , "focus" ) ;
710+ const container = document . body . appendChild ( document . createElement ( "div" ) ) ;
711+ const modal = container . appendChild ( document . createElement ( "openclaw-modal-dialog" ) ) ;
712+ const cancel = modal . appendChild ( document . createElement ( "button" ) ) ;
713+
714+ try {
715+ const { dialog } = await getRenderedModalDialog ( container ) ;
716+ expect ( dialog . open ) . toBe ( true ) ;
717+ expect ( document . querySelector ( "dialog[open]" ) ) . toBeNull ( ) ;
718+ cancel . addEventListener ( "keydown" , ( event ) => pane . handleDocumentKeydown ( event ) ) ;
719+
720+ cancel . dispatchEvent ( new KeyboardEvent ( "keydown" , { key : "x" , cancelable : true } ) ) ;
721+
722+ expect ( focus ) . not . toHaveBeenCalled ( ) ;
723+ } finally {
724+ container . remove ( ) ;
725+ restoreDialogPolyfill ( ) ;
726+ }
727+ } ) ;
728+
729+ it ( "does not steal typing focus from a light-DOM confirmation" , ( ) => {
730+ const { pane } = createTestChatPane ( {
731+ client : createGatewayBrowserClientFixture ( ) ,
732+ sessions : createSessionCapabilityFixture ( ) ,
733+ } ) ;
734+ pane . active = true ;
735+ pane . presented = true ;
736+ const composer = document . createElement ( "div" ) ;
737+ composer . className = "agent-chat__composer-combobox" ;
738+ const textarea = composer . appendChild ( document . createElement ( "textarea" ) ) ;
739+ pane . append ( composer ) ;
740+ const focus = vi . spyOn ( textarea , "focus" ) ;
741+ const modal = document . body . appendChild ( document . createElement ( "div" ) ) ;
742+ modal . setAttribute ( "aria-modal" , "true" ) ;
743+
744+ try {
745+ pane . handleDocumentKeydown ( new KeyboardEvent ( "keydown" , { key : "x" , cancelable : true } ) ) ;
746+
747+ expect ( focus ) . not . toHaveBeenCalled ( ) ;
748+ } finally {
749+ modal . remove ( ) ;
750+ }
751+ } ) ;
752+
696753 it ( "toggles only the active pane's session workspace" , ( ) => {
697754 const client = createGatewayBrowserClientFixture ( ) ;
698755 const sessions = createSessionCapabilityFixture ( ) ;
0 commit comments