offCanvasMenu icon indicating copy to clipboard operation
offCanvasMenu copied to clipboard

Clicking on content when menu is open should close the menu

Open luksak opened this issue 11 years ago • 9 comments

I think it would be an enhancement, if clicking on content when menu is open would close the menu. This is the known behavior from Facebook. Currently the only way to close the menu is to click on the trigger again.

Optionally swiping could also close and maybe even open the menu. This is also the behavior known from Facebook.

I think providing options for each of these behaviors would be very nice.

luksak avatar Feb 26 '14 11:02 luksak

Thanks, @luksak. I agree that this would be a good idea. I think with the current implementation we ran into some finicky behavior, but I've marked this as something worth revisiting.

In the meantime, you can probably achieve this for specific projects using the show() and hide() methods.

tylersticka avatar Feb 27 '14 01:02 tylersticka

True. I will try my luck with the methods.

luksak avatar Feb 27 '14 11:02 luksak

It's tricky because the only way I've found to test if it is open is with the "open" class, but that gets applied right away. So this code opens the menu then immediately closes it :(.

Is there a better way to test if the menu is open?

    $(document).on('click', '.off-canvas-menu.is-open .inner-wrapper', function(event) {
      event.preventDefault();
      menu.hide();
    });

timkelty avatar Mar 14 '14 18:03 timkelty

@timkelty Definitely seems like something we'd want a callback for, doesn't it? Or an event triggered, or something of that sort.

@mattg What do you think?

tylersticka avatar Mar 18 '14 16:03 tylersticka

@timkelty @tylersticka Why not just do this?

$("#menu").on("click", function(e) {
  e.preventDefault();
  menu.hide();
});

mattg avatar Mar 19 '14 20:03 mattg

@mattg But we want to do the opposite. Click OFF of the nav (.inner-wrapper) to close the nav.

timkelty avatar Mar 20 '14 20:03 timkelty

@timkelty I should read a little closer. So, this is ugly, but it works.

$("#content").on("click", function(e) {
  e.preventDefault();
  if (e.target.id !== "menu-trigger") {
    menu.hide();
  }
});

mattg avatar Mar 20 '14 21:03 mattg

@timkelty This assumes you've wrapped your content in a div and that the menu div is outside that content div.

mattg avatar Mar 20 '14 21:03 mattg

Right, and for what I'm looking for I'd also need a check against `e.target.id !== "menu", since i only want it to close when you click off the menu.

So yes, that works. Thanks for the example!

I guess I thought there would be an easier way given that seems to be a pretty "expected" functionality.

timkelty avatar Mar 20 '14 21:03 timkelty