Skip to content

feat: polymorphic link support for nav items and linkable elements #333

Closed

Description

@cixzhang

Problem

All linkable XDS components currently render hardcoded <a> elements. This means they only support native browser navigation via href — there's no way to use framework-specific link components like Next.js <Link>, React Router <Link>, or TanStack Router <Link>.

This affects:

  • XDSPageNavItem — renders <a> when href is provided
  • XDSTopNavItem — always renders <a>
  • XDSTab — renders <a> when href is provided
  • XDSBreadcrumbItem — renders <a> for non-current items
  • XDSLink — renders <a> directly

Without this, users in Next.js apps get full-page reloads instead of client-side navigation, lose prefetching, and can't integrate with their router's active-route detection.

Proposal

Add a polymorphic rendering mechanism so any linkable element can render as a custom component. Two possible approaches:

Option A: as prop (per-component)

import Link from "next/link";

<XDSPageNavItem label="Dashboard" href="/dashboard" as={Link} />
<XDSTopNavItem label="Home" href="/" as={Link} />
<XDSTab value="home" label="Home" href="/" as={Link} />
<XDSBreadcrumbItem href="/projects" as={Link}>Projects</XDSBreadcrumbItem>
<XDSLink label="Docs" href="/docs" as={Link}>Docs</XDSLink>

Option B: Provider-based (app-wide)

import Link from "next/link";

<XDSLinkProvider component={Link}>
  <App /> {/* All linkable XDS components automatically use Next.js Link */}
</XDSLinkProvider>

Option C: Both

A provider sets the default, and the as prop overrides per-instance. This is what most mature design systems do (Chakra, Mantine, etc.).

Affected Components

Component Current element Has href prop
XDSLink <a> ✅
XDSPageNavItem <a> / <button> ✅
XDSTopNavItem <a> ✅
XDSTab <a> / <button> ✅
XDSBreadcrumbItem <a> ✅
XDSTopNavTitle potentially ❌ (but could)

Design Considerations

  • The as component must receive href, children, ref, className, style, and any ARIA props
  • TypeScript generics needed so props are correctly typed for the target component
  • StyleX compatibility — need to verify stylex.props() output works with framework link components
  • Should work with forwardRef components
  • Next.js <Link> passes href to its child <a>, so the integration pattern may need to account for that

Prior Art

  • Radix UI: asChild with Slot pattern
  • Chakra UI: as prop
  • React Aria: elementType prop
  • Mantine: component prop + polymorphicFactory
  • MUI: component prop + LinkComponent on theme

Activity

  1. added 2 commits that reference this issue on Feb 25, 2026
    6d562cf
    528dd1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions