• Resolved Jason Wong

    (@eljkmw)


    I’ve added a search form to the BB menu by add_filter wp_nav_menu_items. The noticed when the BB menu is viewed in mobile, I cannot input any keyword into the search form as the dropdown menu will automatically retract itself.

    Is there any way to prevent this from happening when the search form is in focus?
    Please advise. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ben Carlo

    (@hinampaksh)

    Hey @eljkmw,

    Thanks for posting!

    Can you send us a note via the form below(General Inquiry) and we’ll take it from there? 🙂
    https://www.wpbeaverbuilder.com/contact/

    You can include a link to this thread so we can keep it updated, and you don’t have to repeat the issue.

    Ben

    Thread Starter Jason Wong

    (@eljkmw)

    @hinampaksh,

    I managed to figure it out. Please ignore my submitted General Inquiry, which I recently sent.

    The following is what I implemented to my “custom.js” within my active child theme.

    jQuery(document).ready(function($) {
        /* Prevents mobile menu from closing when input search is focused */
        document.getElementById('menu-item-search').addEventListener('click', function(e) {
            e.stopPropagation(); 
        });
    });

    The ‘menu-item-search’ ID was previously inserted through functions.php, using the snippets below.

    // Add Search via shortcode
    function bb_search_shortcode() {
        ob_start();
        FLTheme::nav_search();
        return ob_get_clean();
    }
    add_shortcode( 'bb_search', 'bb_search_shortcode' );
    
    // Add Search shortcode to Primary Menu
    function bb_add_search_to_primary_menu( $nav, $args ) {
        if ( $args->menu == 'primary' ) {
            $nav .= '<li id="menu-item-search" class="menu-item">' . do_shortcode( '[bb_search]' ) . '</li>';
        }
        return $nav;
    }
    add_filter( 'wp_nav_menu_items', 'bb_add_search_to_primary_menu', 10, 2 );

    I hope this may help someone else. v(^^)v

    Plugin Contributor Ben Carlo

    (@hinampaksh)

    Glad to hear that, @eljkmw! And thanks for taking the time to inform us. 🙂

    Have fun with BB!

    Ben

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Prevent dropdown menu from auto retracting’ is closed to new replies.