-
Couldn't load subscription status.
- Fork 115
fix: Address datepicker issues #2057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d84b171
Updating string formatting
elnelson575 c123c20
Updated types
elnelson575 6a0ddbe
Adding empty str as blank option
elnelson575 2799fbf
Simplify
cpsievert 953aa4a
Simplify again
cpsievert c3cd6a7
Faster check
cpsievert ccb08f4
Another datepicker test
elnelson575 4d479aa
Merge branch 'fix/datepicker' of github.com:posit-dev/py-shiny into f…
elnelson575 36a70d0
Pre-test updates
elnelson575 5be9d98
Tests for datepicker
elnelson575 e46d600
Updated tests and doc strings
elnelson575 a899b94
Support clearing of values programmatically
cpsievert 42f33cd
Adding blank value test
elnelson575 33b5ef8
updates
elnelson575 2317f62
Adding datepicker blanks example
elnelson575 96593b6
Adding date-range
elnelson575 e397dfa
Workaround for type checking issue
cpsievert d6cd8bc
Update shiny/ui/_input_date.py
elnelson575 0085a35
Updates
elnelson575 2ddf4ca
moving folder
elnelson575 f5c7faa
Merge branch 'fix/datepicker' of github.com:posit-dev/py-shiny into f…
elnelson575 9e32278
Updating Changelog
elnelson575 acdd535
Update CHANGELOG.md
elnelson575 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| from datetime import date | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
|
|
||
| from shiny import App, Inputs, Outputs, Session, reactive, render, ui | ||
|
|
||
| min_date = date.fromisoformat("2011-11-04") | ||
| max_date = min_date + relativedelta(days=10) | ||
|
|
||
| app_ui = ui.page_fluid( | ||
| ui.input_date( | ||
| "start_date_picker", | ||
| "Date Type Input:", | ||
| value=max_date, | ||
| min=min_date, | ||
| max=max_date, | ||
| format="dd.mm.yyyy", | ||
| language="en", | ||
| ), | ||
| ui.output_text("start"), | ||
| ui.input_date( | ||
| "min_date_picker", | ||
| "Date Type Input:", | ||
| value=min_date, | ||
| min=min_date, | ||
| max=max_date, | ||
| format="dd.mm.yyyy", | ||
| language="en", | ||
| ), | ||
| ui.output_text("min"), | ||
| ui.input_date( | ||
| "str_date_picker", | ||
| "String Type Input:", | ||
| value="2023-10-05", | ||
| min="2023-10-01", | ||
| max="2023-10-07", | ||
| format="dd-mm-yyyy", | ||
| language="en", | ||
| ), | ||
| ui.output_text("str_format"), | ||
| ui.input_date("none_date_picker", "None Type Input:"), | ||
| ui.output_text("none_format"), | ||
| ui.input_date( | ||
| "empty_date_picker", | ||
| "empty Type Input:", | ||
| value="", | ||
| min=None, | ||
| max=None, | ||
| format="dd-mm-yyyy", | ||
| language="en", | ||
| ), | ||
| ui.output_text("empty_format"), | ||
| ui.input_action_button("update", "Update Dates"), | ||
| ) | ||
|
|
||
|
|
||
| def server(input: Inputs, output: Outputs, session: Session): | ||
| @render.text | ||
| def start(): | ||
| return "Date Picker Value: " + str(input.start_date_picker()) | ||
|
|
||
| @render.text | ||
| def min(): | ||
| return "Date Picker Value: " + str(input.min_date_picker()) | ||
|
|
||
| @render.text | ||
| def str_format(): | ||
| return "Date Picker Value: " + str(input.str_date_picker()) | ||
|
|
||
| @render.text | ||
| def none_format(): | ||
| return "Date Picker Value: " + str(input.none_date_picker()) | ||
|
|
||
| @render.text | ||
| def empty_format(): | ||
| return "Date Picker Value: " + str(input.empty_date_picker()) | ||
|
|
||
| @reactive.effect | ||
| @reactive.event(input.update, ignore_none=True, ignore_init=True) | ||
| def _(): | ||
| d = date.fromisoformat("2011-11-05") | ||
| ui.update_date("start_date_picker", value=d) | ||
| ui.update_date("min_date_picker", value="", min="") | ||
| ui.update_date("str_date_picker", value="2023-10-03", max="2023-10-20") | ||
|
|
||
|
|
||
| app = App(app_ui, server, debug=True) |
68 changes: 68 additions & 0 deletions
68
tests/playwright/shiny/inputs/input_datepicker/test_datepicker.py
This file contains hidden or 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,68 @@ | ||
| import datetime | ||
|
|
||
| from playwright.sync_api import Page | ||
|
|
||
| from shiny.playwright import controller | ||
| from shiny.run import ShinyAppProc | ||
|
|
||
|
|
||
| def test_dynamic_navs(page: Page, local_app: ShinyAppProc) -> None: | ||
| page.goto(local_app.url) | ||
|
|
||
| # Check the initial state of the date picker where value = max | ||
| date1 = controller.InputDate(page, "start_date_picker") | ||
| date1.expect_value("14.11.2011") | ||
|
|
||
| # Can't find a way to inspect the actual display date in the datepicker, | ||
| # as even in the broken example, the correct attribute was still set. | ||
| # To work around this, we will check the displayed value to ensure the | ||
| # correct value is being passed to the server. | ||
| date_output = controller.OutputText(page, "start") | ||
| date_output.expect_value("Date Picker Value: 2011-11-14") | ||
|
|
||
| # Test the date picker with the min date = initial value (unchanged case) | ||
| date2 = controller.InputDate(page, "min_date_picker") | ||
| date2.expect_value("04.11.2011") | ||
|
|
||
| date_output2 = controller.OutputText(page, "min") | ||
| date_output2.expect_value("Date Picker Value: 2011-11-04") | ||
|
|
||
| # Test the date picker with the date set as a string instead of as a date object | ||
| date3 = controller.InputDate(page, "str_date_picker") | ||
| date3.expect_value("05-10-2023") | ||
|
|
||
| date_output3 = controller.OutputText(page, "str_format") | ||
| date_output3.expect_value("Date Picker Value: 2023-10-05") | ||
|
|
||
| # Test the date picker with a None value inputted | ||
| # None defaults to today's date | ||
| input = datetime.date.today().strftime("%Y-%m-%d") | ||
| date4 = controller.InputDate(page, "none_date_picker") | ||
| date4.expect_value(input) | ||
|
|
||
| date_output4 = controller.OutputText(page, "none_format") | ||
| date_output4.expect_value("Date Picker Value: " + input) | ||
|
|
||
| # Test the default value when an empty string is passed is correctly blank | ||
| date5 = controller.InputDate(page, "empty_date_picker") | ||
| date5.expect_value("") | ||
|
|
||
| date_output5 = controller.OutputText(page, "empty_format") | ||
| date_output5.expect_value("Date Picker Value: None") | ||
|
|
||
| controller.InputActionButton(page, "update").click() | ||
|
|
||
| date1.expect_value("05.11.2011") | ||
| date_output.expect_value("Date Picker Value: 2011-11-05") | ||
|
|
||
| date2.expect_value("") | ||
| date_output2.expect_value("Date Picker Value: None") | ||
| # This is updating min and max dates, but the playwright locater cannot find it. | ||
| # It appears that the disabled dates are correct. | ||
| # Expect that means the calcuated values for disabled dates are updating correctly | ||
| # but the attribute is not updated. | ||
|
|
||
| # date2.expect_min_date(None) | ||
|
|
||
| date3.expect_value("03-10-2023") | ||
| date_output3.expect_value("Date Picker Value: 2023-10-03") |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.