|
1 | 1 | import pytest |
2 | 2 | from dash import Dash, Input, Output |
3 | 3 | from dash.dcc import Dropdown |
4 | | -from dash.html import Div, Label, P |
| 4 | +from dash.html import Div, Label, P, Span |
5 | 5 | from selenium.common.exceptions import TimeoutException |
6 | 6 | from selenium.webdriver.common.keys import Keys |
7 | 7 | from selenium.webdriver.common.action_chains import ActionChains |
@@ -434,3 +434,40 @@ def is_visible(el): |
434 | 434 | ) |
435 | 435 |
|
436 | 436 | return all([is_visible(el) for el in elements]) |
| 437 | + |
| 438 | + |
| 439 | +def test_a11y009_dropdown_component_labels_render_correctly(dash_duo): |
| 440 | + app = Dash(__name__) |
| 441 | + app.layout = Div( |
| 442 | + [ |
| 443 | + Dropdown( |
| 444 | + options=[ |
| 445 | + {"label": Span("red"), "value": "red"}, |
| 446 | + {"label": Span("yellow"), "value": "yellow"}, |
| 447 | + {"label": Span("blue"), "value": "blue"}, |
| 448 | + ], |
| 449 | + value=["red", "yellow", "blue"], |
| 450 | + id="components-label-dropdown", |
| 451 | + multi=True, |
| 452 | + ), |
| 453 | + ] |
| 454 | + ) |
| 455 | + |
| 456 | + dash_duo.start_server(app) |
| 457 | + |
| 458 | + dash_duo.find_element("#components-label-dropdown").click() |
| 459 | + dash_duo.wait_for_element(".dash-dropdown-options") |
| 460 | + |
| 461 | + # Click on the "yellow" option |
| 462 | + yellow_option = dash_duo.find_element( |
| 463 | + '.dash-dropdown-option:has(input[value="yellow"])' |
| 464 | + ) |
| 465 | + yellow_option.click() |
| 466 | + |
| 467 | + # After interaction, verify the options render correctly |
| 468 | + option_elements = dash_duo.find_elements(".dash-dropdown-option") |
| 469 | + rendered_labels = [el.text.strip() for el in option_elements] |
| 470 | + |
| 471 | + assert rendered_labels == ["red", "blue", "yellow"] |
| 472 | + |
| 473 | + assert dash_duo.get_logs() == [] |
0 commit comments