This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expose Dropdown option 'title' property #793
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
09cf69a
Add title PropType to Dropdowns
wbrgss 5f23140
No newline after PropType
wbrgss e301a81
Added CHANGELOG entry for exposing dcc.Dropdown option `title`s
wbrgss 5e9c3e0
sub-heading
wbrgss c38eb00
Integration test that checks for title attribute
wbrgss efb812a
newline
wbrgss 4110653
UTF-8 encoding
wbrgss 9d9c50c
Merge branch 'dev' into dropdown-option-titles
wbrgss d5bee5d
Test other inputs + input clearing in dropdown title test
wbrgss 31ec44c
Replace clear() with Ctrl+A + Delete
wbrgss 1d57dbe
Semicolon
wbrgss a8b67a0
Use dash_dcc.clear_input()
wbrgss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: UTF-8 -*- | ||
|
||
import pytest | ||
import dash | ||
from dash.dependencies import Input, Output | ||
import dash_core_components as dcc | ||
import dash_html_components as html | ||
|
||
from utils import wait_for | ||
|
||
|
||
@pytest.mark.DCC793 | ||
@pytest.mark.parametrize("multi", [True, False]) | ||
def test_ddot001_option_title(dash_dcc, multi): | ||
app = dash.Dash(__name__) | ||
app.layout = html.Div([ | ||
dcc.Input( | ||
id="dropdown_title_input", | ||
type="text", | ||
placeholder="Enter a title for New York City" | ||
), | ||
dcc.Dropdown( | ||
id="dropdown", | ||
options=[ | ||
{'label': 'New York City', 'value': 'NYC'}, | ||
{'label': 'Montréal', 'value': 'MTL'}, | ||
{'label': 'San Francisco', 'value': 'SF'} | ||
], | ||
value='NYC', | ||
multi=multi | ||
) | ||
]) | ||
|
||
@app.callback(Output("dropdown", "options"), [Input("dropdown_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) | ||
|
||
dropdown_option_element = dash_dcc.wait_for_element("#dropdown .Select-value") | ||
|
||
dropdown_title_input = dash_dcc.wait_for_element("#dropdown_title_input") | ||
|
||
# Empty string title ('') (default for no title) | ||
wait_for( | ||
lambda: dropdown_option_element.get_attribute("title") | ||
== '', | ||
lambda: '`title` is {}, expected {}'.format( | ||
dropdown_option_element.get_attribute("title"), | ||
'', | ||
), | ||
) | ||
|
||
dropdown_title_input.send_keys("The Big Apple") | ||
|
||
wait_for( | ||
lambda: dropdown_option_element.get_attribute("title") | ||
== "The Big Apple", | ||
lambda: '`title` is {}, expected {}'.format( | ||
dropdown_option_element.get_attribute("title"), | ||
"The Big Apple", | ||
), | ||
) | ||
|
||
dash_dcc.clear_input(dropdown_title_input) | ||
|
||
dropdown_title_input.send_keys("Gotham City?") | ||
|
||
wait_for( | ||
lambda: dropdown_option_element.get_attribute("title") | ||
== "Gotham City?", | ||
lambda: '`title` is {}, expected {}'.format( | ||
dropdown_option_element.get_attribute("title"), | ||
"Gotham City?", | ||
), | ||
) | ||
|
||
dash_dcc.clear_input(dropdown_title_input) | ||
|
||
wait_for( | ||
lambda: dropdown_option_element.get_attribute("title") | ||
== '', | ||
lambda: '`title` is {}, expected {}'.format( | ||
dropdown_option_element.get_attribute("title"), | ||
'', | ||
), | ||
) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wbrgss I'm not sure why there's a callback to update the
title
on the 1st option: If all we want to do is make sure it's present, we could set it in the initial layout. If we want to make sure it's present after an update, we should change it more than once and make sure it changes None --> "Big Apple" --> "Knicks Game" --> None for example.I'm ok with us not testing further (eg.
title
present in the dropdown, not just the selected value) as that would be the same as testing the 3rd party component that we're wrapping.Using
wait_for_element
instead offind_element_by_css_selector
makes for a slightly more verbose test but also for a slightly more resilient test (eg. timing issues in CI). That said the test app is pretty small and probably will rarely be an issue. Same goes forwait_for
vs. simply getting the attribute. This is 👌There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, that makes sense. I'll update it.
Yeah, I've had timing issues here and there with more complicated test apps so I've been using
wait_for
for overkill to be safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Marc-Andre-Rivet I've done this in d5bee5d; if that looks right to you I'm going to merge.