LP1852782 Context menu nagivation and FF repairs
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / share / context-menu / context-menu.directive.ts
index 14de769..2b22c4c 100644 (file)
@@ -52,21 +52,38 @@ export class ContextMenuDirective extends NgbPopover {
             // Only broadcast entry selection to my listeners if I'm
             // hosting the menu where the selection occurred.
 
-            if (this.menu && this.menu.id === this.menuService.activeMenu.id) {
+            if (this.activeMenuIsMe()) {
                 this.menuItemSelected.emit(entry);
+
+                // Item selection via keyboard fails to close the menu.
+                // Force it closed.
+                this.cleanup();
             }
         });
     }
 
-    open() {
+    activeMenuIsMe(): boolean {
+        return (
+            this.menu &&
+            this.menuService.activeMenu &&
+            this.menu.id === this.menuService.activeMenu.id
+        );
+    }
 
-        // In certain scenarios (e.g. right-clicking on another context
-        // menu) an open popover will stay open.  Force it closed here.
+    // Close the active menu
+    cleanup() {
         if (ContextMenuDirective.activeDirective) {
             ContextMenuDirective.activeDirective.close();
             ContextMenuDirective.activeDirective = null;
             this.menuService.activeMenu = null;
         }
+    }
+
+    open() {
+
+        // In certain scenarios (e.g. right-clicking on another context
+        // menu) an open popover will stay open.  Force it closed here.
+        this.cleanup();
 
         if (!this.menuEntries ||
              this.menuEntries.length === 0) {