Skip to content

Commit 538a495

Browse files
committed
Create Checklist and RadioItems labels with titles
1 parent 1be2046 commit 538a495

File tree

5 files changed

+92
-70
lines changed

5 files changed

+92
-70
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
44

55
## [UNRELEASED]
66

7+
## Added
8+
9+
- [#3068](https://github.com/plotly/dash/pull/3068) Add titles to labels in Checklist and RadioItems components
10+
711
## Fixed
812

913
- [#3080](https://github.com/plotly/dash/pull/3080) Fix docstring generation for components using single-line or nonstandard-indent leading comments

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}

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

-70
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
from dash.dependencies import MATCH
4+
from dash.testing import wait
5+
from dash import Dash, Input, Output, dcc, html
6+
7+
8+
def test_ddot001_dropdown_radioitems_checklist_option_title(dash_dcc):
9+
app = Dash(__name__)
10+
11+
options = [
12+
{"label": "New York City", "value": "NYC"},
13+
{"label": "Montréal", "value": "MTL"},
14+
{"label": "San Francisco", "value": "SF"},
15+
]
16+
17+
app.layout = html.Div(
18+
[
19+
dcc.Input(
20+
id="title_input",
21+
type="text",
22+
placeholder="Enter a title for New York City",
23+
),
24+
dcc.Dropdown(id="dropdown_1", options=options, multi=True, value="NYC"),
25+
dcc.Dropdown(id="dropdown_2", options=options, multi=False, value="NYC"),
26+
dcc.Checklist(
27+
id="checklist_1",
28+
options=options,
29+
value=["NYC"],
30+
labelClassName="Select-value-label",
31+
),
32+
dcc.RadioItems(
33+
id="radioitems_1",
34+
options=options,
35+
value="NYC",
36+
labelClassName="Select-value-label",
37+
),
38+
]
39+
)
40+
41+
ids = ["dropdown_1", "dropdown_2", "checklist_1", "radioitems_1"]
42+
43+
for id in ids:
44+
45+
@app.callback(Output(id, "options"), [Input("title_input", "value")])
46+
def add_title_to_option(title):
47+
return [
48+
{"label": "New York City", "title": title, "value": "NYC"},
49+
{"label": "Montréal", "value": "MTL"},
50+
{"label": "San Francisco", "value": "SF"},
51+
]
52+
53+
dash_dcc.start_server(app)
54+
55+
elements = [
56+
dash_dcc.wait_for_element("#dropdown_1 .Select-value"),
57+
dash_dcc.wait_for_element("#dropdown_2 .Select-value"),
58+
dash_dcc.wait_for_element("#checklist_1 .Select-value-label"),
59+
dash_dcc.wait_for_element("#radioitems_1 .Select-value-label"),
60+
]
61+
62+
component_title_input = dash_dcc.wait_for_element(f"#title_input")
63+
64+
# Empty string title ('') (default for no title)
65+
66+
for element in elements:
67+
wait.until(lambda: element.get_attribute("title") == "", 3)
68+
69+
component_title_input.send_keys("The Big Apple")
70+
71+
for element in elements:
72+
wait.until(lambda: element.get_attribute("title") == "The Big Apple", 3)
73+
74+
dash_dcc.clear_input(component_title_input)
75+
76+
component_title_input.send_keys("Gotham City?")
77+
78+
for element in elements:
79+
wait.until(lambda: element.get_attribute("title") == "Gotham City?", 3)
80+
81+
dash_dcc.clear_input(component_title_input)
82+
83+
for element in elements:
84+
wait.until(lambda: element.get_attribute("title") == "", 3)
85+
86+
assert dash_dcc.get_logs() == []

0 commit comments

Comments
 (0)