Add a note to the docs about styling tabs

Note that I can't tell if this comes out as I'd like, as right at the moment
I can't locally serve the docs due to an error during documentation
generation (an issue confirmed by @rodrigogiraoserrao).
This commit is contained in:
Dave Pearson
2023-12-07 15:02:39 +00:00
parent 1e472d54e9
commit 758547b5dd
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
from textual.app import App, ComposeResult
from textual.widgets import Label, TabbedContent, TabPane
class ColorTabsApp(App):
CSS = """
TabbedContent #--content-tab-green {
color: green;
}
TabbedContent #--content-tab-red {
color: red;
}
"""
def compose(self) -> ComposeResult:
with TabbedContent():
with TabPane("Red", id="red"):
yield Label("Red!")
with TabPane("Green", id="green"):
yield Label("Green!")
if __name__ == "__main__":
ColorTabsApp().run()

View File

@@ -94,6 +94,30 @@ The following example contains a `TabbedContent` with three tabs.
--8<-- "docs/examples/widgets/tabbed_content.py"
```
## Styling
The `TabbedContent` widget is composed of two main sub-widgets: a
[`Tabs`](tabs.md) and a [`ContentSwitcher`]((content_switcher.md)); you can
style them accordingly.
The tabs within the `Tabs` widget will have prefixed IDs; each ID being the
ID of the `TabPane` the `Tab` is for, prefixed with `--content-tab-`. If you
wish to style individual tabs within the `TabbedContent` widget you will
need to use that prefix for the `Tab` IDs.
For example, to create a `TabbedContent` that has red and green labels:
=== "Output"
```{.textual path="docs/examples/widgets/tabbed_content_label_color.py"}
```
=== "tabbed_content.py"
```python
--8<-- "docs/examples/widgets/tabbed_content_label_color.py"
```
## Reactive Attributes
| Name | Type | Default | Description |