Skip to content

Commit 14c8a23

Browse files
committed
Create Checklist and RadioItems labels with titles
1 parent 1be2046 commit 14c8a23

File tree

5 files changed

+91
-70
lines changed

5 files changed

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

0 commit comments

Comments
 (0)