Navbars JS behaviour

Mega menu navbar

A navbar that opens on hover and means it: a multi-column panel with column heads, icon links and a gradient discount card — clickable and keyboard-friendly too, with a 140ms grace before closing and Escape to snap it shut.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Hover it, click it, tab into it

The panel opens on hover with a 140ms grace before closing, the trigger toggles it on click, ArrowDown walks the keyboard in and Escape snaps it shut — two link columns and a gradient promo card inside.

One workspace, every rollout

Hover the Product trigger above — the mega panel carries the whole map of the platform, and the promo card never lets a launch go unnoticed.

Ingest3.2M spans/s at p99 under 40ms.
RegionsFrankfurt, Dublin, Singapore, Toronto.
ComplianceSOC 2 Type II, GDPR, HIPAA.

Trigger and promo states

The trigger lights its pill when expanded and the chevron flips; the promo card keeps its glow in both themes.

aria-expanded = true
aria-expanded = false
promo-card

Important props

Important props
Prop Type Default What it does
open-on string 'hover · click · focus' Hover over the zone opens it, click on the trigger toggles it, keyboard focus keeps it alive.
close-grace ms '140' The delay before closing; sweeping the mouse across the bar-panel gap never dismisses the menu.
columns count '2' Link columns; on mobile they stack to one scrollable column.
promo-card node null The gradient card slot at the panel’s end — for the special offer or the launch announcement.

Snippet

{{-- resources/views/components/mega-navbar.blade.php — the hover mega menu --}}
<div class="mgn" x-data="{
    mega: false, closer: null,
    open() { clearTimeout(this.closer); this.mega = true },
    later() { clearTimeout(this.closer); this.closer = setTimeout(() => this.mega = false, 140) },
}" x-on:keydown.escape.window="mega = false">
    <header class="mgn-bar">
        <b class="mgn-brand"><i aria-hidden="true"></i>Meridian</b>
        <nav aria-label="Primary">
            <button type="button" x-bind:aria-expanded="mega" aria-haspopup="true"
                    x-on:click="mega = ! mega" x-on:mouseenter="open()"
                    x-on:keydown.arrow-down.prevent="open(); $nextTick(() => $refs.panel.querySelector('a').focus())">
                Product <i class="mgn-chev" aria-hidden="true">⌄</i>
            </button>
            <a href="#pricing">Pricing</a>
            <a href="#docs">Docs</a>
        </nav>
        <a class="mgn-cta" href="#demo">Book a demo</a>
    </header>

    <div class="mgn-panel" x-ref="panel" x-show="mega" x-cloak
         x-on:mouseenter="open()" x-on:mouseleave="later()"
         x-transition:enter="mgn-in" role="region" aria-label="Product menu">
        <div class="mgn-cols">
            <section>
                <h5>Platform</h5>
                <a href="#dash"><i>▤</i>Dashboards<span>Live architecture</span></a>
                <a href="#alerts"><i>◔</i>Alert routing<span>Follow-the-sun</span></a>
            </section>
            <section>
                <h5>For teams</h5>
                <a href="#analytics"><i>↗</i>Product analytics<span>Funnel-free</span></a>
                <a href="#sso"><i>⛨</i>SSO &amp; SCIM<span>Enterprise ready</span></a>
            </section>
        </div>
        <aside class="mgn-promo">
            <b>Meridian Pro</b>
            <span>30% off annual plans until Oct 31</span>
            <a href="#claim">Claim credit</a>
        </aside>
    </div>
</div>

<style>
.mgn { position: relative; }
.mgn-bar { position: absolute; inset-block-start: 0; inset-inline: 0; z-index: 10;
           display: flex; align-items: center; gap: 1.25rem; padding: .8rem 1.25rem; }
