|
| 1 | +from dash import Dash, Input, Output, State, html |
| 2 | + |
| 3 | + |
| 4 | +def test_dt001_div_tabindex_accept_string_and_number_type(dash_duo): |
| 5 | + app = Dash(__name__) |
| 6 | + app.layout = html.Div( |
| 7 | + [ |
| 8 | + html.Div(id="string-div", tabIndex="1"), |
| 9 | + html.Div(id="number-div", tabIndex=1), |
| 10 | + html.Button("string", id="trigger-string"), |
| 11 | + html.Button("number", id="trigger-number"), |
| 12 | + html.Pre(id="output-string-result"), |
| 13 | + html.Pre(id="output-number-result"), |
| 14 | + ], |
| 15 | + style={"padding": 50}, |
| 16 | + ) |
| 17 | + |
| 18 | + @app.callback( |
| 19 | + Output("output-string-result", "children"), |
| 20 | + Input("trigger-string", "n_clicks"), |
| 21 | + State("string-div", "tabIndex"), |
| 22 | + prevent_initial_call=True, |
| 23 | + ) |
| 24 | + def show_div_tabindex_string_type(n_clicks, tabindex): |
| 25 | + if n_clicks: |
| 26 | + if isinstance(tabindex, str): |
| 27 | + return "success" |
| 28 | + return "fail" |
| 29 | + |
| 30 | + @app.callback( |
| 31 | + Output("output-number-result", "children"), |
| 32 | + Input("trigger-number", "n_clicks"), |
| 33 | + State("number-div", "tabIndex"), |
| 34 | + prevent_initial_call=True, |
| 35 | + ) |
| 36 | + def show_div_tabindex_number_type(n_clicks, tabindex): |
| 37 | + if n_clicks: |
| 38 | + if isinstance(tabindex, int): |
| 39 | + return "success" |
| 40 | + return "fail" |
| 41 | + |
| 42 | + dash_duo.start_server(app) |
| 43 | + |
| 44 | + dash_duo.wait_for_element("#trigger-string").click() |
| 45 | + dash_duo.wait_for_element("#trigger-number").click() |
| 46 | + dash_duo.wait_for_text_to_equal( |
| 47 | + "#output-string-result", |
| 48 | + "success", |
| 49 | + ) |
| 50 | + dash_duo.wait_for_text_to_equal( |
| 51 | + "#output-number-result", |
| 52 | + "success", |
| 53 | + ) |
0 commit comments