| 1 |
(sd-tabs)= |
| 2 |
|
| 3 |
# Tabs |
| 4 |
|
| 5 |
Tabs organize and allow navigation between groups of content that are related and at the same level of hierarchy. |
| 6 |
Each tab should contain content that is distinct from other tabs in a set. |
| 7 |
|
| 8 |
::::{tab-set} |
| 9 |
|
| 10 |
:::{tab-item} Label1 |
| 11 |
Content 1 |
| 12 |
::: |
| 13 |
|
| 14 |
:::{tab-item} Label2 |
| 15 |
Content 2 |
| 16 |
::: |
| 17 |
|
| 18 |
:::: |
| 19 |
|
| 20 |
`````{dropdown-syntax} |
| 21 |
|
| 22 |
````{tab-set-code} |
| 23 |
```{literalinclude} ./snippets/myst/tab-basic.txt |
| 24 |
:language: markdown |
| 25 |
``` |
| 26 |
```{literalinclude} ./snippets/rst/tab-basic.txt |
| 27 |
:language: rst |
| 28 |
``` |
| 29 |
```` |
| 30 |
````` |
| 31 |
|
| 32 |
See the [Material Design](https://material.io/components/tabs) description for further details. |
| 33 |
|
| 34 |
## Synchronised Tabs |
| 35 |
|
| 36 |
The Selection of tab items can be synchronised across multiple tab-sets. |
| 37 |
For a `tab-item` to be synchronisable, add the `sync` option to the `tab-item` directive with a key unique to that set. |
| 38 |
Now when you select a tab in one set, tabs in other sets with the same key will be selected. |
| 39 |
|
| 40 |
:::{note} |
| 41 |
Synchronisation requires that JavaScript is enabled. |
| 42 |
::: |
| 43 |
|
| 44 |
:::{versionadded} 0.6.0 |
| 45 |
To synchronise tabs only across certain tab-sets, add the `:sync-group:` option to each `tab-set` directive with the same group name, such as `:sync-group: category`. |
| 46 |
|
| 47 |
You can also add an [HTML query string](https://en.wikipedia.org/wiki/Query_string) to the end of the page's URL, |
| 48 |
to automatically select a tab with a specific key across all tab-sets of the group, for example: |
| 49 |
|
| 50 |
- [`?category=key1#synchronised-tabs`](?category=key1#synchronised-tabs){.external} |
| 51 |
- [`?category=key2#synchronised-tabs`](?category=key2#synchronised-tabs){.external} |
| 52 |
::: |
| 53 |
|
| 54 |
::::{tab-set} |
| 55 |
:sync-group: category |
| 56 |
|
| 57 |
:::{tab-item} Label1 |
| 58 |
:sync: key1 |
| 59 |
|
| 60 |
Content 1 |
| 61 |
::: |
| 62 |
|
| 63 |
:::{tab-item} Label2 |
| 64 |
:sync: key2 |
| 65 |
|
| 66 |
Content 2 |
| 67 |
::: |
| 68 |
|
| 69 |
:::: |
| 70 |
|
| 71 |
::::{tab-set} |
| 72 |
:sync-group: category |
| 73 |
|
| 74 |
:::{tab-item} Label1 |
| 75 |
:sync: key1 |
| 76 |
|
| 77 |
Content 1 |
| 78 |
::: |
| 79 |
|
| 80 |
:::{tab-item} Label2 |
| 81 |
:sync: key2 |
| 82 |
|
| 83 |
Content 2 |
| 84 |
::: |
| 85 |
|
| 86 |
:::: |
| 87 |
|
| 88 |
`````{dropdown-syntax} |
| 89 |
|
| 90 |
````{tab-set-code} |
| 91 |
```{literalinclude} ./snippets/myst/tab-sync.txt |
| 92 |
:language: markdown |
| 93 |
``` |
| 94 |
```{literalinclude} ./snippets/rst/tab-sync.txt |
| 95 |
:language: rst |
| 96 |
``` |
| 97 |
```` |
| 98 |
````` |
| 99 |
|
| 100 |
## Tabbed code examples |
| 101 |
|
| 102 |
The `tab-set-code` directive provides a shorthand for synced code examples. |
| 103 |
You can place any directives in a `tab-set-code` that produce a `literal_block` node with a `language` attribute, for example `code`, `code-block` and `literalinclude`. |
| 104 |
Tabs will be labelled and synchronised by the `language` attribute (in upper-case). |
| 105 |
|
| 106 |
:::{versionadded} 0.6.0 |
| 107 |
You can also add an [HTML query string](https://en.wikipedia.org/wiki/Query_string) to the end of the page's URL, |
| 108 |
to automatically select a tab with a specific code across all tab-sets of the group, for example: |
| 109 |
|
| 110 |
- [`?code=markdown#tabbed-code-examples`](?code=markdown#tabbed-code-examples){.external} |
| 111 |
- [`?code=rst#tabbed-code-examples`](?code=rst#tabbed-code-examples){.external} |
| 112 |
::: |
| 113 |
|
| 114 |
```````{tab-set} |
| 115 |
:sync-group: code |
| 116 |
|
| 117 |
``````{tab-item} Markdown |
| 118 |
:sync: markdown |
| 119 |
|
| 120 |
````{literalinclude} ./snippets/myst/tab-code-set.txt |
| 121 |
:language: markdown |
| 122 |
```` |
| 123 |
`````` |
| 124 |
|
| 125 |
``````{tab-item} RST |
| 126 |
:sync: rst |
| 127 |
|
| 128 |
````{literalinclude} ./snippets/rst/tab-code-set.txt |
| 129 |
:language: rst |
| 130 |
```` |
| 131 |
`````` |
| 132 |
|
| 133 |
``````` |
| 134 |
|
| 135 |
## Tabs in other components |
| 136 |
|
| 137 |
Tabs can be nested inside other components, such as inside [dropdowns](./dropdowns.md) or within [grid items](./grids.md). |
| 138 |
|
| 139 |
:::::{dropdown} Tabs in dropdown |
| 140 |
:open: |
| 141 |
|
| 142 |
Paragraph |
| 143 |
|
| 144 |
::::{tab-set} |
| 145 |
|
| 146 |
:::{tab-item} Label1 |
| 147 |
:sync: label-1 |
| 148 |
|
| 149 |
Content 1 |
| 150 |
::: |
| 151 |
|
| 152 |
:::{tab-item} Label2 |
| 153 |
:sync: label-2 |
| 154 |
|
| 155 |
Content 2 |
| 156 |
::: |
| 157 |
|
| 158 |
:::: |
| 159 |
::::: |
| 160 |
|
| 161 |
::::::{grid} 1 1 2 2 |
| 162 |
|
| 163 |
:::::{grid-item} |
| 164 |
:outline: |
| 165 |
|
| 166 |
Initial paragraph |
| 167 |
|
| 168 |
::::{tab-set} |
| 169 |
|
| 170 |
:::{tab-item} Label1 |
| 171 |
:sync: label-1 |
| 172 |
|
| 173 |
Content 1 |
| 174 |
::: |
| 175 |
|
| 176 |
:::{tab-item} Label2 |
| 177 |
:sync: label-2 |
| 178 |
|
| 179 |
Content 2 |
| 180 |
::: |
| 181 |
|
| 182 |
:::: |
| 183 |
|
| 184 |
::::: |
| 185 |
|
| 186 |
:::::{grid-item} |
| 187 |
:outline: |
| 188 |
|
| 189 |
::::{tab-set} |
| 190 |
|
| 191 |
:::{tab-item} Label1 |
| 192 |
:sync: label-1 |
| 193 |
|
| 194 |
Content 1 |
| 195 |
::: |
| 196 |
|
| 197 |
:::{tab-item} Label2 |
| 198 |
:sync: label-2 |
| 199 |
|
| 200 |
Content 2 |
| 201 |
::: |
| 202 |
|
| 203 |
:::: |
| 204 |
|
| 205 |
Ending paragraph |
| 206 |
|
| 207 |
::::: |
| 208 |
|
| 209 |
:::::: |
| 210 |
|
| 211 |
Tab set, within tab set: |
| 212 |
|
| 213 |
::::::{tab-set} |
| 214 |
:::::{tab-item} Label 1 |
| 215 |
::::{tab-set} |
| 216 |
:::{tab-item} Label 1a |
| 217 |
Content 1a |
| 218 |
::: |
| 219 |
:::{tab-item} Label 1b |
| 220 |
Content 1b |
| 221 |
::: |
| 222 |
:::: |
| 223 |
::::: |
| 224 |
:::::{tab-item} Label 2 |
| 225 |
Content 2 |
| 226 |
::::: |
| 227 |
:::::: |
| 228 |
|
| 229 |
## `tab-set` options |
| 230 |
|
| 231 |
sync-group |
| 232 |
: A group name for synchronised tab sets (default `tab`). |
| 233 |
|
| 234 |
class |
| 235 |
: Additional CSS classes for the container element. |
| 236 |
|
| 237 |
## `tab-set-code` options |
| 238 |
|
| 239 |
no-sync |
| 240 |
: Disable synchronisation of tabs. |
| 241 |
|
| 242 |
sync-group |
| 243 |
: A group name for synchronised tab sets (default `code`). |
| 244 |
|
| 245 |
class-set |
| 246 |
: Additional CSS classes for the set container element. |
| 247 |
|
| 248 |
class-item |
| 249 |
: Additional CSS classes for the item container element. |
| 250 |
|
| 251 |
## `tab-item` options |
| 252 |
|
| 253 |
selected |
| 254 |
: a flag indicating whether the tab should be selected by default. |
| 255 |
|
| 256 |
sync |
| 257 |
: A key that is used to sync the selected tab across multiple tab-sets. |
| 258 |
|
| 259 |
name |
| 260 |
: Set a reference-able name for the dropdown container. |
| 261 |
|
| 262 |
class-container |
| 263 |
: Additional CSS classes for the container element. |
| 264 |
|
| 265 |
class-label |
| 266 |
: Additional CSS classes for the label element. |
| 267 |
|
| 268 |
class-content |
| 269 |
: Additional CSS classes for the content element. |