Skip to content

Commit d5a97fb

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

File tree

4 files changed

+94
-70
lines changed

4 files changed

+94
-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,92 @@
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(
10+
"component_type,component_kwargs,selector_class_name",
11+
[
12+
(dcc.Dropdown, {"multi": True, "value": "NYC"}, "Select-value"),
13+
(dcc.Dropdown, {"multi": False, "value": "NYC"}, "Select-value"),
14+
(
15+
dcc.Checklist,
16+
{"value": ["NYC"], "labelClassName": "Select-value-label"},
17+
"Select-value-label",
18+
),
19+
(
20+
dcc.RadioItems,
21+
{"value": "NYC", "labelClassName": "Select-value-label"},
22+
"Select-value-label",
23+
),
24+
],
25+
)
26+
def test_ddot001_dropdown_radioitems_checklist_option_title(
27+
dash_dcc, component_type, component_kwargs, selector_class_name
28+
):
29+
app = Dash(__name__)
30+
31+
id_prefix = component_type.__name__.lower()
32+
33+
app.layout = html.Div(
34+
[
35+
dcc.Input(
36+
id=f"{id_prefix}_title_input",
37+
type="text",
38+
placeholder="Enter a title for New York City",
39+
),
40+
component_type(
41+
id=id_prefix,
42+
options=[
43+
{"label": "New York City", "value": "NYC"},
44+
{"label": "Montréal", "value": "MTL"},
45+
{"label": "San Francisco", "value": "SF"},
46+
],
47+
**component_kwargs,
48+
),
49+
]
50+
)
51+
52+
@app.callback(
53+
Output(id_prefix, "options"), [Input(f"{id_prefix}_title_input", "value")]
54+
)
55+
def add_title_to_option(title):
56+
return [
57+
{"label": "New York City", "title": title, "value": "NYC"},
58+
{"label": "Montréal", "value": "MTL"},
59+
{"label": "San Francisco", "value": "SF"},
60+
]
61+
62+
dash_dcc.start_server(app)
63+
64+
component_option_element = dash_dcc.wait_for_element(
65+
f"#{id_prefix} .{selector_class_name}"
66+
)
67+
68+
component_title_input = dash_dcc.wait_for_element(f"#{id_prefix}_title_input")
69+
70+
# Empty string title ('') (default for no title)
71+
72+
wait.until(lambda: component_option_element.get_attribute("title") == "", 3)
73+
74+
component_title_input.send_keys("The Big Apple")
75+
76+
wait.until(
77+
lambda: component_option_element.get_attribute("title") == "The Big Apple", 3
78+
)
79+
80+
dash_dcc.clear_input(component_title_input)
81+
82+
component_title_input.send_keys("Gotham City?")
83+
84+
wait.until(
85+
lambda: component_option_element.get_attribute("title") == "Gotham City?", 3
86+
)
87+
88+
dash_dcc.clear_input(component_title_input)
89+
90+
wait.until(lambda: component_option_element.get_attribute("title") == "", 3)
91+
92+
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)