UIPackage

Breadcrumb

React navigation
Edit on GitHub

Hierarchical wayfinding strip that shows a user’s position in a nested page tree. Built from `<BreadcrumbList>` and `<BreadcrumbItem>` primitives so you can drop in custom separators, dropdowns for collapsed parents, and ellipsis for overflow.

Also available for Vue ->

Installation

$ npx shadcn@latest add https://react.uipkge.dev/r/react/breadcrumb.json

Or with the named registry: npx shadcn@latest add @uipkge-react/breadcrumb

Examples

Props

Name Type / Values Default Required
asChild

emitting an <a> — the React equivalent of reka-ui's as-child.

boolean optional

Dependencies

Used by

Files (2)

  • components/ui/breadcrumb/breadcrumb.tsx 3.4 kB
    import * as React from 'react'
    import { Slot } from '@radix-ui/react-slot'
    import { ChevronRight, MoreHorizontal } from 'lucide-react'
    import { cn } from '@/lib/utils'
    
    const Breadcrumb = React.forwardRef<HTMLElement, React.ComponentPropsWithoutRef<'nav'>>(
      ({ className, ...props }, ref) => (
        <nav
          ref={ref}
          aria-label="breadcrumb"
          data-uipkge=""
          data-slot="breadcrumb"
          className={className}
          {...props}
        />
      ),
    )
    Breadcrumb.displayName = 'Breadcrumb'
    
    const BreadcrumbList = React.forwardRef<HTMLOListElement, React.ComponentPropsWithoutRef<'ol'>>(
      ({ className, ...props }, ref) => (
        <ol
          ref={ref}
          data-uipkge=""
          data-slot="breadcrumb-list"
          className={cn('text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5', className)}
          {...props}
        />
      ),
    )
    BreadcrumbList.displayName = 'BreadcrumbList'
    
    const BreadcrumbItem = React.forwardRef<HTMLLIElement, React.ComponentPropsWithoutRef<'li'>>(
      ({ className, ...props }, ref) => (
        <li
          ref={ref}
          data-uipkge=""
          data-slot="breadcrumb-item"
          className={cn('inline-flex items-center gap-1.5', className)}
          {...props}
        />
      ),
    )
    BreadcrumbItem.displayName = 'BreadcrumbItem'
    
    export interface BreadcrumbLinkProps extends React.ComponentPropsWithoutRef<'a'> {
      /** Render the child element as the link (merging props/styles) instead of
       *  emitting an <a> — the React equivalent of reka-ui's as-child. */
      asChild?: boolean
    }
    
    const BreadcrumbLink = React.forwardRef<HTMLAnchorElement, BreadcrumbLinkProps>(
      ({ className, asChild = false, ...props }, ref) => {
        const Comp = asChild ? Slot : 'a'
        return (
          <Comp
            ref={ref}
            data-uipkge=""
            data-slot="breadcrumb-link"
            className={cn(
              'hover:text-foreground focus-visible:outline-ring rounded-sm underline-offset-4 transition-colors duration-200 hover:underline focus-visible:outline-2 focus-visible:outline-offset-2',
              className,
            )}
            {...props}
          />
        )
      },
    )
    BreadcrumbLink.displayName = 'BreadcrumbLink'
    
    const BreadcrumbPage = React.forwardRef<HTMLSpanElement, React.ComponentPropsWithoutRef<'span'>>(
      ({ className, ...props }, ref) => (
        <span
          ref={ref}
          data-uipkge=""
          data-slot="breadcrumb-page"
          aria-current="page"
          className={cn('text-foreground cursor-default font-normal', className)}
          {...props}
        />
      ),
    )
    BreadcrumbPage.displayName = 'BreadcrumbPage'
    
    const BreadcrumbSeparator = ({ children, className, ...props }: React.ComponentPropsWithoutRef<'li'>) => (
      <li
        data-uipkge=""
        data-slot="breadcrumb-separator"
        role="presentation"
        aria-hidden="true"
        className={cn('[&>svg]:size-3.5', className)}
        {...props}
      >
        {children ?? <ChevronRight />}
      </li>
    )
    BreadcrumbSeparator.displayName = 'BreadcrumbSeparator'
    
    const BreadcrumbEllipsis = ({ children, className, ...props }: React.ComponentPropsWithoutRef<'span'>) => (
      <span
        data-uipkge=""
        data-slot="breadcrumb-ellipsis"
        className={cn('flex size-11 items-center justify-center', className)}
        {...props}
      >
        {children ?? <MoreHorizontal className="size-4" aria-hidden="true" />}
        <span className="sr-only">More</span>
      </span>
    )
    BreadcrumbEllipsis.displayName = 'BreadcrumbEllipsis'
    
    export {
      Breadcrumb,
      BreadcrumbList,
      BreadcrumbItem,
      BreadcrumbLink,
      BreadcrumbPage,
      BreadcrumbSeparator,
      BreadcrumbEllipsis,
    }
  • components/ui/breadcrumb/index.ts 0.2 kB
    export {
      Breadcrumb,
      BreadcrumbList,
      BreadcrumbItem,
      BreadcrumbLink,
      BreadcrumbPage,
      BreadcrumbSeparator,
      BreadcrumbEllipsis,
      type BreadcrumbLinkProps,
    } from './breadcrumb'

Raw manifest: https://react.uipkge.dev/r/react/breadcrumb.json