Skip to content

Commit a718f57

Browse files
docs(breadcrumbs): update docs for accessibility and clarity (#5711)
* docs(breadcrumbs): update docs for accessibility and clarity * docs(breadcrumbs): pr fixes * Update packages/breadcrumbs/breadcrumb-item.md Include disabled as a state Co-authored-by: Nikki Massaro <[email protected]> --------- Co-authored-by: Nikki Massaro <[email protected]>
1 parent 01220fe commit a718f57

File tree

2 files changed

+224
-61
lines changed

2 files changed

+224
-61
lines changed

packages/breadcrumbs/README.md

Lines changed: 149 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1-
## Description
1+
## Overview
2+
3+
An `<sp-breadcrumbs>` shows hierarchy and navigational context for a user's location within an app. The `<sp-breadcrumbs>` component defines its list of items using child `<sp-breadcrumb-item>` elements placed in its default slot.
4+
5+
[View the design documentation for this component.](https://spectrum.adobe.com/page/breadcrumbs/)
26

37
### Usage
48

59
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/breadcrumbs?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/breadcrumbs)
610
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/breadcrumbs?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/breadcrumbs)
711

8-
```
12+
```zsh
913
yarn add @spectrum-web-components/breadcrumbs
1014
```
1115

1216
Import the side effectful registration of `<sp-breadcrumbs>` and `<sp-breadcrumb-item>` via:
1317

14-
```
18+
```js
1519
import '@spectrum-web-components/breadcrumbs/sp-breadcrumbs.js';
1620
import '@spectrum-web-components/breadcrumbs/sp-breadcrumb-item.js';
1721
```
1822

1923
When looking to leverage the `Breadcrumbs` or `BreadcrumbItem` base class as a type and/or for extension purposes, do so via:
2024

