Skip to content

Commit 5b5a6ca

Browse files
committed
Create Checklist and RadioItems labels with titles
1 parent 9566578 commit 5b5a6ca

File tree

4 files changed

+79
-70
lines changed

4 files changed

+79
-70
lines changed

components/dash-core-components/src/components/Checklist.react.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default class Checklist extends Component {
4343
...labelStyle,
4444
}}
4545
className={labelClassName}
46+
title={option.title}
4647
>
4748
<input
4849
checked={includes(option.value, value)}

components/dash-core-components/src/components/RadioItems.react.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default class RadioItems extends Component {
4848
}}
4949
className={labelClassName}
5050
key={option.value}
51+
title={option.title}
5152
>
5253
<input
5354
checked={option.value === value}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
import pytest
4+
from dash.testing import wait
5+
from dash import Dash, Input, Output, dcc, html
6+
7+
8+
@pytest.mark.DCC793
9+
@pytest.mark.parametrize("component_type,component_kwargs,selector_class_name", [
10+
(dcc.Dropdown, {"multi": True, "value": "NYC"}, "Select-value"),
11+
(dcc.Dropdown, {"multi": False, "value": "NYC"}, "Select-value"),
12+
(dcc.Checklist, {"value": ["NYC"], "labelClassName": "Select-value-label"}, "Select-value-label"),
13+
(dcc.RadioItems, {"value": "NYC", "labelClassName": "Select-value-label"}, "Select-value-label"),
14+
])
15+
def test_ddot001_dropdown_radioitems_checklist_option_title(dash_dcc, component_type, component_kwargs, selector_class_name):
16+
app = Dash(__name__)
17+
18+
id_prefix = component_type.__name__.lower()
19+
20+
app.layout = html.Div(
21+
[
22+
dcc.Input(
23+
id=f"{id_prefix}_title_input",
24+
type="text",
25+
placeholder="Enter a title for New York City",
26+
),
27+
component_type(
28+
id=id_prefix,
29+
options=[
30+
{"label": "New York City", "value": "NYC"},
31+
{"label": "Montréal", "value": "MTL"},
32+
{"label": "San Francisco", "value": "SF"},
33+
],
34+
**component_kwargs
35+
),
36+
]
37+
)
38+
39+
@app.callback(
40+
Output(id_prefix, "options"), [Input(f"{id_prefix}_title_input", "value")]
41+
)
42+
def add_title_to_option(title):
43+
return [
44+
{"label": "New York City", "title": title, "value": "NYC"},
45+
{"label": "Montréal", "value": "MTL"},
46+
{"label": "San Francisco", "value": "SF"},
47+
]
48+
49+
dash_dcc.start_server(app)
50+
51+
component_option_element = dash_dcc.wait_for_element(f"#{id_prefix} .{selector_class_name}")
52+
53+
component_title_input = dash_dcc.wait_for_element(f"#{id_prefix}_title_input")
54+
55+
# Empty string title ('') (default for no title)
56+
57+
wait.until(lambda: component_option_element.get_attribute("title") == "", 3)
58+
59+
component_title_input.send_keys("The Big Apple")
60+
61+
wait.until(
62+
lambda: component_option_element.get_attribute("title") == "The Big Apple", 3
63+
)
64+
65+
dash_dcc.clear_input(component_title_input)
66+
67+
component_title_input.send_keys("Gotham City?")
68+
69+
wait.until(
70+
lambda: component_option_element.get_attribute("title") == "Gotham City?", 3
71+
)
72+
73+
dash_dcc.clear_input(component_title_input)
74+
75+
wait.until(lambda: component_option_element.get_attribute("title") == "", 3)
76+
77+
assert dash_dcc.get_logs() == []

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

-70
This file was deleted.

0 commit comments

Comments
 (0)