How to configure submenu with full width

Created on 19 November 2021, about 3 years ago
Updated 25 May 2023, over 1 year ago

Thank you for the nice changes to the new branch. 2.0.0-alpha2 is showing submenus have full width by default, but I'm not seeing any options to enable full width when selecting the submenu. Is there a class I should enter in the 'Extra class' field to enable full width? We are trying to replicate what you've done with the Wilson site.

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada chrisck BC, Canada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States todea

    I used the following code to get full width sub-menus. This code was borrowed and modified from the hollyhunt site.
    I'm using tb_megamenu version 2.0.0-alpha3

    global.js in my site's theme
    dynamically sets the menu width and left offset

    /**
     * @file
     * Global utilities.
     *
     */
    (function ($, Drupal) {
    
      'use strict';
    
      Drupal.behaviors.yoursite = {
        attach: function (context, settings) {
    
            // Make submenu full browser width.
            const submenuFullwidthCalc = function () {
              // Get the Mega menu Level 1 sub menu.
              $(".tbm-nav > .level-1 > .tbm-submenu").each(function () {
                // reset to zero so it can be calculated again and again
                $(this).css("left", 0);
                const offsettarget = $("body").offset();
                // The offset of this submenu.
                const offsetthis = $(this)
                  //.parent()
                  .parents( "ul" ) // get parent ul instead
                  .offset();
                // Calculate the offset.
                $(this).css("left", offsettarget.left - offsetthis.left);
    
                // Set the submenu full width.
                $(this).css("width", $("body").width());
              });
            };
    
            $(window).on("load resize", function () {
              submenuFullwidthCalc();
            });
    
        }
    
    
    
      };
    
    })(jQuery, Drupal);
    

    The below is not necessary but helps with formatting to prevent content from stretching to the edges.

    customized tb-megamenu-submenu.html.twig

    <div {{ attributes }}>
      <div class="tb-dropdown-inner">
        {% for row in rows %}
          {{ row }}
        {% endfor %}
      </div>
    </div>
    

    CSS

    .tb-dropdown-inner {
    	max-width: 1278px;
    	margin: auto;
    	padding: 0 45px 28px;
    	min-height: 200px;
    }
    
Production build 0.71.5 2024