@@ -78,6 +78,7 @@ export const useSubNavContext = () => {
7878}
7979
8080function SubNavProvider ( { children} : { children : React . ReactNode } ) {
81+ const anchoredNavOuterPortalRef = React . useRef < HTMLDivElement > ( null )
8182 const anchoredNavPortalRef = React . useRef < HTMLDivElement > ( null )
8283
8384 const value = useMemo (
@@ -88,7 +89,7 @@ function SubNavProvider({children}: {children: React.ReactNode}) {
8889 )
8990
9091 useEffect ( ( ) => {
91- const menuContainer = anchoredNavPortalRef . current
92+ const menuContainer = anchoredNavOuterPortalRef . current
9293
9394 const observer = new IntersectionObserver (
9495 ( [ entry ] ) => {
@@ -112,7 +113,7 @@ function SubNavProvider({children}: {children: React.ReactNode}) {
112113 < SubNavContext . Provider value = { value } >
113114 { children }
114115
115- < div className = { styles [ 'SubNav__anchor-menu-outer-container' ] } >
116+ < div className = { styles [ 'SubNav__anchor-menu-outer-container' ] } ref = { anchoredNavOuterPortalRef } >
116117 < div className = { clsx ( styles [ 'SubNav__anchor-menu-container' ] ) } ref = { anchoredNavPortalRef } />
117118 </ div >
118119 </ SubNavContext . Provider >
@@ -217,12 +218,11 @@ const _SubNavRoot = memo(({id, children, className, 'data-testid': testId, fullW
217218 { heading : undefined , links : [ ] , action : undefined } ,
218219 )
219220
220- // The values are different types depending on whether a submenu is present
221221 const activeLinklabel =
222222 typeof activeLink ?. props . children === 'string' ? activeLink . props . children : activeLink ?. props . children [ 0 ]
223+
223224 // needed to prevent rendering of anchor subnav inside the narrow <button> element
224225 const MaybeSubNav = activeLink ?. props . children ?. [ 1 ] ?. props ?. variant === 'anchor' && activeLink . props . children ?. [ 1 ]
225-
226226 return (
227227 < div className = { clsx ( styles [ 'SubNav__container' ] , hasAnchoredNav && styles [ 'SubNav__container--with-anchor-nav' ] ) } >
228228 < SubNavProvider >
@@ -241,26 +241,29 @@ const _SubNavRoot = memo(({id, children, className, 'data-testid': testId, fullW
241241 < div ref = { rootRef } className = { styles [ 'SubNav--header-container-outer' ] } >
242242 < div className = { styles [ 'SubNav__header-container' ] } >
243243 { HeadingChild && < div className = { styles [ 'SubNav__heading-container' ] } > { HeadingChild } </ div > }
244- < span role = "separator" className = { styles [ 'SubNav__heading-separator' ] } aria-hidden >
245- < svg
246- xmlns = "http://www.w3.org/2000/svg"
247- width = "8"
248- height = "16"
249- viewBox = "0 0 8 16"
250- fill = "none"
251- aria-hidden
252- >
253- < g clipPath = "url(#clip0_50_1307)" >
254- < path d = "M0 15.2992L5.472 0.701172H7.632L2.16 15.2992H0Z" fill = "currentColor" />
255- </ g >
256- < defs >
257- < clipPath id = "clip0_50_1307" >
258- < rect width = "7.632" height = "14.598" transform = "translate(0 0.701172)" />
259- </ clipPath >
260- </ defs >
261- </ svg >
262- </ span >
263- { activeLink && activeLinklabel && ! isLarge && (
244+ { activeLinklabel && (
245+ < span role = "separator" className = { styles [ 'SubNav__heading-separator' ] } aria-hidden >
246+ < svg
247+ xmlns = "http://www.w3.org/2000/svg"
248+ width = "8"
249+ height = "16"
250+ viewBox = "0 0 8 16"
251+ fill = "none"
252+ aria-hidden
253+ >
254+ < g clipPath = "url(#clip0_50_1307)" >
255+ < path d = "M0 15.2992L5.472 0.701172H7.632L2.16 15.2992H0Z" fill = "currentColor" />
256+ </ g >
257+ < defs >
258+ < clipPath id = "clip0_50_1307" >
259+ < rect width = "7.632" height = "14.598" transform = "translate(0 0.701172)" />
260+ </ clipPath >
261+ </ defs >
262+ </ svg >
263+ </ span >
264+ ) }
265+
266+ { ! isLarge && (
264267 < button
265268 className = { clsx (
266269 styles [ 'SubNav__overlay-toggle' ] ,
@@ -271,11 +274,18 @@ const _SubNavRoot = memo(({id, children, className, 'data-testid': testId, fullW
271274 aria-expanded = { isOpenAtNarrow ? 'true' : 'false' }
272275 aria-controls = { idForLinkContainer }
273276 >
274- < span className = "visually-hidden" > Navigation menu. Current page: </ span >
275- < span className = { styles [ 'SubNav__overlay-toggle-content' ] } >
276- < Text as = "span" size = "200" >
277- { activeLinklabel }
278- </ Text >
277+ { activeLinklabel && < span className = "visually-hidden" > Navigation menu. Current page: </ span > }
278+ < span
279+ className = { clsx (
280+ styles [ 'SubNav__overlay-toggle-content' ] ,
281+ ! activeLinklabel && styles [ 'SubNav__overlay-toggle-content--end' ] ,
282+ ) }
283+ >
284+ { activeLinklabel && (
285+ < Text as = "span" size = "200" >
286+ { activeLinklabel }
287+ </ Text >
288+ ) }
279289 { isOpenAtNarrow ? (
280290 < ChevronUpIcon className = { styles [ 'SubNav__overlay-toggle-icon' ] } size = { 24 } />
281291 ) : (
0 commit comments