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

Keyboard navigation between several menus

1 Answer 50 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Maxime
Top achievements
Rank 1
Maxime asked on 22 Jun 2020, 02:10 PM

Hello,

I have 3 separate "RadMenu" in my page. I would like to be able to navigate between them.

Is there an easy way to access my first menu (with the assigned keys combination), go to the end of my first menu and instead of going back to the start of my menu, go to the start of my second menu, then my third and then my first.

The only thing I could see right now, would be to assign different keys combinations to each one of them (as it should be) and try to detect the end of each one of my menus to trigger the keys combinations of the next menu.

Is there an easier way?

 

Regards,

Maxime

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 25 Jun 2020, 10:50 AM

Hello Maxime,

You are correct, the keyboard navigation would be unnatural if the focus goes between menus instead of looping within the items. 

Nevertheless, you can subscribe to the keydown event for the .RadMenu elements as demonstrated below and handle the focusing with a custom code.

<script>
    function pageInitHandler() {

        $telerik.$(".RadMenu").on("keydown", function (ev) {
            var menu = ev.target.control;
            var focusedItem = menu.get_focusedItem();
            var rootItemsCount = menu.get_items().get_count();
            // if it is a root item
            if (focusedItem.get_level() == 0) {
                if (ev.keyCode == 37 && focusedItem.get_index() == 0) { // left arrow
                    // select the previous Menu 
                    // optionally cancel the event
                    $telerik.cancelRawEvent(ev);
                }
                else if (ev.keyCode == 39 && focusedItem.get_index() == rootItemsCount - 1) { // right arrow
                    // select the next Menu
                    // optionally cancel the event
                    $telerik.cancelRawEvent(ev);
                }
            }
        })
        // Sys.Application.remove_load(pageInitHandler);
    }
    Sys.Application.add_init(pageInitHandler);
</script>

Regards,
Peter Milchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Menu
Asked by
Maxime
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or