Skip to content

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

TypeScript

fix(topnav): move stacking context to nav sections instead of nav element (#378)

rubyycheung439ffc261c06
diff --git a/packages/core/src/TopNav/XDSTopNav.test.tsx b/packages/core/src/TopNav/XDSTopNav.test.tsx
index 7cd86beaf0..158381c5da 100644
--- a/packages/core/src/TopNav/XDSTopNav.test.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.test.tsx
@@ -134,12 +134,23 @@ describe('XDSTopNav', () => {
expect(ref).toHaveBeenCalledWith(expect.any(HTMLElement));
});
- it('creates a stacking context above mega menu backdrop', () => {
- render(<XDSTopNav label="Main navigation" />);
+ it('creates a stacking context on content sections above mega menu backdrop', () => {
+ render(
+ <XDSTopNav
+ label="Main navigation"
+ startContent={<span>Start</span>}
+ endContent={<span>End</span>}
+ />,
+ );
const nav = screen.getByRole('navigation');
- expect(nav).toHaveStyle({position: 'relative'});
- const zIndex = Number(getComputedStyle(nav).zIndex);
- expect(zIndex).toBeGreaterThanOrEqual(100);
+ // Nav itself should NOT have position: relative (backdrop needs outer wrapper as ancestor)
+ 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.tsx
index f42a1ed862..523274a15b 100644
--- a/packages/core/src/TopNav/XDSTopNav.tsx
+++ b/packages/core/src/TopNav/XDSTopNav.tsx
@@ -27,9 +27,6 @@ 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'],
@@ -47,6 +44,9 @@ 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,18 +64,24 @@ 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'],