Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(topnav): mega menu backdrop no longer covers nav items (#377)

rubyycheung22d5df6f11c9
diff --git a/packages/core/src/TopNav/XDSTopNav.test.tsx b/packages/core/src/TopNav/XDSTopNav.test.tsx
index aeb255f06f..7cd86beaf0 100644
--- a/packages/core/src/TopNav/XDSTopNav.test.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.test.tsx
@@ -133,6 +133,14 @@ describe('XDSTopNav', () => {
render(<XDSTopNav ref={ref} />);
expect(ref).toHaveBeenCalledWith(expect.any(HTMLElement));
});
+
+ it('creates a stacking context above mega menu backdrop', () => {
+ render(<XDSTopNav label="Main navigation" />);
+ const nav = screen.getByRole('navigation');
+ expect(nav).toHaveStyle({position: 'relative'});
+ const zIndex = Number(getComputedStyle(nav).zIndex);
+ expect(zIndex).toBeGreaterThanOrEqual(100);
+ });
});
describe('XDSTopNavTitle', () => {
diff --git a/packages/core/src/TopNav/XDSTopNav.tsx b/packages/core/src/TopNav/XDSTopNav.tsx
index 37021ec14c..f42a1ed862 100644
--- a/packages/core/src/TopNav/XDSTopNav.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.tsx
@@ -27,6 +27,9 @@ import type {StyleXStyles as ThemeStyleXStyles} from '../theme/types';
*/
const styles = stylex.create({
base: {
+ // Creates a stacking context above MegaMenu backdrop (z-index: 99)
+ position: 'relative',
+ zIndex: 100,
alignItems: 'center',
width: '100%',
height: spacingVars['--spacing-12'],