4.8.1 • Published 3 years ago

@workday/canvas-kit-labs-react-breadcrumbs v4.8.1

Weekly downloads
264
License
Apache-2.0
Repository
github
Last release
3 years ago

Canvas Kit React Breadcrumbs

Breadcrumbs provides navigation to previous levels of pages.

Installation

yarn add @workday/canvas-kit-labs-react-breadcrumbs

Usage

Breadcrumbs is a composable component that provides more flexibility in its structure. There are two main variations: List and CollapsibleList. First, we'll discuss List. There will also be information about the shared sub-components below.

List

The List component is a styled, unordered list (ul) with no additional behaviors. Use this when you're not concerned about collapsing the list of breadcrumb items into a dropdown menu at a specified width.

Component Props

This component supports all native ul props.

Usage

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

const AccountInvoiceBreadcrumbNav = () => {
  return (
    <Breadcrumbs.Nav aria-label="Breadcrumb">
      <Breadcrumbs.List>
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/account">Account</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/billing">Billing</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/invoices">Invoices</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.CurrentItem>
          2020_08_01_invoice.pdf
        </Breadcrumbs.CurrentItem>
      </BreadCrumbs.List>
    </Breadcrumbs.Nav>
  );
}

CollapsibleList

The CollapsibleList component is built on top of List. It has additional functionality to collapse items in the list into a dropdown menu at a specified width.

Component Props

nametyperequireddefaultrecommended
maxWidthnumbertruen/an/a
buttonAriaLabelstringtruen/a"more links" (and translated equivalent)
buttonIconCanvasSystemIconfalserelatedActionsIconn/a

This component also supports all native ul props. The buttonAriaLabel prop is required for accessibility. We recommend using "more links" as seen in the example. This label is applied to the dropdown menu button.

Handling Collapse

The maxWidth prop sets the point to collapse. If the length of the list exceeds that value, items will be collapsed into a dropdown menu. Note that the first (root) item and last (current) items in the list will never be collapsed.

Handling Custom Dropdown Button Icons

By default the icon for the dropdown button is relatedActionsIcon. However, you can set this to any Canvas System Icon with the buttonIcon prop. Please consult the Canvas team if you decide to do this, as we'd like to keep breadcrumb navigation as consistent as possible.

Usage

const AccountInvoiceCollapsibleBreadcrumbNav = () => {
  return (
    <Breadcrumbs.Nav aria-label="Breadcrumb">
      <Breadcrumbs.CollapsibleList maxWidth={800} buttonAriaLabel="more links">
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/account">Account</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/billing">Billing</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.ListItem>
          <Breadcrumbs.Link href="/invoices">Invoices</Breadcrumbs.Link>
        </Breadcrumbs.ListItem>
        <Breadcrumbs.CurrentItem>
          2020_08_01_invoice.pdf
        </Breadcrumbs.CurrentItem>
      </BreadCrumbs.CollapsibleList>
    </Breadcrumbs.Nav>
  );
}

Nav

Breadcrumb.Nav a styled nav element.

Component Props

nametyperequireddefaultrecommended
aria-labelstringtruen/a"Breadcrumb" (and translated equivalent)

This component supports all native HTMLElement props. The aria-label prop is required for accessibility. We recommend using "Breadcrumb" as seen in the example.

Usage

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

...

return (
  <Breadcrumbs.Nav aria-label="Breadcrumb">
    {/* breadcrumb list goes here */}
  </Breadcrumbs.Nav>
);

ListItem

ListItem is a styled li element that contains a SystemIcon separator.

Component Props

This component supports all native li element props.

Usage

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

return <Breadcrumbs.ListItem>{/* breadcrumb link goes here */}</Breadcrumbs.ListItem>;

RTL (Right-To-Left) Support

This component will automatically toggle the separator icon from chevronRightSmallIcon to chevronLeftSmallIcon when RTL is in use.

Link

Link is a styled a element that also renders a tooltip if the text is truncated.

Component Props

nametyperequireddefault
hrefstringtruen/a
maxWidthnumberfalse350
onAction(href: string) => voidfalsen/a

This component also supports all native a element props.

Usage

Handling Redirects

Link defaults to redirecting with an href, meaning the page will hard-redirect when the link is clicked. However, if you're in a single page application (SPA) environment, you might want to use the internal SPA router instead. You can override this hard-redirect with the onAction prop. Note that onAction will not block any onClick if provided. Let's look at an example below:

import React from 'react';
// using the history package
import { createBrowserHistory } from 'history';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

// this is likely being done at the root of your application and not inside this component.
const history = createBrowserHistory();

const handleClick = (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
  // handle any click side-effects here
  console.log('click event', event);
}

const handleRedirect = (href: string) => {
  // redirect using the internal SPA router
  history.push(href);
}

return (
  <Breadcrumbs.Link
    href="/account"
    onAction={handleRedirect}
    onClick={handleClick}
  >
    Account
  </Breadcrumbs.Link>;
)
Handling Truncation

