An open source design system that's fully customizable and agent ready
TypeScript
feat(topnav): unified card appearance for mega menu without backdrop overlay (#379)
rubyycheunga0246b5b8cc1
diff --git a/apps/sandbox/src/app/pages/mega-menu/page.tsx b/apps/sandbox/src/app/pages/mega-menu/page.tsxindex 3b50b43560..4beb1ac855 100644--- a/apps/sandbox/src/app/pages/mega-menu/page.tsx+++ b/apps/sandbox/src/app/pages/mega-menu/page.tsx@@ -21,14 +21,21 @@ const styles = stylex.create({position: 'relative',borderRadius: 12,overflow: 'visible',+ backgroundColor: 'var(--color-surface, #fff)',boxShadow: '0 1px 3px rgba(0, 0, 0, 0.08)',- transitionProperty: 'box-shadow',+ transitionProperty: 'border-radius, box-shadow',transitionDuration: '0.2s',+ transitionTimingFunction: 'ease-out',},- // Hide wrapper shadow when mega menu is open so the backdrop's- // unified card shadow takes over seamlessly.+ // When the mega menu opens, the wrapper becomes the top half of the+ // unified card: drop the bottom radius so it flows seamlessly into the+ // panel, and remove the wrapper shadow (the panel provides its own+ // shadow that visually wraps the dropdown area).navWrapperMenuOpen: {- boxShadow: 'none',+ borderBottomLeftRadius: 0,+ borderBottomRightRadius: 0,+ boxShadow:+ '0 -1px 3px rgba(0, 0, 0, 0.06), -1px 0 3px rgba(0, 0, 0, 0.04), 1px 0 3px rgba(0, 0, 0, 0.04)',},});diff --git a/packages/core/src/TopNav/XDSTopNav.test.tsx b/packages/core/src/TopNav/XDSTopNav.test.tsxindex 158381c5da..f3e07bd92d 100644--- a/packages/core/src/TopNav/XDSTopNav.test.tsx+++ b/packages/core/src/TopNav/XDSTopNav.test.tsx@@ -134,7 +134,7 @@ describe('XDSTopNav', () => {expect(ref).toHaveBeenCalledWith(expect.any(HTMLElement));});- it('creates a stacking context on content sections above mega menu backdrop', () => {+ it('does not create a stacking context on nav element', () => {render(<XDSTopNavlabel="Main navigation"@@ -143,14 +143,9 @@ describe('XDSTopNav', () => {/>,);const nav = screen.getByRole('navigation');- // Nav itself should NOT have position: relative (backdrop needs outer wrapper as ancestor)+ // Nav itself should NOT have position: relative — the wrapper provides+ // positioning context for the mega menu panel.expect(nav).not.toHaveStyle({position: 'relative'});- // Content section divs should have position: relative for stacking context- const sections = nav.querySelectorAll(':scope > div');- expect(sections.length).toBeGreaterThanOrEqual(1);- sections.forEach(section => {- expect(section).toHaveStyle({position: 'relative'});- });});});diff --git a/packages/core/src/TopNav/XDSTopNav.tsx b/packages/core/src/TopNav/XDSTopNav.tsxindex 523274a15b..37021ec14c 100644--- a/packages/core/src/TopNav/XDSTopNav.tsx+++ b/packages/core/src/TopNav/XDSTopNav.tsx@@ -44,9 +44,6 @@ const styles = stylex.create({gridTemplateColumns: '1fr auto 1fr',},leftSection: {- // Stacking context above MegaMenu backdrop (z-index: 99)- position: 'relative',- zIndex: 100,display: 'flex',alignItems: 'center',gap: spacingVars['--spacing-4'],@@ -64,24 +61,18 @@ const styles = stylex.create({gap: spacingVars['--spacing-1'],},centerContent: {- position: 'relative',- zIndex: 100,display: 'flex',alignItems: 'center',justifyContent: 'center',gap: spacingVars['--spacing-1'],},rightSection: {- position: 'relative',- zIndex: 100,display: 'flex',alignItems: 'center',justifyContent: 'flex-end',gap: spacingVars['--spacing-2'],},endContent: {- position: 'relative',- zIndex: 100,display: 'flex',alignItems: 'center',gap: spacingVars['--spacing-2'],diff --git a/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx b/packages/core/src/TopNav/XDSTopNavMegaMenu.tsxindex 8438f28f61..815e7790f8 100644--- a/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx+++ b/packages/core/src/TopNav/XDSTopNavMegaMenu.tsx@@ -21,7 +21,6 @@ import {textSizeVars,fontWeightVars,lineHeightVars,- elevationVars,} from '../theme/tokens.stylex';// =============================================================================@@ -79,28 +78,6 @@ const styles = stylex.create({chevronOpen: {transform: 'rotate(180deg)',},- // Backdrop covers the entire positioned ancestor (nav + panel area).- // It provides the unified card appearance: shared shadow, rounded corners,- // and surface background so the nav bar and panel look like one popover.- backdrop: {- position: 'absolute',- top: 0,- left: 0,- right: 0,- bottom: 0,- zIndex: 99,- borderRadius: radiusVars['--radius-container'],- backgroundColor: colorVars['--color-surface'],- boxShadow: elevationVars['--elevation-hover'],- opacity: 0,- transitionProperty: 'opacity',- transitionDuration: '0.2s',- transitionTimingFunction: 'ease-out',- pointerEvents: 'none',- },- backdropOpen: {- opacity: 1,- },panel: {position: 'absolute',top: '100%',@@ -108,11 +85,16 @@ const styles = stylex.create({right: 0,zIndex: 100,backgroundColor: colorVars['--color-surface'],- // No separate shadow or border — the backdrop provides the unified- // card shadow, and the panel flows seamlessly from the nav bar.+ // Top border provides a subtle divider between the nav bar and panel+ // while keeping them visually connected as one card.+ borderTop: `1px solid ${colorVars['--color-divider']}`,+ borderTopLeftRadius: 0,+ borderTopRightRadius: 0,borderBottomLeftRadius: radiusVars['--radius-container'],borderBottomRightRadius: radiusVars['--radius-container'],- boxShadow: elevationVars['--elevation-hover'],+ // Shadow wraps the panel; the wrapper handles the nav bar's card chrome.+ // Together they create a unified card appearance without a backdrop overlay.+ boxShadow: `0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08)`,overflow: 'hidden',opacity: 0,transform: 'translateY(-4px)',@@ -458,12 +440,6 @@ export function XDSTopNavMegaMenu({<ChevronDown /></span></button>- {/* Backdrop: covers the entire positioned ancestor to create a unified- card appearance (shared shadow + rounded corners) for nav + panel */}- <div- aria-hidden="true"- {...stylex.props(styles.backdrop, isOpen && styles.backdropOpen)}- /><divrole="menu"aria-label={label}