Skip to content

TreeView Navigation Link - Keyboard Accessibility #3224

Description

@gracepark

Description

Hi there,

I'm on the Docs team here at GitHub, and we're currently using the TreeView Component for navigation links with Next.js in a similar way to this example.

We are using our own NextJS Link Component with TreeView. This has been working great for our use case except for the fact that it's not keyboard accessible. On keyboard press Enter, it does not route to the href as expected as when you click.

The TreeView component has been a great for our sidebar in terms of usability and design and we'd love if it could be keyboard accessible with navigation links.

Steps to reproduce

Given the Next.js example, swap out Link with an a tag:

function TreeLinkItem({id, href, children}) {
const router = useRouter()
const isCurrent = typeof href === 'string' ? router.asPath === href : router.pathname === href.pathname
return (
<a href={href}>
<TreeView.Item id={id} aria-current={isCurrent ? 'page' : false} current={isCurrent}>
{children}
</TreeView.Item>
</a>
)
}

Use tab to focus on the TreeView item and press Enter on your keyboard.
Press Enter and you will not be routed.

Version

v35.2.0

Browser

Chrome

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions