# React Native Breadcrumbs

> Accessible React Native breadcrumbs for iOS, Android and the web: a trail of links back up the hierarchy, the current page marked, long paths folded into an ellipsis, in a brand, iOS, Material 3 or web design.

# Breadcrumbs

Where the page sits in a hierarchy, each level a link back up. The last item is the current page. Use it on tablets and the web, in file browsers, settings and admin screens; on a phone, a [Header](./header) with a back button does the job.

```tsx
import { Breadcrumbs } from 'patine-ui';
```

```tsx live
import { Box, Breadcrumbs, Heading, Text } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

export default function Example() {
  const [path, setPath] = React.useState(['Workspace', 'Marketing', 'Campaigns', 'Spring launch', 'Assets']);
  return (
    <Box padding="lg" border radius="lg" gap="sm" style={{ maxWidth: 520 }}>
      <Breadcrumbs
        maxItems={4}
        items={path.map((label, i) => ({
          label,
          icon: i === 0 ? <Icon name="home" size="sm" /> : undefined,
          onPress: () => setPath(path.slice(0, i + 1)),
        }))}
      />
      <Heading level={3}>{path[path.length - 1]}</Heading>
      <Text color="textSecondary">Press a level to go back up to it.</Text>
    </Box>
  );
}
```

## Example: a file browser

A shared drive: opening a folder adds it to the trail, and pressing any level goes back up to it. Long paths fold their middle into a menu.

```tsx live
import { useState } from 'react';
import { Breadcrumbs, Box, List, ListItem, Text } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const DRIVE = {
  'Company drive': ['Marketing', 'Finance'],
  Marketing: ['Campaigns', 'Brand'],
  Campaigns: ['Spring launch', 'Black Friday'],
  'Spring launch': ['Social', 'Email'],
  Social: [],
  Email: [],
  'Black Friday': [],
  Brand: [],
  Finance: ['Invoices', 'Payroll'],
  Invoices: [],
  Payroll: [],
};

export default function Example() {
  const [path, setPath] = useState(['Company drive', 'Marketing']);
  const folders = DRIVE[path[path.length - 1]];
  return (
    <Box border radius="lg" padding="md" gap="sm" style={{ width: '100%', maxWidth: 480 }}>
      <Breadcrumbs
        maxItems={4}
        items={path.map((label, i) => ({
          label,
          icon: i === 0 ? <Icon name="home" size="sm" /> : undefined,
          onPress: i < path.length - 1 ? () => setPath(path.slice(0, i + 1)) : undefined,
        }))}
      />
      <List>
        {folders.map((name) => (
          <ListItem key={name} leading={<Icon name="folder" />} title={name} description={`${DRIVE[name].length} folders`} onPress={() => setPath([...path, name])} />
        ))}
      </List>
      {folders.length ? null : <Text color="textSecondary">This folder holds files only.</Text>}
    </Box>
  );
}
```

## Long paths

Past `maxItems`, the middle levels fold into `…`, keeping the first and the last ones. Pressing `…` unfolds the whole path.

## Separator

Each design has its own: a slash on the web and in brand, as shadcn draws it, and a chevron on iOS and Material. `separator` takes any string or node.

```tsx live
import { Breadcrumbs, VStack } from 'patine-ui';

const items = [{ label: 'Home', onPress: () => {} }, { label: 'Settings', onPress: () => {} }, { label: 'Notifications' }];

export default function Example() {
  return (
    <VStack gap="md">
      <Breadcrumbs items={items} separator="/" />
      <Breadcrumbs items={items} separator="›" />
      <Breadcrumbs items={items} separator="→" />
    </VStack>
  );
}
```

## Designs

- **brand** and **web**: gray links and slashes, the current page in the text color, as shadcn's Breadcrumb.
- **iOS** and **Material 3**: links in the primary color with a chevron, the current page bolder.

## Accessibility

- A `navigation` landmark named `'Breadcrumb'` (`accessibilityLabel`). Each level is a `link`; the current page is plain text marked `aria-current="page"`.
- Separators are hidden from screen readers. The `…` is a link named `'Show path'` (`expandLabel`).
- Links reach a 44pt touch height on phones and show a focus ring on the web.

## Props

Also takes `View` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `{ label, onPress?, icon? }[]` | — | The path from the top to the current page. |
| `separator` | `ReactNode` | the design's | Between items. |
| `maxItems` | `number` | no limit | Folds the middle into `…` past this many. |
| `accessibilityLabel` | `string` | `'Breadcrumb'` | Names the trail. |
| `expandLabel` | `string` | `'Show path'` | The `…` link's name. |
| `styles` | `{ item?, current?, separator? }` | — | Slot styles. |
| `theme`, `design` | | | As every component. |
