|
1 |
| -from dash import Dash, html, dcc, callback, Output, Input |
| 1 | +from dash import Dash, html, dcc, callback, Output, Input, State |
2 | 2 |
|
3 | 3 | import dash.testing.wait as wait
|
4 | 4 | import time
|
@@ -55,20 +55,27 @@ def test_clp002_clipboard_text(dash_dcc_headed):
|
55 | 55 | timeout=3,
|
56 | 56 | )
|
57 | 57 |
|
| 58 | + |
58 | 59 | def test_clp003_clipboard_text(dash_dcc_headed):
|
59 | 60 | copy_text = "Copy this text to the clipboard using a separate button"
|
60 | 61 | app = Dash(__name__, prevent_initial_callbacks=True)
|
61 | 62 | app.layout = html.Div(
|
62 |
| - [dcc.Clipboard(id="copy_icon", content=copy_text), dcc.Textarea(id="paste"), html.Button("Copy", id="copy_button")] |
| 63 | + [ |
| 64 | + dcc.Clipboard(id="copy_icon", content=copy_text), |
| 65 | + dcc.Textarea(id="paste"), |
| 66 | + html.Button("Copy", id="copy_button"), |
| 67 | + ] |
63 | 68 | )
|
| 69 | + |
64 | 70 | @callback(
|
65 |
| - Output("copy_icon", "content"), |
| 71 | + Output("copy_icon", "n_clicks"), |
| 72 | + State("copy_icon", "n_clicks"), |
66 | 73 | Input("copy_button", "n_clicks"),
|
67 | 74 | prevent_initial_call=True,
|
68 | 75 | )
|
69 |
| - def selected(clicks): |
70 |
| - return f"{clicks}" |
71 |
| - |
| 76 | + def selected(icon_clicks, button_clicks): |
| 77 | + return icon_clicks + 1 |
| 78 | + |
72 | 79 | dash_dcc_headed.start_server(app)
|
73 | 80 |
|
74 | 81 | dash_dcc_headed.find_element("#copy_button").click()
|
|
0 commit comments