Skip to content

feat(link): polymorphic link support with XDSLinkProvider - #337

Merged
cixzhang merged 1 commit into
mainfrom
navi/feat/polymorphic-link
Feb 25, 2026
Merged

cixzhang merged 1 commit into
mainfrom
navi/feat/polymorphic-link

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Summary

Adds polymorphic link rendering so all linkable XDS components can use framework-specific link components (Next.js <Link>, React Router <Link>, TanStack Router, etc.) instead of hardcoded <a> elements.

Two-layer resolution: as prop (per-component) → XDSLinkProvider context → default <a>.

New API

App-wide provider

import Link from "next/link";

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

Per-component override

<XDSTopNavItem label="Home" href="/" as={CustomLink} />
<XDSLink label="Docs" href="/docs" as={RouterLink}>Docs</XDSLink>

Affected Components

Component Change
XDSLink <a> → LinkComponent (always)
XDSSideNavItem <a> → LinkComponent (href branch only, button unchanged)
XDSTopNavItem <a> → LinkComponent (always)
XDSTab <a> → LinkComponent (href branch only, button unchanged)
XDSBreadcrumbItem <a> → LinkComponent (non-current only, span unchanged)

New Exports

  • XDSLinkProvider — context provider
  • useXDSLinkComponent(as?) — resolution hook
  • XDSLinkComponentType — type alias (ElementType)

Test Plan

  • 23 new unit tests across 6 test files
  • Hook tests: default resolution, as override, provider, nested providers
  • Per-component tests: as prop, provider integration, fallback behavior (button/span preserved)
  • yarn build ✅ | yarn test ✅ (1027 tests) | yarn lint ✅

Demo

Sandbox demo page at /pages/polymorphic-link shows provider, per-component override, and default behavior.

Closes #333


Crafted with care by Navi

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 25, 2026
@github-actions

github-actions Bot commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

Breadcrumbs · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 193B N/A
Lines of Code N/A 262 -
Complexity N/A Medium (13) -
Link · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 581B N/A
Lines of Code N/A 232 -
Complexity N/A Medium (14) -
SideNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 645B N/A
Lines of Code N/A 810 -
Complexity N/A Very High (73) -
TabList · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 383B N/A
Lines of Code N/A 549 -
Complexity N/A High (29) -
TopNav · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A 431B N/A
Lines of Code N/A 471 -
Complexity N/A High (28) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@xds/core 7.9KB 12.9KB 2.0KB

Accessibility Audit

Status: 2 accessibility violation(s) found — 1 serious, 1 moderate.

XDSSideNav - 1 issue(s)
  • 🟠 serious: Ensure links have discernible text
    • Rule: link-name · Affects 1/8 stories · Learn more
    • WCAG: 2.4.4, 4.1.2 (Level A)
XDSTabList - 1 issue(s)
  • 🟡 moderate: Ensure landmarks are unique
    • Rule: landmark-unique · Affects 1/5 stories · Learn more

Component Previews

Includes interactive hover previews as animated GIFs.

XDSBreadcrumbs

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · navigation-xdsbreadcrumbs--default

Two Levels

Screenshot:

Two Levels

View in Storybook · navigation-xdsbreadcrumbs--two-levels

Auto-detect Current

Screenshot:

Auto-detect Current

View in Storybook · navigation-xdsbreadcrumbs--auto-detect-current

Custom Separator

Screenshot:

Custom Separator

View in Storybook · navigation-xdsbreadcrumbs--custom-separator

With Icons

Screenshot:

With Icons

View in Storybook · navigation-xdsbreadcrumbs--with-icons

With On Click

Screenshot:

With On Click

View in Storybook · navigation-xdsbreadcrumbs--with-on-click

Deep Hierarchy

Screenshot:

Deep Hierarchy

View in Storybook · navigation-xdsbreadcrumbs--deep-hierarchy

Supporting Variant

