This is a migrated thread and some comments may be shown as answers.

[Solved] Open menu on click

3 Answers 284 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lucas
Top achievements
Rank 1
Lucas asked on 04 May 2012, 09:01 PM
Hello,

I was wondering if there was anyway to only open a menu on click instead of on hover. We have a menu that is relatively close to some other controls and our users are accidentally seeing the menu when trying to click on something close to the menu. 

I would rather the user have to click on a menu item to open the menu drop down.

If there is a CSS way to do this I am using the Office2010Silver theme.

Any ideas?

Thanks!

-Lucas

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 May 2012, 12:58 PM
Hi Lucas,

You should use the OpenOnClick configuration method to enable this behavior:
Html.Telerik().Menu()
    .Name("menu")
    .OpenOnClick(true)



Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Lucas
Top achievements
Rank 1
answered on 16 May 2012, 02:36 PM
Hi Daniel,

Thanks for your quick response! That worked! 

The only thing I am now seeing is that when my mouse hovers outside of the menu, it doesnt close.

Is there anyone to re-enable this feature? Also I would like the menu to close upon clicking on the menu.

Thanks,
Lucas
0
Daniel
Telerik team
answered on 21 May 2012, 06:26 AM
Hi Lucas,

The described behavior is not supported out of the box but can be achieved with some additional code. Basically, you should:
  1.  Disable the OpenOnClick option.
  2. Bind to the mouseenter event of the top level items and stop the event so that it doesn't reach the Menu handler. You should also add the "t-state-hover" class to the element with class "t-link" to achieve the same look when stopping the event.
  3. Add a handler to the OnSelect client-side event and use the client API to close/open the main items.
For example:
//Menu OnLoad event
function onLoad() {
    $(this).find('> .t-item').mouseenter(function (event) {                   
        $(this).find('> .t-link').addClass('t-state-hover');
        event.stopPropagation();
    });
}
//Menu OnSelect event
function onSelect(e) {
    var $item = $(e.item);
    // if  a top-level item is selected
    if ($item.parent().is('.t-menu')) {
        var menu = $(this).data("tMenu");
        // if there are opened sub-items close the item else open it
        if ($item.find('.t-group:visible').length) {
            menu.close($item);
        }
        else {
            menu.open($item);
        }                  
    }
}

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Menu
Asked by
Lucas
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Lucas
Top achievements
Rank 1
Share this question
or