|
2 | 2 |
|
3 | 3 | The `<sp-tabs>` displays a list of `<sp-tab>` element children as `role="tablist"`. An `<sp-tab>` element is associated with a sibling `<sp-tab-panel>` element via their `value` attribute. When an `<sp-tab>` element is `selected`, the associated `<sp-tab-panel>` will also be selected, showing that panel and hiding the others.
|
4 | 4 |
|
| 5 | +[View the design documentation for this component.](https://spectrum.adobe.com/page/tabs/) |
| 6 | + |
5 | 7 | ### Usage
|
6 | 8 |
|
7 | 9 | [](https://www.npmjs.com/package/@spectrum-web-components/tabs)
|
8 | 10 | [](https://bundlephobia.com/result?p=@spectrum-web-components/tabs)
|
9 | 11 | [](https://stackblitz.com/edit/vitejs-vite-3smxuwr2)
|
10 | 12 |
|
11 |
| -``` |
| 13 | +```zsh |
12 | 14 | yarn add @spectrum-web-components/tabs
|
13 | 15 | ```
|
14 | 16 |
|
15 | 17 | Import the side effectful registration of `<sp-tabs>`, `<sp-tab>` or `<sp-tab-panel>` via:
|
16 | 18 |
|
17 |
| -``` |
| 19 | +```ts |
18 | 20 | import '@spectrum-web-components/tabs/sp-tabs.js';
|
19 | 21 | import '@spectrum-web-components/tabs/sp-tab.js';
|
20 | 22 | import '@spectrum-web-components/tabs/sp-tab-panel.js';
|
21 | 23 | ```
|
22 | 24 |
|
23 | 25 | When looking to leverage the `Tabs`, `Tab`, or `TabPanel` base class as a type and/or for extension purposes, do so via:
|
24 | 26 |
|
25 |
| -``` |
26 |
| -import { |
27 |
| - Tabs, |
28 |
| - Tab, |
29 |
| - TabPanel |
30 |
| -} from '@spectrum-web-components/tabs'; |
| 27 | +```ts |
| 28 | +import { Tabs, Tab, TabPanel } from '@spectrum-web-components/tabs'; |
31 | 29 | ```
|
32 | 30 |
|
33 |
| -## Sizes |
| 31 | +### Anatomy |
| 32 | + |
| 33 | +- **Tabs:** The container component (`<sp-tabs>`) that manages the tab list and handles selection logic. |
| 34 | +- **Tab item:** An individual tab (`<sp-tab>`) that users can select to view different content panels. |
| 35 | +- **Tab view:** The content panel (`<sp-tab-panel>`) associated with a tab, shown when its corresponding tab is selected. |
| 36 | +- **Divider:** A visual separator between tab items, used in some variants for clarity. |
| 37 | +- **Selection indicator:** A visual highlight (such as an underline or bar) that shows which tab is currently selected. |
| 38 | + |
| 39 | +## Options |
| 40 | + |
| 41 | +<sp-table> |
| 42 | + <sp-table-head> |
| 43 | + <sp-table-head-cell>Property</sp-table-head-cell> |
| 44 | + <sp-table-head-cell>Values</sp-table-head-cell> |
| 45 | + <sp-table-head-cell>Default value</sp-table-head-cell> |
| 46 | + </sp-table-head> |
| 47 | + <sp-table-body> |
| 48 | + <sp-table-row> |
| 49 | + <sp-table-cell>label</sp-table-cell> |
| 50 | + <sp-table-cell>text / nothing</sp-table-cell> |
| 51 | + <sp-table-cell>–</sp-table-cell> |
| 52 | + </sp-table-row> |
| 53 | + <sp-table-row> |
| 54 | + <sp-table-cell>icon</sp-table-cell> |
| 55 | + <sp-table-cell>icon / nothing</sp-table-cell> |
| 56 | + <sp-table-cell>nothing</sp-table-cell> |
| 57 | + </sp-table-row> |
| 58 | + <sp-table-row> |
| 59 | + <sp-table-cell>is selected</sp-table-cell> |
| 60 | + <sp-table-cell>yes / no</sp-table-cell> |
| 61 | + <sp-table-cell>no</sp-table-cell> |
| 62 | + </sp-table-row> |
| 63 | + <sp-table-row> |
| 64 | + <sp-table-cell>is disabled</sp-table-cell> |
| 65 | + <sp-table-cell>yes / no</sp-table-cell> |
| 66 | + <sp-table-cell>no</sp-table-cell> |
| 67 | + </sp-table-row> |
| 68 | + </sp-table-body> |
| 69 | +</sp-table> |
| 70 | +<br/> |
| 71 | + |
| 72 | +### Variants |
| 73 | + |
| 74 | +### Sizes |
34 | 75 |
|
35 | 76 | <sp-tabs selected="m" auto label="Size Attribute Options">
|
36 | 77 | <sp-tab value="s">Small</sp-tab>
|
@@ -103,7 +144,7 @@ import {
|
103 | 144 | </sp-tab-panel>
|
104 | 145 | </sp-tabs>
|
105 | 146 |
|
106 |
| -## Horizontal Tabs |
| 147 | +### Horizontal Tabs |
107 | 148 |
|
108 | 149 | An `<sp-tabs>` element will display horizontally by default. It can be modified with states like `compact`, `disabled`, and `quiet`, or with content like icons, etc.
|
109 | 150 |
|
@@ -207,7 +248,7 @@ When an `<sp-tabs>` element is given the `disabled` attribute its `<sp-tab>` chi
|
207 | 248 | </sp-tab-panel>
|
208 | 249 | </sp-tabs>
|
209 | 250 |
|
210 |
| -## Vertical Tabs |
| 251 | +### Vertical Tabs |
211 | 252 |
|
212 | 253 | An `<sp-tabs>` element will display horizontally by default. It can be modified with states like `compact`, `disabled`, and `quiet`, or with content like icons, etc.
|
213 | 254 |
|
@@ -314,3 +355,5 @@ When an `<sp-tabs>` element is given the `disabled` attribute its `<sp-tab>` chi
|
314 | 355 | ## Accessibility
|
315 | 356 |
|
316 | 357 | When an `<sp-tabs>` has a `selected` value, the `<sp-tab>` child of that `value` will be given `[tabindex="0"]` and will receive initial focus when tabbing into the `<sp-tabs>` element. When no `selected` value is present, the first `<sp-tab>` child will be treated in this way. When focus is currently within the `<sp-tabs>` element, the left and right arrows will move that focus back and forth through the available `<sp-tab>` children.
|
| 358 | + |
| 359 | +Tab items should have a label for accessibility. If a label isn’t present, it must include an icon and becomes an icon-only tab item. Icons should only be used in a tab item when absolutely necessary: when adding essential value and having a strong association with the label. If the tab item does not have a visible label, it must still have a tooltip to disclose the label. |
0 commit comments