MCPcopy
hub / github.com/github/docs / Breadcrumbs

Function Breadcrumbs

components/page-header/Breadcrumbs.tsx:17–69  ·  view source on GitHub ↗
({ inHeader }: Props)

Source from the content-addressed store, hash-verified

15}
16
17export const Breadcrumbs = ({ inHeader }: Props) => {
18 const { breadcrumbs } = useMainContext()
19
20 return (
21 /*
22 NOTE: The breadcrumbs class and the nav tag are used by the
23 Lunr search scripts. The a tag generated by the Link is also used.
24 If these change, please also change
25 updating script/search/parse-page-sections-into-records.js.
26 */
27 <nav
28 data-testid={inHeader ? 'breadcrumbs-header' : 'breadcrumbs-in-article'}
29 className={cx('f5 breadcrumbs', styles.breadcrumbs)}
30 aria-label="Breadcrumb"
31 >
32 <ul>
33 {Object.values(breadcrumbs)
34 .filter(Boolean)
35 .map((breadcrumb, i, arr) => {
36 const title = `${breadcrumb.title}`
37 return [
38 !breadcrumb.href ? (
39 <span data-testid="breadcrumb-title" key={title} title={title} className="px-2">
40 {breadcrumb.title}
41 </span>
42 ) : (
43 <li className="d-inline-block" key={title}>
44 <Link
45 data-testid="breadcrumb-link"
46 href={breadcrumb.href}
47 title={title}
48 className={cx(
49 'Link--primary mr-2 color-fg-muted',
50 // Show the last breadcrumb if it's in the header, but not if it's in the article
51 // If there's only 1 breadcrumb, show it
52 !inHeader && i === arr.length - 1 && arr.length !== 1 && 'd-none'
53 )}
54 >
55 {breadcrumb.title}
56 </Link>
57 {i !== arr.length - 1 ? (
58 <span className="color-fg-muted pr-2" key={`${i}-slash`}>
59 /
60 </span>
61 ) : null}
62 </li>
63 ),
64 ]
65 })}
66 </ul>
67 </nav>
68 )
69}

Callers

nothing calls this directly

Calls 1

useMainContextFunction · 0.90

Tested by

no test coverage detected