diff --git a/.changeset/stupid-bats-end.md b/.changeset/stupid-bats-end.md new file mode 100644 index 00000000000..0ecab62f117 --- /dev/null +++ b/.changeset/stupid-bats-end.md @@ -0,0 +1,5 @@ +--- +'@primer/react': patch +--- + +Stop rendering `activeClassName` when there is no `to` prop is passed for react-router (TabNav, SubNav, BreadCrumb, UnderlineNav v1) diff --git a/src/Breadcrumbs/Breadcrumbs.tsx b/src/Breadcrumbs/Breadcrumbs.tsx index 7f20c870cba..f479d7c04ec 100644 --- a/src/Breadcrumbs/Breadcrumbs.tsx +++ b/src/Breadcrumbs/Breadcrumbs.tsx @@ -59,7 +59,7 @@ type StyledBreadcrumbsItemProps = { } & SxProp const BreadcrumbsItem = styled.a.attrs(props => ({ - activeClassName: typeof props.to === 'string' ? 'selected' : '', + activeClassName: typeof props.to === 'string' ? 'selected' : undefined, className: classnames(props.selected && SELECTED_CLASS, props.className), 'aria-current': props.selected ? 'page' : null, }))` diff --git a/src/SubNav.tsx b/src/SubNav.tsx index 7c38bbc2c53..a8e35279ee7 100644 --- a/src/SubNav.tsx +++ b/src/SubNav.tsx @@ -63,7 +63,7 @@ type StyledSubNavLinkProps = { } & SxProp const SubNavLink = styled.a.attrs(props => ({ - activeClassName: typeof props.to === 'string' ? 'selected' : '', + activeClassName: typeof props.to === 'string' ? 'selected' : undefined, className: classnames(ITEM_CLASS, props.selected && SELECTED_CLASS, props.className), }))` padding-left: ${get('space.3')}; diff --git a/src/TabNav/TabNav.tsx b/src/TabNav/TabNav.tsx index b0fa7373da1..e3d46809af4 100644 --- a/src/TabNav/TabNav.tsx +++ b/src/TabNav/TabNav.tsx @@ -81,7 +81,7 @@ export type TabNavLinkProps = React.DetailedHTMLProps(props => ({ - activeClassName: typeof props.to === 'string' ? 'selected' : '', + activeClassName: typeof props.to === 'string' ? 'selected' : undefined, className: classnames(ITEM_CLASS, props.selected && SELECTED_CLASS, props.className), role: 'tab', 'aria-selected': !!props.selected, diff --git a/src/UnderlineNav.tsx b/src/UnderlineNav.tsx index a4c43803c1c..56721e3f93e 100644 --- a/src/UnderlineNav.tsx +++ b/src/UnderlineNav.tsx @@ -70,7 +70,7 @@ type StyledUnderlineNavLinkProps = { } & SxProp const UnderlineNavLink = styled.a.attrs(props => ({ - activeClassName: typeof props.to === 'string' ? 'selected' : '', + activeClassName: typeof props.to === 'string' ? 'selected' : undefined, className: classnames(ITEM_CLASS, props.selected && SELECTED_CLASS, props.className), }))` padding: ${get('space.3')} ${get('space.2')};