Skip to content

Commit 48f5699

Browse files
docs(sidenav): update sidenav documentation
1 parent dbfe680 commit 48f5699

File tree

1 file changed

+124
-43
lines changed

1 file changed

+124
-43
lines changed

packages/sidenav/README.md

Lines changed: 124 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Description
1+
## Overview
22

33
Side navigation allows users to locate information and features within the UI.
44
It can be used for either hierarchical or flat navigation, and gives the ability
@@ -7,37 +7,67 @@ prioritize content or features based on your users’ needs in a way that
77
maintains clear, persistent visibility. Use side navigation within the context
88
of larger elements and mechanisms within the app frame.
99

10-
`<sp-sidenav>` elements accept both `<sp-sidenav-item>` and `<sp-sidenav-heading>` elements as children in order to construct a hierarchy of navigation elements. [`<sp-sidenav-item>`](./components/sidenav-item) elements will place themselves as a togglable child of their `<sp-sidenav>` element parent. `<sp-sidenav-heading>` elements will create visible structure by grouping their child `<sp-sidenav-item>` children under a non-interactive heading.
10+
`<sp-sidenav>` elements accept both `<sp-sidenav-item>` and `<sp-sidenav-heading>` elements as children in order to construct a hierarchy of navigation elements. [`<sp-sidenav-item>`](/components/sidenav-item/) elements will place themselves as a togglable child of their `<sp-sidenav>` element parent. [`<sp-sidenav-heading>`](/components/sidenav-heading/) elements will create visible structure by grouping their `<sp-sidenav-item>` children under a non-interactive heading.
11+
12+
[View the design documentation for this component.](https://spectrum.adobe.com/page/side-navigation/)
1113

1214
### Usage
1315

1416
[![See it on NPM!](https://img.shields.io/npm/v/@spectrum-web-components/sidenav?style=for-the-badge)](https://www.npmjs.com/package/@spectrum-web-components/sidenav)
1517
[![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/sidenav?style=for-the-badge)](https://bundlephobia.com/result?p=@spectrum-web-components/sidenav)
1618
[![Try it on Stackblitz](https://img.shields.io/badge/Try%20it%20on-Stackblitz-blue?style=for-the-badge)](https://stackblitz.com/edit/vitejs-vite-q3w6kjxv)
1719

18-
```
20+
```bash
1921
yarn add @spectrum-web-components/sidenav
2022
```
2123

2224
Import the side effectful registration of `<sp-sidenav>`, `<sp-sidenav-heading>`, or `<sp-sidenav-item>` via:
2325

24-
```
26+
```js
2527
import '@spectrum-web-components/sidenav/sp-sidenav.js';
2628
import '@spectrum-web-components/sidenav/sp-sidenav-heading.js';
2729
import '@spectrum-web-components/sidenav/sp-sidenav-item.js';
2830
```
2931

3032
When looking to leverage the `Sidenav`, `SidenavHeading`, or `SidenavItem` base classes as a type and/or for extension purposes, do so via:
3133

32-
```
34+
```js
3335
import {
3436
Sidenav,
3537
SidenavHeading,
36-
SidenavItem
38+
SidenavItem,
3739
} from '@spectrum-web-components/sidenav';
3840
```
3941

40-
## Example
42+
### Anatomy
43+
44+
The side navigation consists of several key parts:
45+
46+
- A container element that manages the side navigation behavior
47+
- Individual side navigation items that may or may not be expandable
48+
- Children side navigation items that are revealed when a parent item is expanded
49+
- Optional header with a label
50+
51+
```html live-demo
52+
<sp-sidenav>
53+
<sp-sidenav-heading label="Piano"></sp-sidenav-heading>
54+
<sp-sidenav-item label="Treble"></sp-sidenav-item>
55+
<sp-sidenav-item label="Bass"></sp-sidenav-item>
56+
<sp-sidenav-item disabled label="Grand staff"></sp-sidenav-item>
57+
</sp-sidenav>
58+
```
59+
60+
### Options
61+
62+
<sp-tabs selected="default" auto label="Side navigation options">
63+
<sp-tab value="default">Default</sp-tab>
64+
<sp-tab-panel value="default">
65+
66+
Make sure to use the right option for the context and user needs. Don’t mix behavior, styles, or variations together in a single navigation menu. Follow these guidelines:
67+
68+
- When navigation is simple, use the single level side navigation.
69+
- When navigation is simple but categorical, use the single level side navigation with headers.
70+
- When navigation is expansive, hierarchical, and/or you need progressive disclosure in the menu behavior, use the multi-level side navigation.
4171

4272
```html
4373
<sp-sidenav defaultValue="Docs">
@@ -79,38 +109,64 @@ import {
79109
</sp-sidenav>
80110
```
81111

82-
## Multi-level
112+
</sp-tab-panel>
113+
<sp-tab value="headings">With headings</sp-tab>
114+
<sp-tab-panel value="headings">
115+
116+
Use a single level with headers side navigation when needing to group navigation items into categories. This variation has the same behavior as the single level side navigation, but it has headers that aren’t interactive. If items don’t fall into a category, place them at the top.
117+
118+
```html
119+
<sp-sidenav variant="multilevel">
120+
<sp-sidenav-item value="Section 1" label="Section 1"></sp-sidenav-item>
121+
<sp-sidenav-item value="Section 2" label="Section 2"></sp-sidenav-item>
122+
<sp-sidenav-heading label="Category 1">
123+
<sp-sidenav-item value="Section 3" label="Section 3"></sp-sidenav-item>
124+
<sp-sidenav-item value="Section 4" label="Section 4"></sp-sidenav-item>
125+
</sp-sidenav-heading>
126+
<sp-sidenav-heading label="Category 2">
127+
<sp-sidenav-item value="Section 5" label="Section 5"></sp-sidenav-item>
128+
<sp-sidenav-item value="Section 6" label="Section 6"></sp-sidenav-item>
129+
</sp-sidenav-heading>
130+
</sp-sidenav>
131+
```
132+
133+
</sp-tab-panel>
134+
<sp-tab value="multilevel">Multi-level</sp-tab>
135+
<sp-tab-panel value="multilevel">
83136

84-
Use this variation when you have multiple layers of hierarchical navigation. The
85-
headers are styled differently and possess the same interactive behavior as a
86-
treeview; clicking the header opens and collapses the children navigation items.
137+
Use `variant="multi-level` when you have multiple layers of hierarchical navigation.
87138
In the instances where a top-level navigation item has no children, clicking
88139
will send the user to the location of the item.
89140

141+
In multi-level side navigation, only the first-level items can have icons. Any sub-level items should always be text-only to ensure clear hierarchy. In cases where the navigation content might be user-generated, stick to text-only navigation items.
142+
90143
```html
91144
<sp-sidenav variant="multilevel" defaultValue="Layout">
92-
<sp-sidenav-item value="Guidelines" label="Guidelines">
93-
</sp-sidenav-item>
94-
<sp-sidenav-item value="Styles" label="Styles" expanded>
95-
<sp-sidenav-item value="Color" label="Color">
96-
</sp-sidenav-item>
145+
<sp-sidenav-item value="Guidelines" label="Guidelines"></sp-sidenav-item>
146+
<sp-sidenav-heading value="Styles" label="Styles" expanded>
147+
<sp-sidenav-item value="Color" label="Color"></sp-sidenav-item>
97148
<sp-sidenav-item value="Grid" label="Grid" expanded>
98-
<sp-sidenav-item value="Layout" label="Layout">
99-
</sp-sidenav-item>
100-
<sp-sidenav-item value="Responsive" label="Responsive">
101-
</sp-sidenav-item>
149+
<sp-sidenav-item value="Layout" label="Layout"></sp-sidenav-item>
150+
<sp-sidenav-item
151+
value="Responsive"
152+
label="Responsive"
153+
></sp-sidenav-item>
102154
</sp-sidenav-item>
103-
<sp-sidenav-item value="Typography" label="Typography">
104-
</sp-sidenav-item>
105-
</sp-sidenav-item>
106-
<sp-sidenav-item value="Elements" label="Elements">
107-
</sp-sidenav-item>
108-
<sp-sidenav-item value="Patterns" label="Patterns">
109-
</sp-sidenav-item>
110-
</sp-sidenav-itm>
155+
<sp-sidenav-item
156+
value="Typography"
157+
label="Typography"
158+
></sp-sidenav-item>
159+
</sp-sidenav-heading>
160+
<sp-sidenav-item value="Elements" label="Elements"></sp-sidenav-item>
161+
<sp-sidenav-item value="Patterns" label="Patterns"></sp-sidenav-item>
162+
</sp-sidenav>
111163
```
112164

113-
## Icon
165+
</sp-tab-panel>
166+
<sp-tab value="icon">Icons</sb-tab>
167+
<sp-tab-panel value="icon">
168+
169+
Icon and text-only navigation items can be used in combination. However, do not alternate the two to keep a clear hierarchy. When using the heading variation, an entire category should either all have icons or all be text-only.
114170

115171
```html
116172
<sp-sidenav>
@@ -126,23 +182,48 @@ will send the user to the location of the item.
126182
</sp-sidenav>
127183
```
128184

129-
## Heading
185+
</sp-tab-panel>
186+
</sp-tabs>
187+
188+
### Behaviors
189+
190+
When an side navigation item becomes selected in `variant="multilevel"`, all of its parent items automatically expand to reveal the selection path.
191+
192+
### States
193+
194+
With the `disabled` attribute, the entire `sp-sidenav` can be removed from the tab order.
130195

131196
```html
132-
<sp-sidenav variant="multilevel">
133-
<sp-sidenav-item value="Section 1" label="Section 1"></sp-sidenav-item>
134-
<sp-sidenav-item value="Section 2" label="Section 2"></sp-sidenav-item>
135-
<sp-sidenav-heading label="Category 1">
136-
<sp-sidenav-item value="Section 3" label="Section 3"></sp-sidenav-item>
137-
<sp-sidenav-item value="Section 4" label="Section 4"></sp-sidenav-item>
138-
</sp-sidenav-heading>
139-
<sp-sidenav-heading label="Category 2">
140-
<sp-sidenav-item value="Section 5" label="Section 5"></sp-sidenav-item>
141-
<sp-sidenav-item value="Section 6" label="Section 6"></sp-sidenav-item>
142-
</sp-sidenav-heading>
197+
<sp-sidenav >
198+
<sp-sidenav-item value="Section Title 1" label="Section Title 1">
199+
<sp-icon-star slot="icon"></sp-icon-star>
200+
</sp-sidenav-item>
201+
<sp-sidenav-item value="Section Title 2" label="Section Title 2">
202+
<sp-icon-star slot="icon"></sp-icon-star>
203+
</sp-sidenav-item>
204+
<sp-sidenav-item value="Section Title 3" label="Section Title 3">
205+
<sp-icon-star slot="icon"></sp-icon-star>
206+
</sp-sidenav-item>
143207
</sp-sidenav>
144208
```
145209

146-
## Accessibility
210+
### Accessibility
211+
212+
When the `manage-tab-index` attribute is set on an `sp-sidenav` element, it will present its `sp-sidenav-item` children with a single tab-stop. This will leave items beyond the selected item (or when there is no focusable selected item), accessible via the up and down arrow keys. Items with expanded children that aren't selected lose focus when `manage-tab-index` is active.
213+
214+
- `<sp-sidenav>` renders a `<nav>` tag and implicitly sets `role="navigation"`
215+
- Optional `aria-label` is available for further identification
216+
- Individual items use `role="listitem"` automatically
217+
- Nested list containers (i.e. `div` tags) use `role="list"`
218+
- Nested item containers use `aria-labelledby` referencing their parent item's `id`
219+
- `aria-expanded="true/false"` indicates expand/collapse state for parent items
220+
- `aria-controls` on parent items is set to the `id` of their child `role="list"` containers when expanded
221+
- `aria-current="page"` indicates the currently selected item when it has an `href`
222+
- When the `sp-sidenav` includes the `disabled` property, the entire component receives `tabindex="-1"`
223+
- `aria-hidden="true"` is applied to all decorative icons
224+
225+
#### Keyboard interaction
147226

148-
When the `manage-tab-index` attribute is set on an `sp-sidenav` element then it will presents its child `sp-sidenav-item` children with a single tab-stop. This will leave items beyond the selected item, or first when there is no focusable selected item, will be accessibile via the up and down arrow keys.
227+
- `Tab` and `Shift + Tab` moves focus into or out of the side nav
228+
- If `manage-tab-index` is enabled, the up and down arrow keys will shift focus between all visible sidenav items
229+
- `Enter` or `Space` selects a side nav item or toggles expansion for parent items

0 commit comments

Comments
 (0)