diff --git a/src/components/TopNav/TopNav.test.tsx b/src/components/TopNav/TopNav.test.tsx
index 311aa86..ff3e2a4 100644
--- a/src/components/TopNav/TopNav.test.tsx
+++ b/src/components/TopNav/TopNav.test.tsx
@@ -183,6 +183,25 @@ describe('TopNavItem', () => {
expect(link).toHaveAttribute('tabindex', '-1');
});
+ it('drops the href, target, and rel of a disabled item', () => {
+ render(
+
+
+ ,
+ );
+
+ const link = screen.getByRole('link', {name: /Admin/});
+ expect(link).not.toHaveAttribute('href');
+ expect(link).not.toHaveAttribute('target');
+ expect(link).not.toHaveAttribute('rel');
+ });
+
it('prevents navigation when disabled', () => {
render(
diff --git a/src/components/TopNav/TopNavItem.tsx b/src/components/TopNav/TopNavItem.tsx
index 73e9dfb..8feecb8 100644
--- a/src/components/TopNav/TopNavItem.tsx
+++ b/src/components/TopNav/TopNavItem.tsx
@@ -150,15 +150,15 @@ export function TopNavItem({
as={as}
className={className_}
data-testid={dataTestId}
- href={href}
+ href={isDisabled ? undefined : href}
isDisabled={href == null ? isDisabled : undefined}
isLink={href != null}
onClick={handleClick}
ref={ref}
- rel={href != null ? linkRel : undefined}
+ rel={href != null && !isDisabled ? linkRel : undefined}
style={style}
tabIndex={href != null && isDisabled ? -1 : undefined}
- target={href != null ? target : undefined}>
+ target={href != null && !isDisabled ? target : undefined}>
{content}
{opensInNewTab && !isIconOnly ? (
<>