Link has built-in truncation + tooltip functionality to provide an easy-to-use, accessible feature for managing the length of link text. By default, the maxWidth is set to 350, however you can adjust this as needed. Note that tooltips will only render when text is truncated. Here's an example:

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

return (
  <Breadcrumbs.Link maxWidth={150} href="/account">
    2019_Q2_financial_documents
  </Breadcrumbs.Link>
);

CurrentItem

CurrentItem is a styled li element also renders a tooltip if the text is truncated.

Component Props

nametyperequireddefault
maxWidthnumberfalse350

This component also supports all native li element props.

Usage

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

return (
  <Breadcrumbs.CurrentItem>
    2020_06_28_Summary_of_Annual_Recurring_Revenue.pdf
  </Breadcrumbs.CurrentItem>
);
Handling Truncation

CurrentItem has built-in truncation + tooltip functionality to provide an easy-to-use, accessible feature for managing the length of link text. By default, the maxWidth is set to 350, however you can adjust this as needed. Note that tooltips will only render when text is truncated. Here's an example:

import React from 'react';
import Breadcrumbs from '@workday/canvas-kit-labs-react-breadcrumbs';

return (
  <Breadcrumbs.CurrentItem maxWidth={150}>
    2020_06_28_Summary_of_Annual_Recurring_Revenue.pdf
  </Breadcrumbs.CurrentItem>
);

RTL (Right-To-Left) Support

Breadcrumbs handles RTL internally without additional configuration needed. All you need to supply is the translated text for items and ARIA labels.

Accessibility

Accessibility is built into Breadcrumbs in a way that allows you to create an inclusive experience little additional configuration. The only ARIA labels you'll need to add are the aria-label for the Nav and the buttonAriaLabel for the CollapsibleList. And all links require hrefs to be properly identified. All other accessible attributes are baked into the components.

4.8.3

3 years ago

4.8.2

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.1-next.18

3 years ago

4.7.1-next.14

3 years ago

4.7.1-next.15

3 years ago

4.7.1-next.16

3 years ago

4.7.1-next.0

3 years ago

4.7.1-next.1

3 years ago

4.7.1-next.2

3 years ago

4.7.1-next.3

3 years ago

4.7.1-next.4

3 years ago

4.7.1-next.5

3 years ago

4.7.1-next.6

3 years ago

4.7.1-next.7

3 years ago

4.7.1-next.8

3 years ago

4.7.1-next.9

3 years ago

4.7.1-next.10

3 years ago

4.7.1-next.11

3 years ago

4.7.1-next.12

3 years ago

4.7.0

3 years ago

4.6.1-next.3

3 years ago

4.6.1-next.2

3 years ago

4.6.1-next.1

3 years ago

4.6.0

3 years ago

4.5.2-next.3

3 years ago

4.5.2-next.1

3 years ago

4.5.2-next.2

3 years ago

4.5.2-next.0

3 years ago

4.5.1-next.3

3 years ago

4.5.1-next.4

3 years ago

4.5.1

3 years ago

4.5.1-next.2

3 years ago

4.5.1-next.1

3 years ago

4.5.1-next.0

3 years ago

4.5.0

3 years ago

4.4.3-next.15

3 years ago

4.4.3-next.14

3 years ago

4.4.3-next.17

3 years ago

4.4.3-next.16

3 years ago

4.4.3-next.18

3 years ago

4.4.3-next.13

3 years ago

4.4.3-next.12

3 years ago

4.4.3-next.11

3 years ago

5.0.0-beta.0

3 years ago

4.4.3-next.10

3 years ago

4.4.3-next.9

3 years ago

4.4.3-next.8

3 years ago

4.4.3-next.7

3 years ago

4.4.3-next.6

3 years ago

4.4.3-next.5

3 years ago

4.4.3-next.4

3 years ago

4.4.3-next.3

3 years ago

4.4.3-next.0

3 years ago

4.4.3-next.1

3 years ago

4.4.2

3 years ago

4.4.2-next.4

3 years ago

4.4.2-next.3

3 years ago

4.4.2-next.2

3 years ago

4.4.1-next.4

3 years ago

4.4.1

3 years ago

4.4.1-next.3

3 years ago

4.4.1-next.2

3 years ago

4.4.1-next.0

3 years ago

4.4.1-next.1

3 years ago

4.4.0

3 years ago

4.3.2-next.6

3 years ago

4.3.2-next.4

3 years ago

4.3.2-next.3

3 years ago

4.3.2-next.5

3 years ago

4.3.2-next.2

3 years ago

4.3.2-next.1

4 years ago

4.3.2-next.0

4 years ago

4.3.1

4 years ago

4.3.1-next.4

4 years ago

4.3.1-next.2

4 years ago

4.3.1-next.3

4 years ago

4.3.1-next.1

4 years ago

4.3.1-next.0

4 years ago

4.3.0

4 years ago

4.1.3-next.28

4 years ago