Skip to content

Commit 6793b36

Browse files
authored
Add labels with icons example to tabs docs (#1147)
1 parent 6637417 commit 6793b36

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

docs/components_page/components/tabs.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ To apply certain styles only to the currently active tab, you can use the `activ
3535

3636
{{example:components/tabs/active_style.py:tabs}}
3737

38+
## Labels with icons
39+
40+
Unfortunately it is currently only possible to use strings for tab labels, and not arbitrary Dash components. It is possible however to use some custom CSS to add icons to tabs as this example shows. If you try this yourself, make sure you [link the FontAwesome CSS](https://www.dash-bootstrap-components.com/docs/icons/).
41+
42+
```css
43+
#labelled-tabs .nav-item .nav-link::after {
44+
font-family: 'Font Awesome 6 Free';
45+
font-weight: 200;
46+
font-style: normal;
47+
margin: 0px 0px 0px 10px;
48+
text-decoration: none;
49+
}
50+
51+
#labelled-tabs .nav-item:nth-child(1) .nav-link::after {
52+
content: '\f005';
53+
}
54+
55+
#labelled-tabs .nav-item:nth-child(2) .nav-link::after {
56+
content: '\f2bd';
57+
}
58+
```
59+
60+
{{example:components/tabs/labels_with_icons.py:tabs}}
61+
3862
{{apidoc:src/components/tabs/Tabs.js}}
3963

4064
{{apidoc:src/components/tabs/Tab.js}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import dash_bootstrap_components as dbc
2+
from dash import html
3+
4+
tabs = dbc.Tabs(
5+
[
6+
dbc.Tab(
7+
html.Div("This is the content of tab 1", className="p-4"),
8+
label="Tab 1",
9+
),
10+
dbc.Tab(
11+
html.Div("This is the content of tab 2", className="p-4"),
12+
label="Tab 2",
13+
),
14+
],
15+
id="labelled-tabs",
16+
)

docs/static/docs.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ span.hljs-meta {
6565
}
6666

6767
.docs-sidebar .nav-link {
68-
color: var(--bs-body-color)
68+
color: var(--bs-body-color);
6969
padding: 0.3rem 0.5rem 0.3rem 1rem;
7070
border-left: 2px solid transparent;
7171
}
@@ -152,6 +152,23 @@ span.hljs-meta {
152152
outline: none;
153153
}
154154

155+
/* css for labelled tabs */
156+
#labelled-tabs .nav-item .nav-link::after {
157+
font-family: 'Font Awesome 6 Free';
158+
font-weight: 200;
159+
font-style: normal;
160+
margin: 0px 0px 0px 10px;
161+
text-decoration: none;
162+
}
163+
164+
#labelled-tabs .nav-item:nth-child(1) .nav-link::after {
165+
content: '\f005';
166+
}
167+
168+
#labelled-tabs .nav-item:nth-child(2) .nav-link::after {
169+
content: '\f2bd';
170+
}
171+
155172
/* radio button group example */
156173
.button-group-demo .radio-group .form-check {
157174
padding-left: 0;

docs/templates/partials/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
<link rel="stylesheet" href="/static/docs.css" />
99
<link rel="shortcut icon" type="image/x-icon" href="/static/images/favicon.ico" />
1010
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" />
11+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.7.2/css/all.css" />

0 commit comments

Comments
 (0)