Skip to content

Commit 7ea7c65

Browse files
committed
fix multiselect dropdown with components as labels
1 parent 50cb3e4 commit 7ea7c65

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

components/dash-core-components/src/fragments/Dropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ const Dropdown = (props: DropdownProps) => {
233233

234234
setDisplayOptions(sortedOptions);
235235
}
236-
}, [filteredOptions, isOpen]);
236+
}, [filteredOptions, isOpen, sanitizedValues]);
237237

238238
// Focus first selected item or search input when dropdown opens
239239
useEffect(() => {

components/dash-core-components/tests/integration/dropdown/test_a11y.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from dash import Dash, Input, Output
33
from dash.dcc import Dropdown
4-
from dash.html import Div, Label, P
4+
from dash.html import Div, Label, P, Span
55
from selenium.common.exceptions import TimeoutException
66
from selenium.webdriver.common.keys import Keys
77
from selenium.webdriver.common.action_chains import ActionChains
@@ -434,3 +434,40 @@ def is_visible(el):
434434
)
435435

436436
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

Comments
 (0)