.mgn-panel { position: absolute; inset-block-start: 100%; inset-inline: 1rem; z-index: 9;
             display: grid; grid-template-columns: 1fr 1fr 15rem; gap: 1.25rem; padding: 1.25rem;
             border-radius: 1rem; background: #fff; box-shadow: 0 24px 60px #0f172a26; }
.mgn-chev { transition: rotate .2s; }
[aria-expanded='true'] .mgn-chev { rotate: 180deg; }
.mgn-cols a { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: .5rem;
              border-radius: .6rem; text-decoration: none; }
.mgn-cols a:hover { background: #eef2ff; }
.mgn-promo { border-radius: .9rem; padding: 1rem; color: #fff;
             background: linear-gradient(160deg, #4f46e5, #d946ef); }
</style>
// app/Pages/Overview.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import MegaNavbar from '@/components/MegaNavbar';

export default function Overview() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <MegaNavbar />
      </main>
    </NabuXUIProvider>
  );
}
// MegaNavbar.jsx — hover mega menu with click, keyboard and Escape
import { useEffect, useRef, useState } from 'react';
import '@nabuxai/ui-core/css';

const COLUMNS = [
  { head: 'Platform', links: [
    { icon: '▤', label: 'Dashboards', hint: 'Live architecture' },
    { icon: '◔', label: 'Alert routing', hint: 'Follow-the-sun' },
    { icon: '⧉', label: 'Integrations', hint: '120+ connectors' },
  ]},
  { head: 'For teams', links: [
    { icon: '↗', label: 'Product analytics', hint: 'No funnels required' },
    { icon: '⛨', label: 'SSO & SCIM', hint: 'Enterprise ready' },
    { icon: '⟳', label: 'Release notes', hint: 'Auto-drafted' },
  ]},
];

export default function MegaNavbar() {
  const [mega, setMega] = useState(false);
  const closer = useRef(null);
  const open = () => { clearTimeout(closer.current); setMega(true); };
  const later = () => { clearTimeout(closer.current); closer.current = setTimeout(() => setMega(false), 140); };
  useEffect(() => () => clearTimeout(closer.current), []);
  // Escape snaps the panel shut from anywhere on the page.
  useEffect(() => {
    const onKey = (e) => { if (e.key === 'Escape') setMega(false); };
    window.addEventListener('keydown', onKey);
    return () => window.removeEventListener('keydown', onKey);
  }, []);

  return (
    <>
      <style>{`
        .mgn-zone { position: relative; font: 500 14px/1 Inter, sans-serif; color: #0f172a; }
        .mgn-bar { display: flex; align-items: center; gap: 1.25rem; padding: .8rem 1.25rem; }
        .mgn-bar nav { display: flex; gap: .25rem; margin-inline-start: 1rem; }
        .mgn-trigger { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .75rem;
                       border: 0; background: none; font: inherit; cursor: pointer; }
        .mgn-trigger[aria-expanded='true'] { background: #eef2ff; border-radius: 999px; }
        .mgn-chev { transition: rotate .2s; }
        .mgn-trigger[aria-expanded='true'] .mgn-chev { rotate: 180deg; }
        .mgn-panel { position: absolute; inset-inline: 1rem; inset-block-start: 100%; z-index: 9;
                     display: grid; grid-template-columns: 1fr 1fr 15rem; gap: 1.25rem; padding: 1.25rem;
                     border-radius: 1rem; background: #fff; box-shadow: 0 24px 60px #0f172a26; }
        .mgn-panel[data-open='false'] { display: none; }
        .mgn-cols h5 { margin: 0 0 .5rem; font-size: .72rem; letter-spacing: .08em;
                       text-transform: uppercase; color: #64748b; }
        .mgn-cols a { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: .5rem;
                      border-radius: .6rem; text-decoration: none; color: inherit; }
        .mgn-cols a:hover { background: #eef2ff; }
        .mgn-cols span { grid-column: 2; color: #64748b; font-size: .76rem; }
        .mgn-promo { border-radius: .9rem; padding: 1rem; color: #fff;
                     background: linear-gradient(160deg, #4f46e5, #d946ef); }
        .mgn-promo a { color: #fff; font-weight: 600; }
      `}</style>
      <div className="mgn-zone" onMouseEnter={open} onMouseLeave={later}>
        <header className="mgn-bar">
          <b className="mgn-brand"><i aria-hidden="true">◉</i> Meridian</b>
          <nav aria-label="Primary">
            <button type="button" className="mgn-trigger" aria-haspopup="true"
                    aria-expanded={mega} onClick={() => setMega((m) => !m)}>
              Product <i className="mgn-chev" aria-hidden="true">⌄</i>
            </button>
            <a href="#pricing">Pricing</a>
            <a href="#docs">Docs</a>
          </nav>
          <a className="mgn-cta" href="#demo">Book a demo</a>
        </header>
        <div className="mgn-panel" data-open={mega} role="region" aria-label="Product menu">
          {COLUMNS.map((col) => (
            <section key={col.head}>
              <h5>{col.head}</h5>
              {col.links.map((l) => (
                <a key={l.label} href={`#${l.label}`}>
                  <i aria-hidden="true">{l.icon}</i>{l.label}<span>{l.hint}</span>
                </a>
              ))}
            </section>
          ))}
          <aside className="mgn-promo">
            <b>Meridian Pro</b>
            <p>30% off annual plans until Oct 31.</p>
            <a href="#claim">Claim credit</a>
          </aside>
        </div>
      </div>
    </>
  );
}
<!-- MegaNavbar.vue — hover mega menu with click, keyboard and Escape -->
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import '@nabuxai/ui-core/css';

const COLUMNS = [
  { head: 'Platform', links: [
    { icon: '▤', label: 'Dashboards', hint: 'Live architecture' },
    { icon: '◔', label: 'Alert routing', hint: 'Follow-the-sun' },
    { icon: '⧉', label: 'Integrations', hint: '120+ connectors' },
  ]},
  { head: 'For teams', links: [
    { icon: '↗', label: 'Product analytics', hint: 'No funnels required' },
    { icon: '⛨', label: 'SSO & SCIM', hint: 'Enterprise ready' },
    { icon: '⟳', label: 'Release notes', hint: 'Auto-drafted' },
  ]},
];
const mega = ref(false);
let closer: ReturnType<typeof setTimeout> | undefined;
const open = () => { clearTimeout(closer); mega.value = true; };
const later = () => { clearTimeout(closer); closer = setTimeout(() => (mega.value = false), 140); };
// Escape snaps the panel shut from anywhere on the page.
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') mega.value = false; };
onMounted(() => window.addEventListener('keydown', onKey));
onBeforeUnmount(() => { window.removeEventListener('keydown', onKey); clearTimeout(closer); });
</script>

<template>
  <div class="mgn-zone" @mouseenter="open" @mouseleave="later">
    <header class="mgn-bar">
      <b class="mgn-brand"><i aria-hidden="true">◉</i> Meridian</b>
      <nav aria-label="Primary">
        <button type="button" class="mgn-trigger" aria-haspopup="true"
                :aria-expanded="mega" @click="mega = !mega">
          Product <i class="mgn-chev" aria-hidden="true">⌄</i>
        </button>
        <a href="#pricing">Pricing</a>
        <a href="#docs">Docs</a>
      </nav>
      <a class="mgn-cta" href="#demo">Book a demo</a>
    </header>
    <div class="mgn-panel" :data-open="mega" role="region" aria-label="Product menu">
      <section v-for="col in COLUMNS" :key="col.head">
        <h5>{{ col.head }}</h5>
        <a v-for="l in col.links" :key="l.label" :href="'#' + l.label">
          <i aria-hidden="true">{{ l.icon }}</i>{{ l.label }}<span>{{ l.hint }}</span>
        </a>
      </section>
      <aside class="mgn-promo">
        <b>Meridian Pro</b>
        <p>30% off annual plans until Oct 31.</p>
        <a href="#claim">Claim credit</a>
      </aside>
    </div>
  </div>
</template>

<style scoped>
.mgn-zone { position: relative; font: 500 14px/1 Inter, sans-serif; color: #0f172a; }
.mgn-bar { display: flex; align-items: center; gap: 1.25rem; padding: .8rem 1.25rem; }
.mgn-bar nav { display: flex; gap: .25rem; margin-inline-start: 1rem; }
.mgn-trigger { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .75rem;
               border: 0; background: none; font: inherit; cursor: pointer; }
.mgn-trigger[aria-expanded='true'] { background: #eef2ff; border-radius: 999px; }
.mgn-chev { transition: rotate .2s; }
.mgn-trigger[aria-expanded='true'] .mgn-chev { rotate: 180deg; }
.mgn-panel { position: absolute; inset-inline: 1rem; inset-block-start: 100%; z-index: 9;
             display: grid; grid-template-columns: 1fr 1fr 15rem; gap: 1.25rem; padding: 1.25rem;
             border-radius: 1rem; background: #fff; box-shadow: 0 24px 60px #0f172a26; }
.mgn-panel[data-open='false'] { display: none; }
.mgn-cols h5 { margin: 0 0 .5rem; font-size: .72rem; letter-spacing: .08em;
               text-transform: uppercase; color: #64748b; }
.mgn-cols a { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: .5rem;
              border-radius: .6rem; text-decoration: none; color: inherit; }
.mgn-cols a:hover { background: #eef2ff; }
.mgn-cols span { grid-column: 2; color: #64748b; font-size: .76rem; }
.mgn-promo { border-radius: .9rem; padding: 1rem; color: #fff;
             background: linear-gradient(160deg, #4f46e5, #d946ef); }
.mgn-promo a { color: #fff; font-weight: 600; }
</style>
<!-- MegaNavbar.svelte — hover mega menu with click, keyboard and Escape -->
<script lang="ts">
  import '@nabuxai/ui-core/css';

  const COLUMNS = [
    { head: 'Platform', links: [
      { icon: '▤', label: 'Dashboards', hint: 'Live architecture' },
      { icon: '◔', label: 'Alert routing', hint: 'Follow-the-sun' },
      { icon: '⧉', label: 'Integrations', hint: '120+ connectors' },
    ]},
    { head: 'For teams', links: [
      { icon: '↗', label: 'Product analytics', hint: 'No funnels required' },
      { icon: '⛨', label: 'SSO & SCIM', hint: 'Enterprise ready' },
      { icon: '⟳', label: 'Release notes', hint: 'Auto-drafted' },
    ]},
  ];
  let mega = $state(false);
  let closer: ReturnType<typeof setTimeout> | undefined;
  const open = () => { clearTimeout(closer); mega = true; };
  const later = () => { clearTimeout(closer); closer = setTimeout(() => (mega = false), 140); };
  // Escape snaps the panel shut from anywhere on the page.
  $effect(() => {
    const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') mega = false; };
    window.addEventListener('keydown', onKey);
    return () => { window.removeEventListener('keydown', onKey); clearTimeout(closer); };
  });
</script>

<div class="mgn-zone" onmouseenter={open} onmouseleave={later}>
  <header class="mgn-bar">
    <b class="mgn-brand"><i aria-hidden="true">◉</i> Meridian</b>
    <nav aria-label="Primary">
      <button type="button" class="mgn-trigger" aria-haspopup="true"
              aria-expanded={mega} onclick={() => (mega = !mega)}>
        Product <i class="mgn-chev" aria-hidden="true">⌄</i>
      </button>
      <a href="#pricing">Pricing</a>
      <a href="#docs">Docs</a>
    </nav>
    <a class="mgn-cta" href="#demo">Book a demo</a>
  </header>
  <div class="mgn-panel" data-open={mega} role="region" aria-label="Product menu">
    {#each COLUMNS as col (col.head)}
      <section>
        <h5>{col.head}</h5>
        {#each col.links as l (l.label)}
          <a href={'#' + l.label}>
            <i aria-hidden="true">{l.icon}</i>{l.label}<span>{l.hint}</span>
          </a>
        {/each}
      </section>
    {/each}
    <aside class="mgn-promo">
      <b>Meridian Pro</b>
      <p>30% off annual plans until Oct 31.</p>
      <a href="#claim">Claim credit</a>
    </aside>
  </div>
</div>

<style>
.mgn-zone { position: relative; font: 500 14px/1 Inter, sans-serif; color: #0f172a; }
.mgn-bar { display: flex; align-items: center; gap: 1.25rem; padding: .8rem 1.25rem; }
.mgn-bar nav { display: flex; gap: .25rem; margin-inline-start: 1rem; }
.mgn-trigger { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .75rem;
               border: 0; background: none; font: inherit; cursor: pointer; }
.mgn-trigger[aria-expanded='true'] { background: #eef2ff; border-radius: 999px; }
.mgn-chev { transition: rotate .2s; }
.mgn-trigger[aria-expanded='true'] .mgn-chev { rotate: 180deg; }
.mgn-panel { position: absolute; inset-inline: 1rem; inset-block-start: 100%; z-index: 9;
             display: grid; grid-template-columns: 1fr 1fr 15rem; gap: 1.25rem; padding: 1.25rem;
             border-radius: 1rem; background: #fff; box-shadow: 0 24px 60px #0f172a26; }
.mgn-panel[data-open='false'] { display: none; }
.mgn-cols h5 { margin: 0 0 .5rem; font-size: .72rem; letter-spacing: .08em;
               text-transform: uppercase; color: #64748b; }
.mgn-cols a { display: grid; grid-template-columns: auto 1fr; gap: .2rem .6rem; padding: .5rem;
              border-radius: .6rem; text-decoration: none; color: inherit; }
.mgn-cols a:hover { background: #eef2ff; }
.mgn-cols span { grid-column: 2; color: #64748b; font-size: .76rem; }
.mgn-promo { border-radius: .9rem; padding: 1rem; color: #fff;
             background: linear-gradient(160deg, #4f46e5, #d946ef); }
.mgn-promo a { color: #fff; font-weight: 600; }
</style>