Screenshot:

Supporting Variant

View in Storybook · navigation-xdsbreadcrumbs--supporting-variant

Supporting Variant with Icons

Screenshot:

Supporting Variant with Icons

View in Storybook · navigation-xdsbreadcrumbs--supporting-with-icons

XDSLink

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · core-xdslink--default

Secondary

Screenshot:

Secondary

View in Storybook · core-xdslink--secondary

Primary

Screenshot:

Primary

View in Storybook · core-xdslink--primary

With Underline

Screenshot:

With Underline

View in Storybook · core-xdslink--with-underline

Disabled

Screenshot:

Disabled

View in Storybook · core-xdslink--disabled

External Link

Screenshot:

External Link

View in Storybook · core-xdslink--external-link

With Tooltip

Screenshot:

With Tooltip

View in Storybook · core-xdslink--with-tooltip

Standalone

Screenshot:

Standalone

View in Storybook · core-xdslink--standalone

Inline With Text

Screenshot:

Inline With Text

View in Storybook · core-xdslink--inline-with-text

All Variants

Screenshot:

All Variants

View in Storybook · core-xdslink--all-variants

External Links

Screenshot:

External Links

View in Storybook · core-xdslink--external-links

Links With Tooltips

Screenshot:

Links With Tooltips

View in Storybook · core-xdslink--links-with-tooltips

XDSSideNav

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · navigation-xdssidenav--default

Title Without Icon

Screenshot:

Title Without Icon

View in Storybook · navigation-xdssidenav--title-without-icon

Header with Menu

Screenshot:

Header with Menu

View in Storybook · navigation-xdssidenav--with-header-menu

Suite with Independent Links

Screenshot:

Suite with Independent Links

View in Storybook · navigation-xdssidenav--suite-header

Nested Items

Screenshot:

Nested Items

View in Storybook · navigation-xdssidenav--nested-items

With Footer Icons

Screenshot:

With Footer Icons

View in Storybook · navigation-xdssidenav--with-footer

Disabled Items

Screenshot:

Disabled Items

View in Storybook · navigation-xdssidenav--disabled-item

Hidden Section Header

Screenshot:

Hidden Section Header

View in Storybook · navigation-xdssidenav--hidden-section-header

XDSTabList

Default

Screenshot:

Default

Interaction Preview: (view video)

Default interaction

View in Storybook · navigation-xdstablist--default

With Menu

Screenshot:

With Menu

View in Storybook · navigation-xdstablist--with-menu

Menu With Selected Child

Screenshot:

Menu With Selected Child

View in Storybook · navigation-xdstablist--menu-with-selected-child

Size Variants

Screenshot:

Size Variants

View in Storybook · navigation-xdstablist--size-variants

With Icons

Screenshot:

With Icons

View in Storybook · navigation-xdstablist--with-icons


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

…-component as prop

Adds a provider-based default + per-component `as` prop override so all
linkable XDS components can render as custom link components (Next.js Link,
React Router Link, etc.).

New exports:
- XDSLinkProvider — app-wide default link component
- useXDSLinkComponent — hook for resolution (as > provider > 'a')
- XDSLinkComponentType — type alias

Modified components:
- XDSLink, XDSSideNavItem, XDSTopNavItem, XDSTab, XDSBreadcrumbItem

Closes #333

Co-authored-by: Navi <[email protected]>
@cixzhang
cixzhang force-pushed the navi/feat/polymorphic-link branch from 6d562cf to 528dd1a Compare February 25, 2026 06:04
@cixzhang
cixzhang merged commit afe1a89 into main Feb 25, 2026
8 checks passed
@cixzhang
cixzhang deleted the navi/feat/polymorphic-link branch February 25, 2026 15:29
cixzhang added a commit that referenced this pull request Apr 26, 2026
cixzhang added a commit that referenced this pull request Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: polymorphic link support for nav items and linkable elements

1 participant