|
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 |
@@ -732,3 +732,40 @@ def is_visible(el): |
732 | 732 | ) |
733 | 733 |
|
734 | 734 | return all([is_visible(el) for el in elements]) |
| 735 | + |
| 736 | + |
| 737 | +def test_a11y009_dropdown_component_labels_render_correctly(dash_duo): |
| 738 | + app = Dash(__name__) |
| 739 | + app.layout = Div( |
| 740 | + [ |
| 741 | + Dropdown( |
| 742 | + options=[ |
| 743 | + {"label": Span("red"), "value": "red"}, |
| 744 | + {"label": Span("yellow"), "value": "yellow"}, |
| 745 | + {"label": Span("blue"), "value": "blue"}, |
| 746 | + ], |
| 747 | + value=["red", "yellow", "blue"], |
| 748 | + id="components-label-dropdown", |
| 749 | + multi=True, |
| 750 | + ), |
| 751 | + ] |
| 752 | + ) |
| 753 | + |
| 754 | + dash_duo.start_server(app) |
| 755 | + |
| 756 | + dash_duo.find_element("#components-label-dropdown").click() |
| 757 | + dash_duo.wait_for_element(".dash-dropdown-options") |
| 758 | + |
| 759 | + # Click on the "yellow" option |
| 760 | + yellow_option = dash_duo.find_element( |
| 761 | + '.dash-dropdown-option:has(input[value="yellow"])' |
| 762 | + ) |
| 763 | + yellow_option.click() |
| 764 | + |
| 765 | + # After interaction, verify the options render correctly |
| 766 | + option_elements = dash_duo.find_elements(".dash-dropdown-option") |
| 767 | + rendered_labels = [el.text.strip() for el in option_elements] |
| 768 | + |
| 769 | + assert rendered_labels == ["red", "yellow", "blue"] |
| 770 | + |
| 771 | + assert dash_duo.get_logs() == [] |
0 commit comments