21-
```
22-
import { Breadcrumbs, BreadcrumbItem } from '@spectrum-web-components/breadcrumbs';
25+
```js
26+
import {
27+
Breadcrumbs,
28+
BreadcrumbItem,
29+
} from '@spectrum-web-components/breadcrumbs';
2330
```
2431

25-
## Example
32+
### Anatomy
2633

27-
```html
28-
<sp-breadcrumbs>
29-
<sp-breadcrumb-item value="1">Home</sp-breadcrumb-item>
30-
<sp-breadcrumb-item value="2">Trend</sp-breadcrumb-item>
31-
<sp-breadcrumb-item value="3">March 2019 Assets</sp-breadcrumb-item>
32-
</sp-breadcrumbs>
33-
```
34+
Breadcrumbs consist of several key parts:
3435

35-
## Disabled
36-
37-
`sp-breadcrumb-item` can have a `disabled` state which disables the events from the disabled item.
36+
- A breadcrumbs list, usually consisting of multiple [breadcrumb items](/components/breadcrumb-item), with a separator between each item.
37+
- A breadcrumbs title at the end of the list displaying the current location within the hierarchy.
38+
- A truncation menu may also appear, which displays all options within a breadcrumb. Within the menu, items are listed with the hierarchy ordered from the top (root) to the bottom, and will include the currently selected item. Breadcrumbs truncate when there isn't enough space to show all items, or when the list contains five or more levels. Truncation helps manage space and keep the most relevant breadcrumbs visible in deeply nested hierarchies.
3839

3940
```html
4041
<sp-breadcrumbs>
41-
<sp-breadcrumb-item disabled value="1">Home</sp-breadcrumb-item>
42-
<sp-breadcrumb-item value="2">Trend</sp-breadcrumb-item>
43-
<sp-breadcrumb-item value="3">March 2019 Assets</sp-breadcrumb-item>
42+
<sp-breadcrumb-item value="home">Home</sp-breadcrumb-item>
43+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
44+
<sp-breadcrumb-item value="assets">March 2019 Assets</sp-breadcrumb-item>
4445
</sp-breadcrumbs>
4546
```
4647

47-
## Compact
48+
### Options
49+
50+
#### Compact
4851

49-
When needing to optimize for functional space of `sp-breadcrumbs`, the compact option is useful for reducing the height of the breadcrumbs while still maintaining the proper user context.
52+
When needing to optimize for functional space of `<sp-breadcrumbs>`, the `compact` property can be used to reduce the height of the breadcrumbs while still maintaining the proper user context.
5053

5154
```html
5255
<sp-breadcrumbs compact>
@@ -56,34 +59,52 @@ When needing to optimize for functional space of `sp-breadcrumbs`, the compact o
5659
</sp-breadcrumbs>
5760
```
5861

59-
## Links
62+
#### Overflowing
6063

61-
By default, `sp-breadcrumbs` emits a `change` event when clicking on one of its children.
62-
However, there may be cases in which these should redirect to another page. This can be achieved by using the `href` attribute instead of `value`.
63-
Please note that the `change` event will no longer be triggered in this case.
64+
When space becomes limited or the maximum visible items are reached, the component automatically moves the first breadcrumbs into an action menu, adjusting dynamically as the window is resized.
65+
66+
By default, the maximum number of visible breadcrumbs is 4, as recommended by [Spectrum Design](https://spectrum.adobe.com/page/breadcrumbs/#Don%E2%80%99t-show-too-many-breadcrumbs-at-once). You can override this by using the `max-visible-items` attribute. The `<sp-breadcrumbs>` component will always display the action menu and the breadcrumbs title, so the minimum number of visible items is 1.
67+
68+
<sp-tabs selected="default" label="Overflow options">
69+
<sp-tab value="default">Default</sp-tab>
70+
<sp-tab-panel value="default">
6471

6572
```html
6673
<sp-breadcrumbs>
67-
<sp-breadcrumb-item href="https://opensource.adobe.com/home">
68-
Home
69-
</sp-breadcrumb-item>
70-
<sp-breadcrumb-item href="https://opensource.adobe.com/trend">
71-
Trend
72-
</sp-breadcrumb-item>
73-
<sp-breadcrumb-item href="https://opensource.adobe.com/assets">
74-
March 2019 Assets
75-
</sp-breadcrumb-item>
74+
<sp-breadcrumb-item value="your_stuff">Your stuff</sp-breadcrumb-item>
75+
<sp-breadcrumb-item value="team">Team</sp-breadcrumb-item>
76+
<sp-breadcrumb-item value="in_progress">In progress</sp-breadcrumb-item>
77+
<sp-breadcrumb-item value="files">Files</sp-breadcrumb-item>
78+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
79+
<sp-breadcrumb-item value="winter">Winter</sp-breadcrumb-item>
80+
<sp-breadcrumb-item value="assets">Assets</sp-breadcrumb-item>
81+
<sp-breadcrumb-item value="18x24">18x24</sp-breadcrumb-item>
7682
</sp-breadcrumbs>
7783
```
7884

79-
## Overflowing
85+
</sp-tab-panel>
86+
<sp-tab value="one-max-item">One maximum visible item</sp-tab>
87+
<sp-tab-panel value="one-max-item">
8088

81-
When the space is limited or the maximum number of visible items is reached, the component will render the first breadcrumbs inside an action menu. If needed, the last breadcrumb item will be truncated and will render a tooltip with the full text.
89+
```html
90+
<sp-breadcrumbs max-visible-items="1">
91+
<sp-breadcrumb-item value="your_stuff">Your stuff</sp-breadcrumb-item>
92+
<sp-breadcrumb-item value="team">Team</sp-breadcrumb-item>
93+
<sp-breadcrumb-item value="in_progress">In progress</sp-breadcrumb-item>
94+
<sp-breadcrumb-item value="files">Files</sp-breadcrumb-item>
95+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
96+
<sp-breadcrumb-item value="winter">Winter</sp-breadcrumb-item>
97+
<sp-breadcrumb-item value="assets">Assets</sp-breadcrumb-item>
98+
<sp-breadcrumb-item value="18x24">18x24</sp-breadcrumb-item>
99+
</sp-breadcrumbs>
100+
```
82101

83-
As recommended by [Spectrum Design](https://spectrum.adobe.com/page/breadcrumbs/#Don%E2%80%99t-show-too-many-breadcrumbs-at-once), by default the maximum visible breadcrumbs is 4. If you want to override this, you can use the `max-visible-items` attribute.
102+
</sp-tab-panel>
103+
<sp-tab value="three-max-items">Three maximum visible items</sp-tab>
104+
<sp-tab-panel value="three-max-items">
84105

85106
```html
86-
<sp-breadcrumbs>
107+
<sp-breadcrumbs max-visible-items="3">
87108
<sp-breadcrumb-item value="your_stuff">Your stuff</sp-breadcrumb-item>
88109
<sp-breadcrumb-item value="team">Team</sp-breadcrumb-item>
89110
<sp-breadcrumb-item value="in_progress">In progress</sp-breadcrumb-item>
@@ -95,9 +116,37 @@ As recommended by [Spectrum Design](https://spectrum.adobe.com/page/breadcrumbs/
95116
</sp-breadcrumbs>
96117
```
97118

98-
### Show root
119+
</sp-tab-panel>
120+
<sp-tab value="resizable">Resizable</sp-tab>
121+
<sp-tab-panel value="resizable">
122+
123+
These breadcrumbs are in a resizable container. Reduce the size of the container to see how the maximum number of visible items changes.
124+
125+
```html
126+
<div style="border: 2px solid; padding: 20px; resize: both; overflow: auto;">
127+
<sp-breadcrumbs max-visible-items="8">
128+
<sp-breadcrumb-item value="your_stuff">Your stuff</sp-breadcrumb-item>
129+
<sp-breadcrumb-item value="team">Team</sp-breadcrumb-item>
130+
<sp-breadcrumb-item value="in_progress">In progress</sp-breadcrumb-item>
131+
<sp-breadcrumb-item value="files">Files</sp-breadcrumb-item>
132+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
133+
<sp-breadcrumb-item value="winter">Winter</sp-breadcrumb-item>
134+
<sp-breadcrumb-item value="assets">Assets</sp-breadcrumb-item>
135+
<sp-breadcrumb-item value="18x24">18x24</sp-breadcrumb-item>
136+
</sp-breadcrumbs>
137+
</div>
138+
```
139+
140+
</sp-tab-panel>
141+
</sp-tabs>
142+
143+
#### Show root
99144

100-
Use the "root" slot to always render the first breadcrumb item, even if the breadcrumbs are overflowing.
145+
Use the `root` slot on the first breadcrumb item to always render the first breadcrumb item, even if the breadcrumbs are overflowing. The root will always show in addition to the number of items specified with `max-visible-items`.
146+
147+
<sp-tabs selected="overflowing" auto label="Root slot variations">
148+
<sp-tab value="overflowing">Overflowing</sp-tab>
149+
<sp-tab-panel value="overflowing">
101150

102151
```html
103152
<sp-breadcrumbs>
@@ -112,9 +161,48 @@ Use the "root" slot to always render the first breadcrumb item, even if the brea
112161
</sp-breadcrumbs>
113162
```
114163

115-
## Custom Action Menu
164+
</sp-tab-panel>
165+
<sp-tab value="not-overflowing">Not overflowing</sp-tab>
166+
<sp-tab-panel value="not-overflowing">
167+
168+
```html
169+
<sp-breadcrumbs>
170+
<sp-breadcrumb-item slot="root" value="your_stuff">
171+
Your stuff
172+
</sp-breadcrumb-item>
173+
<sp-breadcrumb-item value="files">Files</sp-breadcrumb-item>
174+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
175+
<sp-breadcrumb-item value="winter">Winter</sp-breadcrumb-item>
176+
<sp-breadcrumb-item value="assets">Assets</sp-breadcrumb-item>
177+
</sp-breadcrumbs>
178+
```
179+
180+
</sp-tab-panel>
181+
</sp-tabs>
116182

117-
The component offers the possibility to replace the action menu's icon with a custom one using the `icon` slot. Moreover, for accesibility purposes you can provide an internationalized string for the menu label using the `menu-label` attribute.
183+
#### Links
184+
185+
By default, `sp-breadcrumbs` emits a `change` event when clicking on one of its children.
186+
However, there may be cases in which clicking should redirect to another page. This can be achieved by using the `href` attribute instead of `value`.
187+
Please note that the `change` event will no longer be triggered in this case.
188+
189+
```html
190+
<sp-breadcrumbs>
191+
<sp-breadcrumb-item href="https://opensource.adobe.com/">
192+
Home
193+
</sp-breadcrumb-item>
194+
<sp-breadcrumb-item href="https://opensource.adobe.com/trend">
195+
Trend
196+
</sp-breadcrumb-item>
197+
<sp-breadcrumb-item href="https://opensource.adobe.com/assets">
198+
March 2019 Assets
199+
</sp-breadcrumb-item>
200+
</sp-breadcrumbs>
201+
```
202+
203+
#### Custom Action Menu
204+
205+
The component offers the possibility to replace the action menu's icon with a custom one using the `icon` slot. Moreover, for accessibility purposes you can provide an internationalized string for the menu label using the `menu-label` attribute.
118206

119207
```html
120208
<sp-breadcrumbs menu-label="Settings">
@@ -127,3 +215,22 @@ The component offers the possibility to replace the action menu's icon with a cu
127215
<sp-breadcrumb-item value="1">Preset #1</sp-breadcrumb-item>
128216
</sp-breadcrumbs>
129217
```
218+
219+
### Accessibility
220+
221+
The `<sp-breadcrumbs>` component provides the following accessibility features:
222+
223+
- Automatically sets `role="navigation"` to ensure proper semantic meaning for assistive technologies
224+
- Uses semantic markup by rendering a `<ul>` with each [`<sp-breadcrumb-item>`](/components/breadcrumb-item) assigned `role="listitem"`
225+
- The last breadcrumb item automatically receives `aria-current="page"` to indicate the current location
226+
- Sets `aria-label` based on the `label` property, defaulting to `"Breadcrumbs"` if none is provided
227+
- Each breadcrumb item is keyboard accessible with `tabindex="0"`
228+
- Provides an accessible [action menu](/components/action-menu) with keyboard navigation and screen reader support
229+
230+
#### Best practices
231+
232+
- **Limit breadcrumb depth**: Keep breadcrumbs to 4-5 levels maximum to avoid overwhelming users
233+
- **Use descriptive labels**: Each breadcrumb item should clearly identify the section or page
234+
- **Maintain consistent hierarchy**: Always start from the root and progress logically to the current page
235+
- **Handle overflow gracefully**: Use the `max-visible-items` property to control truncation behavior
236+
- **Provide meaningful menu labels**: Use the `menu-label` attribute to describe the overflow menu purpose
Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,114 @@
11
## Overview
22

3-
For use within an `<sp-breadcrumbs>` element, an `<sp-breadcrumb-item>` represents a single item in a list.
3+
For use within an [`<sp-breadcrumbs>`](/components/breadcrumbs) element, an `<sp-breadcrumb-item>` represents a single item in a breadcrumbs list. The default slot contains the main content of the breadcrumb item.
44

55
### Usage
66

77
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/breadcrumbs?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/breadcrumbs)
88
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/breadcrumbs?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/breadcrumbs)
99

10-
```
10+
```zsh
1111
yarn add @spectrum-web-components/breadcrumbs
1212
```
1313

1414
Import the side effectful registration of `<sp-breadcrumb-item>` as follows:
1515

16-
```
16+
```js
1717
import '@spectrum-web-components/breadcrumbs/sp-breadcrumb-item.js';
1818
```
1919

2020
When looking to leverage the `BreadcrumbItem` base class as a type and/or for extension purposes, do so via:
2121

22-
```
22+
```js
2323
import { BreadcrumbItem } from '@spectrum-web-components/breadcrumbs';
2424
```
2525

26-
## Example
26+
### Anatomy
27+
28+
The breadcrumb item consists of the following:
29+
30+
- A clickable anchor (`<a>`) that contains the breadcrumb text and handles navigation
31+
- Text content as the main label displayed in the default slot, which becomes the clickable link text
32+
- A separator consisting of a chevron [UI icon component](/components/icons-ui/) (`<sp-icon-chevron100>`) that visually separates breadcrumb items
33+
- An optional [action menu](/components/action-menu) for displaying overflowed breadcrumb items
34+
35+
### Options
36+
37+
#### Value or href attributes
38+
39+
When using the `href` attribute instead of the `value` attribute, the breadcrumb item behaves as a regular anchor link.
40+
41+
<sp-tabs selected="link" label="Value or href attributes">
42+
<sp-tab value="using-value">Value</sp-tab>
43+
<sp-tab-panel value="using-value">
2744

2845
```html
2946
<sp-breadcrumbs>
30-
<sp-breadcrumb-item value="1">Home</sp-breadcrumb-item>
31-
<sp-breadcrumb-item value="2">Trend</sp-breadcrumb-item>
32-
<sp-breadcrumb-item value="3">March 2019 Assets</sp-breadcrumb-item>
47+
<sp-breadcrumb-item value="home">Home</sp-breadcrumb-item>
48+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
49+
<sp-breadcrumb-item value="assets">March 2019 Assets</sp-breadcrumb-item>
3350
</sp-breadcrumbs>
3451
```
3552

36-
## Links
37-
38-
When using the `href` attribute instead of the `value` attribute, the breadcrumb item behaves as a regular anchor link.
53+
</sp-tab-panel>
54+
<sp-tab value="using-link">Link</sp-tab>
55+
<sp-tab-panel value="using-link">
3956

4057
```html
4158
<sp-breadcrumbs>
42-
<sp-breadcrumb-item href="/1">Home</sp-breadcrumb-item>
43-
<sp-breadcrumb-item href="/2">Trend</sp-breadcrumb-item>
44-
<sp-breadcrumb-item href="/3">March 2019 Assets</sp-breadcrumb-item>
59+
<sp-breadcrumb-item href="/home">Home</sp-breadcrumb-item>
60+
<sp-breadcrumb-item href="/trend">Trend</sp-breadcrumb-item>
61+
<sp-breadcrumb-item href="/assets">March 2019 Assets</sp-breadcrumb-item>
4562
</sp-breadcrumbs>
4663
```
4764

48-
## Disabled
65+
</sp-tab-panel>
66+
</sp-tabs>
67+
68+
#### With menu content
4969

50-
Disabled breadcrumb items no longer receive focus and keyboard events.
70+
When breadcrumbs overflow, `<sp-breadcrumbs>` will create an `<sp-breadcrumb-item>` with an [`<sp-action-menu>`](/components/action-menu) that contains the full list of breadcrumb items in reading order.
71+
72+
```html
73+
<sp-breadcrumbs max-visible-items="2">
74+
<sp-breadcrumb-item slot="root" value="your_stuff">
75+
Your stuff
76+
</sp-breadcrumb-item>
77+
<sp-breadcrumb-item value="team">Files</sp-breadcrumb-item>
78+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
79+
<sp-breadcrumb-item value="winter">Winter</sp-breadcrumb-item>
80+
<sp-breadcrumb-item value="assets">Assets</sp-breadcrumb-item>
81+
<sp-breadcrumb-item value="18x24">18x24</sp-breadcrumb-item>
82+
</sp-breadcrumbs>
83+
```
84+
85+
### States
86+
87+
#### Disabled
88+
89+
An `sp-breadcrumb-item` can have a `disabled` state which disables the events from that item.
5190

5291
```html
5392
<sp-breadcrumbs>
54-
<sp-breadcrumb-item disabled value="1">Home</sp-breadcrumb-item>
55-
<sp-breadcrumb-item disabled value="2">Trend</sp-breadcrumb-item>
56-
<sp-breadcrumb-item value="3">March 2019 Assets</sp-breadcrumb-item>
93+
<sp-breadcrumb-item disabled value="home">Home</sp-breadcrumb-item>
94+
<sp-breadcrumb-item value="trend">Trend</sp-breadcrumb-item>
95+
<sp-breadcrumb-item value="assets">March 2019 Assets</sp-breadcrumb-item>
5796
</sp-breadcrumbs>
5897
```
98+
99+
### Accessibility
100+
101+
The `<sp-breadcrumb-item>` component provides the following accessibility features:
102+
103+
- Automatically applies `role="listitem"` to ensure proper semantic meaning for assistive technologies
104+
- The last breadcrumb item automatically receives `aria-current="page"` to indicate the current location
105+
- Applies `aria-disabled="true"` when the `disabled` property is set
106+
- Each breadcrumb item is keyboard accessible with `tabindex="0"`
107+
- Supports `Enter` key activation for navigation
108+
109+
#### Best practices
110+
111+
- **Provide meaningful text content**: Ensure each breadcrumb item has descriptive and meaningful labels
112+
- **Use proper hierarchy**: Place breadcrumb items in the correct order from root to current page
113+
- **Handle navigation events**: Listen for the `breadcrumb-select` event when using `value` instead of `href`
114+
- **Keep labels concise**: Use short, descriptive labels that clearly identify each level

0 commit comments

Comments
 (0)