0

I have a menu that the user can open at any stage. I would like the menu to autohide if the user starts to type anything or executes some action.

The menu is applicable to many pages in my app. Ideally I'd like to execute the code to test if the menu should close whenever the user changes anything in the app. e.g.

if(appController.get('showMenu'){
   appController.set('showMenu', false);  
}  

Any thoughts on a good DRY solution for this?

TrevTheDev
  • 2,616
  • 2
  • 18
  • 36

2 Answers2

0

Have you tried listening for a lose focus event? Just have it set to false when the component loses focus.

Sho'vah
  • 41
  • 5
  • Unfortunately that does not seem like a very DRY solution as I would have to add code to every form and control type to track these changes. Better would be some hook into the ember run loop. – TrevTheDev Mar 17 '14 at 12:04
0

I managed to solve this problem using the solution proposed here and thought I would share it in case someone else has the similar requirement.

Simply execute this code on the page:

    $('html').click(function() {
        App.applicationRoute.send('hideMenu');
    });

This works by capturing every click event on the page and then hiding the menu - events still propagate to the menu as well.

Community
  • 1
  • 1
TrevTheDev
  • 2,616
  • 2
  • 18
  • 36