Skip to content

Commit

Permalink
Create Checklist and RadioItems labels with titles
Browse files Browse the repository at this point in the history
  • Loading branch information
giladmaya committed Nov 21, 2024
1 parent 1be2046 commit 14c8a23
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 70 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

## Added

- [#3068](https://github.com/plotly/dash/pull/3068) Add titles to labels in Checklist and RadioItems components

## Fixed

- [#3080](https://github.com/plotly/dash/pull/3080) Fix docstring generation for components using single-line or nonstandard-indent leading comments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class Checklist extends Component {
...labelStyle,
}}
className={labelClassName}
title={option.title}
>
<input
checked={includes(option.value, value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class RadioItems extends Component {
}}
className={labelClassName}
key={option.value}
title={option.title}
>
<input
checked={option.value === value}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- coding: UTF-8 -*-

from dash.testing import wait
from dash import Dash, Input, Output, dcc, html


def test_ddot001_dropdown_radioitems_checklist_option_title(dash_dcc):
app = Dash(__name__)

options = [
{"label": "New York City", "value": "NYC"},
{"label": "Montréal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
]

app.layout = html.Div(
[
dcc.Input(
id="title_input",
type="text",
placeholder="Enter a title for New York City",
),
dcc.Dropdown(id="dropdown_1", options=options, multi=True, value="NYC"),
dcc.Dropdown(id="dropdown_2", options=options, multi=False, value="NYC"),
dcc.Checklist(
id="checklist_1",
options=options,
value=["NYC"],
labelClassName="Select-value-label",
),
dcc.RadioItems(
id="radioitems_1",
options=options,
value="NYC",
labelClassName="Select-value-label",
),
]
)

ids = ["dropdown_1", "dropdown_2", "checklist_1", "radioitems_1"]

for id in ids:

@app.callback(Output(id, "options"), [Input("title_input", "value")])
def add_title_to_option(title):
return [
{"label": "New York City", "title": title, "value": "NYC"},
{"label": "Montréal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
]

dash_dcc.start_server(app)

elements = [
dash_dcc.wait_for_element("#dropdown_1 .Select-value"),
dash_dcc.wait_for_element("#dropdown_2 .Select-value"),
dash_dcc.wait_for_element("#checklist_1 .Select-value-label"),
dash_dcc.wait_for_element("#radioitems_1 .Select-value-label"),
]

component_title_input = dash_dcc.wait_for_element("#title_input")

# Empty string title ('') (default for no title)

for element in elements:
wait.until(lambda: element.get_attribute("title") == "", 3)

component_title_input.send_keys("The Big Apple")

for element in elements:
wait.until(lambda: element.get_attribute("title") == "The Big Apple", 3)

dash_dcc.clear_input(component_title_input)

component_title_input.send_keys("Gotham City?")

for element in elements:
wait.until(lambda: element.get_attribute("title") == "Gotham City?", 3)

dash_dcc.clear_input(component_title_input)

for element in elements:
wait.until(lambda: element.get_attribute("title") == "", 3)

assert dash_dcc.get_logs() == []

0 comments on commit 14c8a23

Please sign in to comment.