Skip to content

Commit dbfe680

Browse files
docs(sidenav): update sidenav-item docs
1 parent 475f4cd commit dbfe680

File tree

1 file changed

+248
-11
lines changed

1 file changed

+248
-11
lines changed

packages/sidenav/sidenav-item.md

Lines changed: 248 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,58 @@
1-
## Description
1+
## Overview
22

3-
An `<sp-sidenav-item>` stands as both a child item of an `<sp-sidenav>` element, as well as a parent for further subdivisions of that navigation. An `<sp-sidenav-item>` with further `<sp-sidenav-item>` children will count as a toggle for the visibility of this next level of navigation items, while also updating the parent `<sp-sidenav>` element to its value when selected.
3+
An `<sp-sidenav-item>` can act as both a child item of an `<sp-sidenav>` element, as well as a parent for further subdivisions of that navigation. An `<sp-sidenav-item>` with further `<sp-sidenav-item>` children will count as a toggle for the visibility of the next level of navigation items, while also updating the parent `<sp-sidenav>` element to its value when selected.
44

55
### Usage
66

77
[![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)
88
[![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)
99

10-
```
10+
```bash
1111
yarn add @spectrum-web-components/sidenav
1212
```
1313

1414
Import the side effectful registration of `<sp-sidenav-item>` via:
1515

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

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

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

26-
## Example
26+
### Anatomy
27+
28+
- **Label**: Text content of the navigation item
29+
- **Value**: Unique identifier; required for selection changes via the `sidenav-select` event
30+
- **href** (optional): When defined, renders the side nav item as an anchor link
31+
- **Default slot**: Nested `sp-sidenav-items`
32+
33+
### Options
34+
35+
<sp-tabs selected="default" auto label="Side nav item options">
36+
<sp-tab value="default">Default</sp-tab>
37+
<sp-tab-panel value="default">
38+
39+
Most often, the default side nav item includes an `href` to navigate users to a new page or section.
2740

2841
```html
2942
<sp-sidenav>
3043
<sp-sidenav-item
31-
value="Docs"
32-
label="Docs"
44+
value="pixar"
45+
label="Pixar movies"
3346
href="/components/sidenav"
3447
></sp-sidenav-item>
3548
</sp-sidenav>
3649
```
3750

38-
## Multi-level
51+
</sp-tab-panel>
52+
<sp-tab value="multi-level">Multi-level</sp-tab>
53+
<sp-tab-panel value="multi-level">
54+
55+
To create a multi-level navigation, set the parent `<sp-sidenav>` to `variant="multilevel"` and nest `sp-sidenav-item` elements inside each other. Parent `sp-sidenav-item` elements that contain children can use the `expanded` attribute to show and hide their nested items. Each `sp-sidenav-item` with nested children acts as both a selectable navigation item (with its own value) and a toggle for expanding/collapsing its children.
3956

4057
```html
4158
<sp-sidenav variant="multilevel">
@@ -54,12 +71,232 @@ import { SidenavItem } from '@spectrum-web-components/sidenav';
5471
</sp-sidenav-itm>
5572
```
5673

57-
## Icon
74+
</sp-tab-panel>
75+
<sp-tab value="icons">Accommodating icons</sp-tab>
76+
<sp-tab-panel value="icons">
77+
78+
Icons can be displayed in first-level items of any type of side navigation (single level or multi-level). Use icons only when absolutely necessary: when they add essential value and have a strong association with the text. Never use icons just as decoration.
5879

5980
```html
6081
<sp-sidenav>
61-
<sp-sidenav-item value="Section Title 1" label="Section Title 1">
82+
<sp-sidenav-item value="star" label="Starred">
6283
<sp-icon-star slot="icon"></sp-icon-star>
6384
</sp-sidenav-item>
85+
<sp-sidenav-item value="home" label="Home">
86+
<sp-icon-home slot="icon"></sp-icon-home>
87+
</sp-sidenav-item>
88+
</sp-sidenav>
89+
```
90+
91+
</sp-tab-panel>
92+
<sp-tab value="target">Target</sp-tab>
93+
<sp-tab-panel value="target">
94+
95+
The `target` property specifies where to display the linked URL, such as in a new tab (`_blank`), parent frame (`_parent`), same frame (`_self`), or top frame (`_top`). It only applies when the sidenav item has an `href` attribute and functions like a standard HTML anchor link.
96+
97+
```html
98+
<sp-sidenav>
99+
<sp-sidenav-item
100+
value="pixar"
101+
label="Pixar movies"
102+
href="/components/sidenav"
103+
target="_blank"
104+
></sp-sidenav-item>
105+
</sp-sidenav>
106+
```
107+
108+
</sp-tab-panel>
109+
<sp-tab value="download">Download</sp-tab>
110+
<sp-tab-panel value="download">
111+
112+
When set, the `download` property causes the browser to treat the linked URL as a downloadable file, rather than navigating to it. It works in conjunction with the `href` attribute to trigger file downloads when the sidenav item is clicked.
113+
114+
```html
115+
<sp-sidenav>
116+
<sp-sidenav-item
117+
value="pixar"
118+
label="Pixar movies"
119+
href="/components/sidenav"
120+
download
121+
></sp-sidenav-item>
122+
</sp-sidenav>
123+
```
124+
125+
</sp-tab-panel>
126+
<sp-tab value="rel">Rel</sp-tab>
127+
<sp-tab-panel value="rel">
128+
129+
The `rel` property defines the relationship between the current page and the linked URL using space-separated link types (like `nofollow`, `noreferrer`, or `external`). It provides semantic information to browsers and search engines about the nature of the link relationship.
130+
131+
```html
132+
<sp-sidenav>
133+
<sp-sidenav-item
134+
value="pixar"
135+
label="Pixar movies"
136+
href="/components/sidenav"
137+
rel="noreferrer"
138+
></sp-sidenav-item>
139+
</sp-sidenav>
140+
```
141+
142+
</sp-tab-panel>
143+
<sp-tab value="referrer-policy">Referrer policy</sp-tab>
144+
<sp-tab-panel value="referrer-policy">
145+
146+
Setting `referrer-policy` will control how much referrer information is sent when following the link, with options ranging from no referrer (`no-referrer`) to full URL (`unsafe-url`).
147+
148+
```html
149+
<sp-sidenav>
150+
<sp-sidenav-item
151+
value="pixar"
152+
label="Pixar movies"
153+
href="/components/sidenav"
154+
referrerpolicy="no-referrer"
155+
></sp-sidenav-item>
156+
</sp-sidenav>
157+
```
158+
159+
</sp-tab-panel>
160+
</sp-tabs>
161+
162+
### States
163+
164+
<sp-tabs selected="disabled" auto label="Side nav item states">
165+
<sp-tab value="disabled">Disabled</sp-tab>
166+
<sp-tab-panel value="disabled">
167+
168+
Adding the `disabled` attribute to a side nav item renders it non-interactive.
169+
170+
```html
171+
<sp-sidenav>
172+
<sp-sidenav-item
173+
value="toy-story"
174+
label="Toy Story"
175+
disabled
176+
></sp-sidenav-item>
177+
<sp-sidenav-item
178+
value="monsters-inc"
179+
label="Monsters, Inc."
180+
></sp-sidenav-item>
181+
<sp-sidenav-item
182+
value="incredibles"
183+
label="The Incredibles"
184+
></sp-sidenav-item>
185+
<sp-sidenav-item value="up" label="Up" disabled></sp-sidenav-item>
186+
</sp-sidenav>
187+
```
188+
189+
</sp-tab-panel>
190+
<sp-tab value="expanded">Expanded</sp-tab>
191+
<sp-tab-panel value="expanded">
192+
193+
Adding `expanded` to an `sp-sidenav-item` will render it as expanded if it has subsequent child items.
194+
195+
```html
196+
<sp-sidenav>
197+
<sp-sidenav-item value="toy-story" label="Toy Story" expanded>
198+
<sp-sidenav-item
199+
value="toy-story-2"
200+
label="Toy Story 2"
201+
></sp-sidenav-item>
202+
<sp-sidenav-item
203+
value="toy-story-3"
204+
label="Toy Story 3"
205+
></sp-sidenav-item>
206+
<sp-sidenav-item
207+
value="toy-story-4"
208+
label="Toy Story 4"
209+
></sp-sidenav-item>
210+
</sp-sidenav-item>
211+
<sp-sidenav-item
212+
value="monsters-inc"
213+
label="Monsters, Inc."
214+
></sp-sidenav-item>
215+
<sp-sidenav-item
216+
value="incredibles"
217+
label="The Incredibles"
218+
></sp-sidenav-item>
219+
<sp-sidenav-item value="up" label="Up"></sp-sidenav-item>
220+
</sp-sidenav>
221+
```
222+
223+
</sp-tab-panel>
224+
<sp-tab value="selected">Selected</sp-tab>
225+
<sp-tab-panel value="selected">
226+
227+
When users select an item, the `selected` attribute is applied. The `value` of the selected item will be bubbled up to the parent `sp-sidenav` to update the `value` of `sp-sidenav`.
228+
229+
```html
230+
<sp-sidenav value="wall-e">
231+
<sp-sidenav-item value="toy-story" label="Toy Story">
232+
<sp-sidenav-item
233+
value="toy-story-2"
234+
label="Toy Story 2"
235+
></sp-sidenav-item>
236+
<sp-sidenav-item
237+
value="toy-story-3"
238+
label="Toy Story 3"
239+
></sp-sidenav-item>
240+
<sp-sidenav-item
241+
value="toy-story-4"
242+
label="Toy Story 4"
243+
></sp-sidenav-item>
244+
</sp-sidenav-item>
245+
<sp-sidenav-item
246+
value="monsters-inc"
247+
label="Monsters, Inc."
248+
></sp-sidenav-item>
249+
<sp-sidenav-item
250+
value="incredibles"
251+
label="The Incredibles"
252+
></sp-sidenav-item>
253+
<sp-sidenav-item
254+
value="up"
255+
label="Up"
256+
></sp-sidenav-item>
257+
<sp-sidenav-item
258+
value="wall-e"
259+
label="Wall-E"
260+
selected
261+
></sp-sidenav-item>
64262
</sp-sidenav>
65263
```
264+
265+
</sp-tab-panel>
266+
</sp-tabs>
267+
268+
### Behaviors
269+
270+
When the side navigation item text is too long for the horizontal space available, it wraps to form another line.
271+
272+
For RTL (right-to-left) languages, the layout of the side navigation is mirrored. Navigation items are left-aligned and their icons are placed on the right side of the text.
273+
274+
When users select an `sp-sidenav-item`, the change in the `value` property of the parent side navigation element is announced. This change can be "canceled" via `event.preventDefault()`.
275+
276+
When `manage-tab-index` is enabled on the parent side nav, expanded parent side nav items that aren't selected lose focus to prevent focus traps.
277+
278+
### Accessibility
279+
280+
#### ARIA attributes
281+
282+
- Individual items use `role="listitem"` automatically
283+
- Nested list containers (i.e. `div` tags) use `role="list"`
284+
- Nested item containers use `aria-labelledby` referencing their parent item's `id`
285+
- `aria-expanded="true/false"` indicates expand/collapse state for parent side nav items
286+
- `aria-controls` on parent items is set to the `id` of their child `role="list"` containers when expanded
287+
- `aria-current="page"` indicates the currently selected item when it has an `href`
288+
- `aria-hidden="true"` should be applied to all decorative icons
289+
290+
#### Keyboard interactions
291+
292+
**Standard navigation:** (when parent side nav has `manage-tab-index` disabled)
293+
294+
- `Tab` moves focus to individual items
295+
- `Enter` or `Space` select a focused item or toggle the expansion of any nested side nav items
296+
297+
**Roving `tabindex` mode** (when parent side nav has `manage-tab-index="true"`):
298+
299+
- The parent `sp-sidenav` component is the single tab-stop
300+
- `Up` and `Down` arrow keys navigate between all visible side nav items
301+
- `Home` and `End` keys jump to first/last items respectively
302+
- `Enter` or `Space` select a focused item or toggle the expansion of any nested side nav items

0 commit comments

Comments
 (0)