Skip to content

Commit 1b87258

Browse files
glsdowntcbegley
andcommitted
Fix issues with Navbar examples (#667)
* Add inner container to navbar example * Remove extra div in Collapse/Fade layout * Adjust navbar examples * Docs example + formatting Co-authored-by: tcbegley <[email protected]>
1 parent 04ac302 commit 1b87258

File tree

9 files changed

+108
-126
lines changed

9 files changed

+108
-126
lines changed

docs/components_page/components/button_group/radios.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ button_group <- htmlDiv(
66
dbcRadioItems(
77
id = "radios",
88
class_name = "btn-group",
9-
input_class_name="btn-check",
9+
input_class_name = "btn-check",
1010
label_class_name = "btn btn-outline-primary",
1111
label_checked_class_name = "active",
1212
options = list(

docs/components_page/components/input/selected_styles.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ checklist <- htmlDiv(
1010
list(label = "Option 2", value = 2),
1111
list(label = "Option 3", value = 3)
1212
),
13-
label_checked_style=list("color" = "red"),
14-
input_checked_style=list(
15-
"backgroundColor" = "#fa7268",
16-
"borderColor" = "#ea6258"
13+
label_checked_style = list("color" = "red"),
14+
input_checked_style = list(
15+
"backgroundColor" = "#fa7268",
16+
"borderColor" = "#ea6258"
1717
)
1818
),
1919
htmlHr(),
2020
dbcRadioItems(
21-
id="radio-selected-style",
21+
id = "radio-selected-style",
2222
options = list(
2323
list(label = "Option 1", value = 1),
2424
list(label = "Option 2", value = 2),
2525
list(label = "Option 3", value = 3)
2626
),
27-
label_checked_class_name="text-success",
28-
input_checked_class_name="border border-success bg-success"
27+
label_checked_class_name = "text-success",
28+
input_checked_class_name = "border border-success bg-success"
2929
)
3030
)
3131
)

docs/components_page/components/navbar.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `NavbarSimple` will collapse on smaller screens, and add a toggle for reveal
1717

1818
## Navbar
1919

20-
If you want to have more control over the layout of your navbar you can use the `Navbar` component. This gives you full control over the children, but you will have to write your own callbacks to achieve things like the toggle behaviour on small screens. We recommend using a `Nav` component to wrap the navigation items, check the [docs here](/docs/components/nav).
20+
If you want to have more control over the layout of your navbar you can use the `Navbar` component. This gives you full control over the children, but you will have to write your own callbacks to achieve things like the toggle behaviour on small screens. From Bootstrap 5, all elements inside the `NavBar` should be contained within a [`Container`](/docs/components/layout). We also recommend using a `Nav` component to wrap the navigation items, check the [docs here](/docs/components/nav).
2121

2222
Here is an example of a custom navbar, see the `examples/` folder in the [GitHub repo](https://github.com/facultyai/dash-bootstrap-components/blob/main/examples/python/advanced-component-usage/navbars.py) for more.
2323

@@ -30,4 +30,3 @@ Here is an example of a custom navbar, see the `examples/` folder in the [GitHub
3030
{{apidoc:src/components/nav/NavbarBrand.js}}
3131

3232
{{apidoc:src/components/nav/NavbarToggler.js}}
33-

docs/components_page/components/navbar/navbar.R

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,37 @@ search_bar <- dbcRow(
1414
width = "auto"
1515
)
1616
),
17-
class_name = "ms-auto flex-nowrap mt-3 mt-md-0 g-0",
17+
class_name = "g-0 ms-auto flex-nowrap mt-3 mt-md-0",
1818
align = "center"
1919
)
2020

2121
navbar <- dbcNavbar(
22-
list(
23-
htmlA(
24-
# Use row and col to control vertical alignment of logo / brand
25-
dbcRow(
26-
list(
27-
dbcCol(htmlImg(src = PLOTLY_LOGO, height = "30px")),
28-
dbcCol(dbcNavbarBrand("Navbar", class_name = "ms-2"))
22+
dbcContainer(
23+
list(
24+
htmlA(
25+
# Use row and col to control vertical alignment of logo / brand
26+
dbcRow(
27+
list(
28+
dbcCol(htmlImg(src = PLOTLY_LOGO, height = "30px")),
29+
dbcCol(dbcNavbarBrand("Navbar", class_name = "ms-2"))
30+
),
31+
align = "center",
32+
class_name = "g-0"
2933
),
30-
align = "center",
31-
class_name = "g-0"
32-
),
33-
href = "https://plotly.com",
34-
style = list("textDecoration" = "none")
35-
),
36-
htmlDiv(
37-
list(
38-
dbcNavbarToggler(id = "navbar-toggler", n_clicks = 0),
39-
dbcCollapse(
40-
search_bar,
41-
id = "navbar-collapse",
42-
is_open = FALSE,
43-
navbar = TRUE
44-
)
34+
href = "https://plotly.com",
35+
style = list("textDecoration" = "none")
4536
),
46-
class_name = "ms-auto"
37+
dbcNavbarToggler(id = "navbar-toggler", n_clicks = 0),
38+
dbcCollapse(
39+
search_bar,
40+
id = "navbar-collapse",
41+
is_open = FALSE,
42+
navbar = TRUE
43+
)
4744
)
4845
),
4946
color = "dark",
50-
dark = TRUE,
51-
class_name = "py-2 px-3"
47+
dark = TRUE
5248
)
5349

5450

docs/components_page/components/navbar/navbar.jl

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ search_bar = dbc_row(
1010
width = "auto",
1111
),
1212
],
13-
class_name = "ms-auto flex-nowrap mt-3 mt-md-0 g-0",
13+
class_name = "g-0 ms-auto flex-nowrap mt-3 mt-md-0",
1414
align = "center",
1515
);
1616

1717
navbar = dbc_navbar(
18-
[
18+
dbc_container([
1919
html_a(
2020
# Use row and col to control vertical alignment of logo / brand
2121
dbc_row(
@@ -29,22 +29,11 @@ navbar = dbc_navbar(
2929
href = "https://plotly.com",
3030
style = Dict("textDecoration" => "none"),
3131
),
32-
html_div(
33-
[
34-
dbc_navbartoggler(id = "navbar-toggler", n_clicks = 0),
35-
dbc_collapse(
36-
search_bar,
37-
id = "navbar-collapse",
38-
is_open = false,
39-
navbar = true,
40-
),
41-
],
42-
class_name = "ms-auto",
43-
),
44-
],
32+
dbc_navbartoggler(id = "navbar-toggler", n_clicks = 0),
33+
dbc_collapse(search_bar, id = "navbar-collapse", is_open = false, navbar = true),
34+
]),
4535
color = "dark",
4636
dark = true,
47-
class_name = "py-2 px-3",
4837
)
4938

5039

docs/components_page/components/navbar/navbar.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,37 @@
1515
width="auto",
1616
),
1717
],
18-
class_name="ms-auto flex-nowrap mt-3 mt-md-0 g-0",
18+
class_name="g-0 ms-auto flex-nowrap mt-3 mt-md-0",
1919
align="center",
2020
)
2121

2222
navbar = dbc.Navbar(
23-
[
24-
html.A(
25-
# Use row and col to control vertical alignment of logo / brand
26-
dbc.Row(
27-
[
28-
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
29-
dbc.Col(dbc.NavbarBrand("Navbar", class_name="ms-2")),
30-
],
31-
align="center",
32-
class_name="g-0",
33-
),
34-
href="https://plotly.com",
35-
style={"textDecoration": "none"},
36-
),
37-
html.Div(
38-
[
39-
dbc.NavbarToggler(id="navbar-toggler", n_clicks=0),
40-
dbc.Collapse(
41-
search_bar,
42-
id="navbar-collapse",
43-
is_open=False,
44-
navbar=True,
23+
dbc.Container(
24+
[
25+
html.A(
26+
# Use row and col to control vertical alignment of logo / brand
27+
dbc.Row(
28+
[
29+
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
30+
dbc.Col(dbc.NavbarBrand("Navbar", class_name="ms-2")),
31+
],
32+
align="center",
33+
class_name="g-0",
4534
),
46-
],
47-
class_name="ms-auto",
48-
),
49-
],
35+
href="https://plotly.com",
36+
style={"textDecoration": "none"},
37+
),
38+
dbc.NavbarToggler(id="navbar-toggler", n_clicks=0),
39+
dbc.Collapse(
40+
search_bar,
41+
id="navbar-collapse",
42+
is_open=False,
43+
navbar=True,
44+
),
45+
]
46+
),
5047
color="dark",
5148
dark=True,
52-
class_name="py-2 px-3",
5349
)
5450

5551

examples/python/advanced-component-usage/navbars.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,36 @@
6464

6565
# this example that adds a logo to the navbar brand
6666
logo = dbc.Navbar(
67-
[
68-
html.A(
69-
# Use row and col to control vertical alignment of logo / brand
70-
dbc.Row(
71-
[
72-
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
73-
dbc.Col(dbc.NavbarBrand("Logo", class_name="ms-2")),
74-
],
75-
align="center",
76-
class_name="g-0",
67+
dbc.Container(
68+
[
69+
html.A(
70+
# Use row and col to control vertical alignment of logo / brand
71+
dbc.Row(
72+
[
73+
dbc.Col(html.Img(src=PLOTLY_LOGO, height="30px")),
74+
dbc.Col(dbc.NavbarBrand("Logo", class_name="ms-2")),
75+
],
76+
align="center",
77+
class_name="g-0",
78+
),
79+
href="https://plotly.com",
80+
style={"textDecoration": "none"},
7781
),
78-
href="https://plotly.com",
79-
style={"textDecoration": "none"},
80-
),
81-
html.Div(
82-
[
83-
dbc.NavbarToggler(id="navbar-toggler2", n_clicks=0),
84-
dbc.Collapse(
85-
dbc.Nav(
86-
[nav_item, dropdown], class_name="ms-auto", navbar=True
87-
),
88-
id="navbar-collapse2",
82+
dbc.NavbarToggler(id="navbar-toggler2", n_clicks=0),
83+
dbc.Collapse(
84+
dbc.Nav(
85+
[nav_item, dropdown],
86+
class_name="ms-auto",
8987
navbar=True,
9088
),
91-
],
92-
className="ms-auto",
93-
),
94-
],
89+
id="navbar-collapse2",
90+
navbar=True,
91+
),
92+
],
93+
),
9594
color="dark",
9695
dark=True,
97-
class_name="py-2 px-3 mb-5",
96+
class_name="mb-5",
9897
)
9998

10099
# this example has a search bar and button instead of navitems / dropdowns
@@ -136,17 +135,21 @@
136135

137136
# custom navbar based on https://getbootstrap.com/docs/4.1/examples/dashboard/
138137
dashboard = dbc.Navbar(
139-
[
140-
dbc.Col(dbc.NavbarBrand("Dashboard", href="#"), sm=3, md=2),
141-
dbc.Col(dbc.Input(type="search", placeholder="Search here")),
142-
dbc.Col(
143-
dbc.Nav(dbc.NavItem(dbc.NavLink("Sign out")), navbar=True),
144-
width="auto",
145-
),
146-
],
138+
dbc.Container(
139+
[
140+
dbc.Col(dbc.NavbarBrand("Dashboard", href="#"), sm=3, md=2),
141+
dbc.Col(dbc.Input(type="search", placeholder="Search here")),
142+
dbc.Col(
143+
dbc.Nav(
144+
dbc.Container(dbc.NavItem(dbc.NavLink("Sign out"))),
145+
navbar=True,
146+
),
147+
width="auto",
148+
),
149+
],
150+
),
147151
color="dark",
148152
dark=True,
149-
class_name="py-2 px-3",
150153
)
151154

152155
app.layout = html.Div(

src/components/collapse/Collapse.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import {omit} from 'ramda';
44
import RBCollapse from 'react-bootstrap/Collapse';
5-
import RBNavbarCollapse from 'react-bootstrap/NavbarCollapse';
65

76
/**
87
* Hide or show content with a vertical collapsing animation. Visibility of the
98
* children is controlled by the `is_open` prop which can be targetted by
109
* callbacks.
1110
*/
12-
const Collapse = props => {
11+
const Collapse = React.forwardRef((props, ref) => {
1312
const {
1413
children,
1514
is_open,
@@ -21,10 +20,8 @@ const Collapse = props => {
2120
...otherProps
2221
} = props;
2322

24-
const Component = navbar ? RBNavbarCollapse : RBCollapse;
25-
2623
return (
27-
<Component
24+
<RBCollapse
2825
in={is_open}
2926
as={tag}
3027
className={class_name || className}
@@ -33,10 +30,12 @@ const Collapse = props => {
3330
(loading_state && loading_state.is_loading) || undefined
3431
}
3532
>
36-
<div>{children}</div>
37-
</Component>
33+
<div ref={ref} className={navbar && 'navbar-collapse'}>
34+
{children}
35+
</div>
36+
</RBCollapse>
3837
);
39-
};
38+
});
4039

4140
Collapse.propTypes = {
4241
/**

src/components/fade/Fade.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import RBFade from 'react-bootstrap/Fade';
77
* Hide or show content with a fading animation. Visibility of the children is
88
* controlled by the `is_open` prop which can be targetted by callbacks.
99
*/
10-
const Fade = props => {
10+
const Fade = React.forwardRef((props, ref) => {
1111
const {
1212
children,
1313
is_in,
@@ -35,10 +35,10 @@ const Fade = props => {
3535
(loading_state && loading_state.is_loading) || undefined
3636
}
3737
>
38-
<div>{children}</div>
38+
<div ref={ref}>{children}</div>
3939
</RBFade>
4040
);
41-
};
41+
});
4242

4343
Fade.propTypes = {
4444
/**

0 commit comments

Comments
 (0)