@@ -10,6 +10,7 @@ import {
1010import { t } from "../i18n/index.ts" ;
1111import { EDITOR_IDS , EDITOR_LABELS , type EditorId } from "../lib/editor-links.ts" ;
1212import { OpenClawLightDomElement } from "../lit/openclaw-element.ts" ;
13+ import { DropdownMenuController } from "./dropdown-menu-controller.ts" ;
1314import { icons } from "./icons.ts" ;
1415import { activateMenuShortcut , menuShortcutHint } from "./menu-shortcuts.ts" ;
1516import { promoteToPopoverTopLayer } from "./menu-surface.ts" ;
@@ -83,33 +84,21 @@ class SessionMenu extends OpenClawLightDomElement {
8384 @property ( { attribute : false } ) onAction : ( action : SessionMenuAction ) => void = ( ) => { } ;
8485 @property ( { attribute : false } ) onClose : ( ) => void = ( ) => { } ;
8586 @state ( ) private iconPickerOpen = false ;
87+ readonly menuLifecycle = new DropdownMenuController ( this , {
88+ getTrigger : ( ) => this . trigger ,
89+ onClose : ( ) => this . onClose ( ) ,
90+ onKeydown : ( event ) => activateMenuShortcut ( this , event ) ,
91+ } ) ;
8692
8793 override connectedCallback ( ) {
8894 super . connectedCallback ( ) ;
89- document . addEventListener ( "keydown" , this . handleDocumentKeydown , true ) ;
9095 // Sidebar-hosted menus live inside the nav stacking context (z-index 10),
9196 // which paints below the sidebar resizer divider (z-index 20); promoting
9297 // the menu to the popover top layer keeps app chrome from bleeding
9398 // through it (same pattern as openclaw-native-link-menu).
9499 promoteToPopoverTopLayer ( this ) ;
95100 }
96101
97- override disconnectedCallback ( ) {
98- document . removeEventListener ( "keydown" , this . handleDocumentKeydown , true ) ;
99- super . disconnectedCallback ( ) ;
100- }
101-
102- private readonly handleDocumentKeydown = ( event : KeyboardEvent ) => {
103- if ( event . key === "Escape" ) {
104- event . preventDefault ( ) ;
105- event . stopPropagation ( ) ;
106- this . trigger ?. focus ( ) ;
107- this . onClose ( ) ;
108- return ;
109- }
110- activateMenuShortcut ( this , event ) ;
111- } ;
112-
113102 private runAction ( action : SessionMenuAction ) {
114103 this . onClose ( ) ;
115104 this . onAction ( action ) ;
0 commit comments