Skip to content

Commit 843e304

Browse files
take the list changes back for underlinenav
1 parent 5f94786 commit 843e304

File tree

2 files changed

+45
-59
lines changed

2 files changed

+45
-59
lines changed

src/UnderlineNav2/UnderlineNav.tsx

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,13 @@ export const UnderlineNav = forwardRef(
175175
// This is the case where the viewport is too narrow to show any list item with the more menu. In this case, we only show the dropdown
176176
const onlyMenuVisible = responsiveProps.items.length === 0
177177

178-
if (__DEV__) {
179-
// Practically, this is not a conditional hook, it is just making sure this hook runs only on DEV not PROD.
180-
// eslint-disable-next-line react-hooks/rules-of-hooks
181-
useEffect(() => {
182-
// Address illegal state where there are multiple items that have `aria-current='page'` attribute
183-
const activeElements = validChildren.filter(child => {
184-
return child.props['aria-current'] !== undefined
185-
})
186-
invariant(activeElements.length <= 1, 'Only one current element is allowed')
187-
invariant(ariaLabel, 'Use the `aria-label` prop to provide an accessible label for assistive technology')
188-
})
189-
}
178+
// Address illegal state where there are multiple items that have `aria-current='page'` attribute
179+
const activeElements = validChildren.filter(child => {
180+
return child.props['aria-current'] !== undefined
181+
})
182+
invariant(activeElements.length <= 1, 'Only one current element is allowed')
183+
// Throw an error if aria-label is not provided
184+
invariant(ariaLabel, 'Use the `aria-label` prop to provide an accessible label for assistive technology')
190185

191186
function getItemsWidth(itemText: string): number {
192187
return noIconChildWidthArray.find(item => item.text === itemText)?.width ?? 0
@@ -310,18 +305,7 @@ export const UnderlineNav = forwardRef(
310305
ref={navRef}
311306
>
312307
<NavigationList sx={ulStyles} ref={listRef} role="list">
313-
{listItems.map(listItem => {
314-
return (
315-
<Box
316-
key={listItem.props.children}
317-
as="li"
318-
sx={{display: 'flex', flexDirection: 'column', alignItems: 'center'}}
319-
>
320-
{listItem}
321-
</Box>
322-
)
323-
})}
324-
308+
{listItems}
325309
{menuItems.length > 0 && (
326310
<MoreMenuListItem ref={moreMenuRef}>
327311
{!onlyMenuVisible && <Box sx={getDividerStyle(theme)}></Box>}

src/UnderlineNav2/UnderlineNavItem.tsx

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -114,43 +114,45 @@ export const UnderlineNavItem = forwardRef(
114114
)
115115

116116
return (
117-
<Link
118-
ref={ref}
119-
as={Component}
120-
href={href}
121-
aria-current={ariaCurrent}
122-
onKeyDown={keyDownHandler}
123-
onClick={clickHandler}
124-
sx={merge<BetterSystemStyleObject>(getLinkStyles(theme, ariaCurrent), sxProp as SxProp)}
125-
{...props}
126-
>
127-
{iconsVisible && Icon && (
128-
<Box as="span" data-component="icon" sx={iconWrapStyles}>
129-
<Icon />
130-
</Box>
131-
)}
132-
{children && (
133-
<Box
134-
as="span"
135-
data-component="text"
136-
data-content={children}
137-
sx={Boolean(ariaCurrent) && ariaCurrent !== 'false' ? {fontWeight: 600} : {}}
138-
>
139-
{children}
140-
</Box>
141-
)}
142-
{loadingCounters ? (
143-
<Box as="span" data-component="counter" sx={counterStyles}>
144-
<LoadingCounter />
145-
</Box>
146-
) : (
147-
counter !== undefined && (
117+
<Box as="li" sx={{display: 'flex', flexDirection: 'column', alignItems: 'center'}}>
118+
<Link
119+
ref={ref}
120+
as={Component}
121+
href={href}
122+
aria-current={ariaCurrent}
123+
onKeyDown={keyDownHandler}
124+
onClick={clickHandler}
125+
sx={merge<BetterSystemStyleObject>(getLinkStyles(theme, ariaCurrent), sxProp as SxProp)}
126+
{...props}
127+
>
128+
{iconsVisible && Icon && (
129+
<Box as="span" data-component="icon" sx={iconWrapStyles}>
130+
<Icon />
131+
</Box>
132+
)}
133+
{children && (
134+
<Box
135+
as="span"
136+
data-component="text"
137+
data-content={children}
138+
sx={Boolean(ariaCurrent) && ariaCurrent !== 'false' ? {fontWeight: 600} : {}}
139+
>
140+
{children}
141+
</Box>
142+
)}
143+
{loadingCounters ? (
148144
<Box as="span" data-component="counter" sx={counterStyles}>
149-
<CounterLabel>{counter}</CounterLabel>
145+
<LoadingCounter />
150146
</Box>
151-
)
152-
)}
153-
</Link>
147+
) : (
148+
counter !== undefined && (
149+
<Box as="span" data-component="counter" sx={counterStyles}>
150+
<CounterLabel>{counter}</CounterLabel>
151+
</Box>
152+
)
153+
)}
154+
</Link>
155+
</Box>
154156
)
155157
},
156158
) as PolymorphicForwardRefComponent<'a', UnderlineNavItemProps>

0 commit comments

Comments
 (0)