Skip to content

Commit 9606086

Browse files
glsdowntcbegley
andauthored
Popover fixes (#757)
* Fix issue related to legacy trigger * Fix support for hide_arrow * Add in support for offset * Improve tests * Bump react-bootstrap version * Format * Add additional popover examples * Change default body behaviour * Add legacy integration test * Improve popover doc examples * Format * Update dependencies * Remove redundant Jest config * Set rootClose to false if legacy trigger removed * Remove rogue comma * Fix popover tests Co-authored-by: tcbegley <tomcbegley@gmail.com>
1 parent 09b6dd9 commit 9606086

File tree

21 files changed

+11241
-11032
lines changed

21 files changed

+11241
-11032
lines changed

docs/components_page/components/popover.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ lead: Use the Popover component to add Bootstrap popovers to any component in yo
55

66
## Examples
77

8-
To use `Popover`, add it to your layout, and set the `target` argument to the `id` of the component you would like to attach the popover to. The easiest way to trigger the popover is to specify the `trigger` property. This should be a string containing any of the following 4 values (space separated)
8+
To use `Popover`, add it to your layout, and set the `target` argument to the `id` of the component you would like to attach the popover to. You can add content to the popover quickly by specifying `body=True`, or make use of the `PopoverBody` (see below for more details).
9+
10+
{{example:components/popover/simple.py:popovers}}
11+
12+
## Trigger Types
13+
14+
The easiest way to trigger the popover is to specify the `trigger` property. This should be a string containing any of the following 4 values (space separated)
915

1016
* `"click"`: toggles the popover when the target is clicked.
1117
* `"focus"`: toggles the popover when the target receives focus
@@ -14,6 +20,12 @@ To use `Popover`, add it to your layout, and set the `target` argument to the `i
1420

1521
{{example:components/popover/popover.py:popovers}}
1622

23+
## Popover components
24+
25+
You can build a styled `Popover` by making use of the `PopoverHeader` and `PopoverBody`.
26+
27+
{{example:components/popover/popover_components.py:popovers}}
28+
1729
## Toggling the Popover with callbacks
1830

1931
Alternatively, you can manually control the appearance of the popover using callbacks by setting the `is_open` property of the `Popover`. This can be useful for example when you want to make the popover appear after the user interacts with something other than the target component as demonstrated in the below example.
@@ -26,6 +38,13 @@ Use the `placement` argument to control the placement of the `Popover`. The basi
2638

2739
{{example:components/popover/direction.py:popovers}}
2840

41+
## Styling
42+
43+
You can use `hide_arrow` to remove the arrow, and the `offset` property to offset the popover in relation to the target.
44+
45+
{{example:components/popover/styling.py:popovers}}
46+
47+
2948
{{apidoc:src/components/popover/Popover.js}}
3049

3150
{{apidoc:src/components/popover/PopoverHeader.js}}

docs/components_page/components/popover/popover.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
library(dashBootstrapComponents)
22

3-
popover_children <- list(
4-
dbcPopoverHeader("Popover header"),
5-
dbcPopoverBody("And here's some amazing content. Cool!")
6-
)
3+
popover_children <- "I am a popover!"
74

85
popovers <- div(
96
list(
@@ -14,8 +11,8 @@ popovers <- div(
1411
),
1512
dbcPopover(
1613
popover_children,
17-
id = "click",
1814
target = "click-target",
15+
body = TRUE,
1916
trigger = "click"
2017
),
2118
dbcButton(
@@ -25,8 +22,8 @@ popovers <- div(
2522
),
2623
dbcPopover(
2724
popover_children,
28-
id = "focus",
2925
target = "focus-target",
26+
body = TRUE,
3027
trigger = "focus"
3128
),
3229
dbcButton(
@@ -36,18 +33,18 @@ popovers <- div(
3633
),
3734
dbcPopover(
3835
popover_children,
39-
id = "hover",
4036
target = "hover-target",
41-
trigger = "hover",
37+
body = TRUE,
38+
trigger = "hover"
4239
),
4340
dbcButton("Legacy",
4441
id = "legacy-target", n_clicks = 0,
4542
color = "danger"
4643
),
4744
dbcPopover(
4845
popover_children,
49-
id = "legacy",
5046
target = "legacy-target",
47+
body = TRUE,
5148
trigger = "legacy"
5249
)
5350
)
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using DashBootstrapComponents, DashHtmlComponents
22

3-
popover_children = [
4-
dbc_popoverheader("Popover header"),
5-
dbc_popoverbody("And here's some amazing content. Cool!"),
6-
];
3+
popover_children = "I am a popover!";
74

85
popovers = html_div([
96
dbc_button(
@@ -13,28 +10,28 @@ popovers = html_div([
1310
className = "me-1",
1411
n_clicks = 0,
1512
),
16-
dbc_popover(popover_children, id = "click", target = "click-target", trigger = "click"),
13+
dbc_popover(popover_children, target = "click-target", body = true, trigger = "click"),
1714
dbc_button(
1815
"Focus",
1916
id = "focus-target",
2017
color = "danger",
2118
className = "me-1",
2219
n_clicks = 0,
2320
),
24-
dbc_popover(popover_children, id = "focus", target = "focus-target", trigger = "focus"),
21+
dbc_popover(popover_children, target = "focus-target", body = true, trigger = "focus"),
2522
dbc_button(
2623
"Hover",
2724
id = "hover-target",
2825
color = "danger",
2926
className = "me-1",
3027
n_clicks = 0,
3128
),
32-
dbc_popover(popover_children, id = "hover", target = "hover-target", trigger = "hover"),
29+
dbc_popover(popover_children, target = "hover-target", body = true, trigger = "hover"),
3330
dbc_button("Legacy", id = "legacy-target", color = "danger", n_clicks = 0),
3431
dbc_popover(
3532
popover_children,
36-
id = "legacy",
3733
target = "legacy-target",
34+
body = true,
3835
trigger = "legacy",
3936
),
4037
]);

docs/components_page/components/popover/popover.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import dash_bootstrap_components as dbc
22
from dash import html
33

4-
popover_children = [
5-
dbc.PopoverHeader("Popover header"),
6-
dbc.PopoverBody("And here's some amazing content. Cool!"),
7-
]
4+
popover_children = "I am a popover!"
85

96
popovers = html.Div(
107
[
@@ -17,8 +14,8 @@
1714
),
1815
dbc.Popover(
1916
popover_children,
20-
id="click",
2117
target="click-target",
18+
body=True,
2219
trigger="click",
2320
),
2421
dbc.Button(
@@ -30,8 +27,8 @@
3027
),
3128
dbc.Popover(
3229
popover_children,
33-
id="focus",
3430
target="focus-target",
31+
body=True,
3532
trigger="focus",
3633
),
3734
dbc.Button(
@@ -43,15 +40,15 @@
4340
),
4441
dbc.Popover(
4542
popover_children,
46-
id="hover",
4743
target="hover-target",
44+
body=True,
4845
trigger="hover",
4946
),
5047
dbc.Button("Legacy", id="legacy-target", color="danger", n_clicks=0),
5148
dbc.Popover(
5249
popover_children,
53-
id="legacy",
5450
target="legacy-target",
51+
body=True,
5552
trigger="legacy",
5653
),
5754
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
library(dashBootstrapComponents)
2+
3+
popovers <- div(
4+
list(
5+
dbcButton(
6+
"Click Me",
7+
id = "component-target", n_clicks = 0
8+
),
9+
dbcPopover(
10+
list(
11+
dbcPopoverHeader("Popover header"),
12+
dbcPopoverBody("And here's some amazing content. Cool!")
13+
),
14+
target = "component-target",
15+
trigger = "click"
16+
)
17+
)
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using DashBootstrapComponents, DashHtmlComponents
2+
3+
popovers = html_div([
4+
dbc_button("Click Me", id = "component-target", n_clicks = 0),
5+
dbc_popover(
6+
[
7+
dbc_popoverheader("Popover header"),
8+
dbc_popoverbody("And here's some amazing content. Cool!"),
9+
],
10+
target = "component-target",
11+
trigger = "click",
12+
),
13+
]);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import dash_bootstrap_components as dbc
2+
from dash import html
3+
4+
popovers = html.Div(
5+
[
6+
dbc.Button(
7+
"Click Me",
8+
id="component-target",
9+
n_clicks=0,
10+
),
11+
dbc.Popover(
12+
[
13+
dbc.PopoverHeader("Popover header"),
14+
dbc.PopoverBody("And here's some amazing content. Cool!"),
15+
],
16+
target="component-target",
17+
trigger="click",
18+
),
19+
]
20+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
library(dashBootstrapComponents)
2+
3+
popovers <- div(
4+
list(
5+
# First example - using dbcPopoverBody
6+
dbcButton(
7+
"popover-target",
8+
id = "popover-target",
9+
className = "me-1"
10+
),
11+
dbcPopover(
12+
dbcPopoverBody("My `target` is `popover-target`."),
13+
target = "popover-target",
14+
trigger = "click"
15+
),
16+
# Second example - using body=TRUE
17+
dbcButton(
18+
"popover-alt-target",
19+
id = "popover-alt-target",
20+
className = "me-1"
21+
),
22+
dbcPopover(
23+
"My `target` is `popover-alt-target`.",
24+
body = TRUE,
25+
target = "popover-alt-target",
26+
trigger = "click"
27+
)
28+
)
29+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using DashBootstrapComponents, DashHtmlComponents
2+
3+
popovers = html_div([
4+
# First example - using dbc_popoverbody
5+
dbc_button("popover-target", id = "popover-target", className = "me-1"),
6+
dbc_popover(
7+
dbc_popoverbody("My `target` is `popover-target`."),
8+
target = "popover-target",
9+
trigger = "click",
10+
),
11+
# Second example - using body=true
12+
dbc_button("popover-alt-target", id = "popover-alt-target", className = "me-1"),
13+
dbc_popover(
14+
"My `target` is `popover-alt-target`.",
15+
body = true,
16+
target = "popover-alt-target",
17+
trigger = "click",
18+
),
19+
])
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import dash_bootstrap_components as dbc
2+
from dash import html
3+
4+
popovers = html.Div(
5+
[
6+
# First example - using dbc.PopoverBody
7+
dbc.Button(
8+
"popover-target",
9+
id="popover-target",
10+
className="me-1",
11+
),
12+
dbc.Popover(
13+
dbc.PopoverBody("My `target` is `popover-target`."),
14+
target="popover-target",
15+
trigger="click",
16+
),
17+
# Second example - using body=True
18+
dbc.Button(
19+
"popover-alt-target",
20+
id="popover-alt-target",
21+
className="me-1",
22+
),
23+
dbc.Popover(
24+
"My `target` is `popover-alt-target`.",
25+
body=True,
26+
target="popover-alt-target",
27+
trigger="click",
28+
),
29+
]
30+
)

0 commit comments

Comments
 (0)