@@ -7,32 +7,35 @@ export interface MenuItem {
77}
88
99type MenuState = {
10+ activeElement : HTMLElement | null ;
1011 open : boolean ;
1112 menus : MenuItem [ ] ;
1213 x : number ;
1314 y : number ;
1415} ;
1516
1617export const menuStore = createStore < MenuState > ( {
18+ activeElement : null ,
1719 open : false ,
1820 menus : [ ] ,
1921 x : 0 ,
2022 y : 0 ,
2123} ) ;
2224
23- export function openMenu ( x : number , y : number , menus : MenuItem [ ] ) {
24- updateStore ( menuStore , { open : true , x, y, menus } ) ;
25+ export function openMenu ( activeElement : HTMLElement | null , x : number , y : number , menus : MenuItem [ ] ) {
26+ updateStore ( menuStore , { open : true , x, y, menus, activeElement } ) ;
2527}
2628
27- export function closeMenu ( ) {
29+ export function pointerDownHandle ( ) {
30+ setTimeout ( ( ) => menuStore . activeElement ?. focus ( ) ) ;
2831 updateStore ( menuStore , { open : false } ) ;
2932}
3033
3134@customElement ( 'gem-panel-menu' )
3235@connectStore ( menuStore )
3336export class GemPanelMenuElement extends GemElement {
3437 mounted = ( ) => {
35- this . addEventListener ( 'click ' , closeMenu ) ;
38+ this . addEventListener ( 'pointerdown ' , pointerDownHandle ) ;
3639 } ;
3740
3841 render = ( ) => {
@@ -84,7 +87,7 @@ export class GemPanelMenuElement extends GemElement {
8487 </ style >
8588 < div part ="menu " class ="menu ">
8689 ${ menuStore . menus . map (
87- ( { text, handle } ) => html `< div part ="menu-item " class ="item " @click =${ handle } > ${ text } </ div > ` ,
90+ ( { text, handle } ) => html `< div part ="menu-item " class ="item " @pointerdown =${ handle } > ${ text } </ div > ` ,
8891 ) }
8992 </ div >
9093 ` ;
0 commit comments