Skip to content

Breadcrumbs.Item with Next.js Link component gives activeClassName warning #2847

Closed
@pveierland

Description

@pveierland

Description

When using Breadcrumbs.Item with Next.js and next/link, the following warning occurs:

Warning: React does not recognize the `activeClassName` prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase `activeclassname` instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Creating an adapted version of Breadcrumbs.Item resolves the issue:

const BreadcrumbsItem = styled.a.attrs(props => ({
    className: classnames(props.selected && SELECTED_CLASS, props.className),
    'aria-current': props.selected ? 'page' : null,
    ...(typeof props.to === 'string' ? { activeClassName: 'selected' } : {}),
}))
...

I'm not sure if this is the desired fix, however it would be good if the issue is resolved, or that my usage is corrected if invalid.

Steps to reproduce

  1. Create a test page using Primer React 35.18.0 + Next.js 13.1.5:
import { Breadcrumbs } from '@primer/react';
import Link from 'next/link';

export default function TestPage() {
    return (
        <Breadcrumbs>
            <Breadcrumbs.Item
                as={Link}
                href={'/target'}
            >
                Target
            </Breadcrumbs.Item>
        </Breadcrumbs>
    );
}

Version

35.18.0

Browser

Firefox

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions