Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed the `InputSlider` controller's `.expect_width()` to check the `width` property within the `style` attribute. (#1691)

* Fixed the `InputDate` and `InputDateRange` controllers to check the `width` property within the `style` attribute. (#1696)

## [1.1.0] - 2024-09-03

### New features
Expand Down
33 changes: 25 additions & 8 deletions shiny/api-examples/input_date/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@
from shiny import App, Inputs, Outputs, Session, ui

app_ui = ui.page_fluid(
ui.input_date("date1", "Date:", value="2016-02-29"),
ui.input_date("date1", "Has default date:", value="2016-02-29"),
# Default value is the date in client's time zone
ui.input_date("date2", "Date:"),
ui.input_date("date2", "Client's timezone:"),
# value is always yyyy-mm-dd, even if the display format is different
ui.input_date("date3", "Date:", value="2016-02-29", format="mm/dd/yy"),
ui.input_date("date3", "Format mm/dd/yy:", value="2016-02-29", format="mm/dd/yy"),
# Pass in a Date object
ui.input_date("date4", "Date:", value=date(2016, 2, 29)),
ui.input_date("date4", "Default uses date object:", value=date(2016, 2, 29)),
# Use different language and different first day of week
ui.input_date("date5", "Date:", language="ru", weekstart=1),
ui.input_date(
"date5",
"Language is German and the week starts on Monday:",
language="ru",
weekstart=1,
),
# Start with decade view instead of default month view
ui.input_date("date6", "Date:", startview="decade"),
ui.input_date("date6", "Start Date picker in Decade view:", startview="decade"),
# Disable Mondays and Tuesdays.
ui.input_date("date7", "Date:", daysofweekdisabled=[1, 2]),
ui.input_date("date7", "Disable Monday and Tuesday:", daysofweekdisabled=[1, 2]),
# Disable specific dates.
ui.input_date(
"date8",
"Date:",
"Disable specific dates:",
value="2016-02-29",
datesdisabled=["2016-03-01", "2016-03-02"],
),
# Set min and max dates.
ui.input_date(
"date9",
"Set min and max dates:",
value="2016-02-03",
min="2016-02-01",
max="2016-02-29",
),
# Set width of the date field
ui.input_date("date10", "Set width of text input:", width="600px"),
# Set autoclose to false
ui.input_date("date11", "Auto close is disabled:", autoclose=False),
)


Expand Down
4 changes: 3 additions & 1 deletion shiny/api-examples/input_date/app-express.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from shiny.express import ui

# TODO-karan. Duplicate changes from app-core.py

ui.input_date("date1", "Date:", value="2016-02-29")
# Default value is the date in client's time zone
ui.input_date("date2", "Date:")
Expand All @@ -10,7 +12,7 @@
# Pass in a Date object
ui.input_date("date4", "Date:", value=date(2016, 2, 29))
# Use different language and different first day of week
ui.input_date("date5", "Date:", language="ru", weekstart=1)
ui.input_date("date5", "Date:", language="de", weekstart=1)
# Start with decade view instead of default month view
ui.input_date("date6", "Date:", startview="decade")
# Disable Mondays and Tuesdays.
Expand Down
31 changes: 23 additions & 8 deletions shiny/api-examples/input_date_range/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
from shiny import App, Inputs, Outputs, Session, ui

app_ui = ui.page_fluid(
# Default start and end is the current date in the client's time zone
ui.input_date_range("daterange1", "Date range:"),
# Set start and end dates
ui.input_date_range(
"daterange1", "Date range:", start="2001-01-01", end="2010-12-31"
"daterange2", "Set start and end date:", start="2001-01-01", end="2010-12-31"
),
# Default start and end is the current date in the client's time zone
ui.input_date_range("daterange2", "Date range:"),
# start and end are always specified in yyyy-mm-dd, even if the display
# Start and end are always specified in yyyy-mm-dd, even if the display
# format is different
ui.input_date_range(
"daterange3",
"Date range:",
"Min, max, start, and end dates are set with custom format and separator:",
start="2001-01-01",
end="2010-12-31",
min="2001-01-01",
Expand All @@ -22,12 +23,26 @@
),
# Pass in Date objects
ui.input_date_range(
"daterange4", "Date range:", start=date(2001, 1, 1), end=date(2010, 12, 31)
"daterange4",
"Default start and end use date objects:",
start=date(2001, 1, 1),
end=date(2010, 12, 31),
),
# Use different language and different first day of week
ui.input_date_range("daterange5", "Date range:", language="de", weekstart=1),
ui.input_date_range(
"daterange5",
"Language is German and we starts on Monday:",
language="de",
weekstart=1,
),
# Start with decade view instead of default month view
ui.input_date_range("daterange6", "Date range:", startview="decade"),
ui.input_date_range(
"daterange6", "Start Date picker in Decade view:", startview="decade"
),
# Set width of the daterange field
ui.input_date_range("daterange7", "Set width of text input:", width="600px"),
# Set autoclose to false
ui.input_date_range("daterange8", "Auto close is disabled:", autoclose=False),
)


Expand Down
2 changes: 2 additions & 0 deletions shiny/api-examples/input_date_range/app-express.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from shiny.express import ui

# TODO-karan. Duplicate changes from app-core.py

ui.input_date_range("daterange1", "Date range:", start="2001-01-01", end="2010-12-31")
# Default start and end is the current date in the client's time zone
ui.input_date_range("daterange2", "Date range:")
Expand Down
2 changes: 1 addition & 1 deletion shiny/playwright/controller/_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
value
The expected width.
timeout
The maximum time to wait for the width to be visible and interactable. Defaults to `None`.
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
"""
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)

Expand Down
2 changes: 1 addition & 1 deletion shiny/playwright/controller/_input_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def expect_width(self, value: StyleValue, *, timeout: Timeout = None) -> None:
value
The expected value of the width.
timeout
The timeout for the expectation. Defaults to `None`.
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
"""
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)

Expand Down
2 changes: 1 addition & 1 deletion shiny/playwright/controller/_input_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def expect_width(self, value: str, *, timeout: Timeout = None) -> None:
value
The expected width.
timeout
The maximum time to wait for the width to be visible and interactable. Defaults to `None`.
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
"""
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)

Expand Down
33 changes: 28 additions & 5 deletions shiny/playwright/controller/_input_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,40 @@
from ._base import (
Resize,
UiBaseP,
UiWithContainerP,
UiWithLabel,
WidthContainerM,
WidthLocM,
all_missing,
not_is_missing,
set_text,
)


class InputDateWidthM:
"""
A mixin class for input date width.
This mixin class provides methods to expect the width of input date elements.
"""

def expect_width(
self: UiWithContainerP,
value: AttrValue,
*,
timeout: Timeout = None,
) -> None:
"""
Expect the input select to have a specific width.

Parameters
----------
value
The expected width.
timeout
The maximum time to wait for the expectation to be fulfilled. Defaults to `None`.
"""
_expect_style_to_have_value(self.loc_container, "width", value, timeout=timeout)


class _SetTextM:
def set(self: UiBaseP, value: str, *, timeout: Timeout = None) -> None:
"""
Expand Down Expand Up @@ -425,8 +450,8 @@ def expect_autoresize(


class _DateBase(
InputDateWidthM,
_SetTextM,
WidthContainerM,
UiWithLabel,
):

Expand Down Expand Up @@ -669,7 +694,7 @@ def __init__(self, page: Page, id: str) -> None:
)


class InputDateRange(WidthContainerM, UiWithLabel):
class InputDateRange(InputDateWidthM, UiWithLabel):
"""Controller for :func:`shiny.ui.input_date_range`."""

loc_separator: Locator
Expand Down Expand Up @@ -933,8 +958,6 @@ def expect_separator(
"""
playwright_expect(self.loc_separator).to_have_text(value, timeout=timeout)

# width: Optional[str] = None,

# autoclose: bool = True,
def expect_autoclose(
self,
Expand Down
13 changes: 12 additions & 1 deletion tests/playwright/shiny/inputs/test_input_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def expect_date(
) -> None:
date.expect_value(str(datetime.date.today()) if value == "today" else value)
autoclose_str = "true" if autoclose else "false"
date.expect_label(label)
date.expect_autoclose(autoclose_str)
date.expect_datesdisabled(datesdisabled)
date.expect_daysofweekdisabled(daysofweekdisabled)
Expand All @@ -48,7 +49,6 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:

date1 = controller.InputDate(page, "date1")

date1.expect_label("Date:")
expect(date1.loc_label).to_have_text("Date:")

expect_date(date1, "2016-02-29")
Expand All @@ -75,3 +75,14 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
"2016-02-29",
datesdisabled=["2016-03-01", "2016-03-02"],
)

expect_date(
controller.InputDate(page, "date9"),
"2016-02-03",
min_date="2016-02-01",
max_date="2016-02-29",
)

expect_date(controller.InputDate(page, "date10"), width="600px")

expect_date(controller.InputDate(page, "date11"), autoclose=False)
18 changes: 12 additions & 6 deletions tests/playwright/shiny/inputs/test_input_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ def expect_date_range(
start_value: str | Literal["today"] = "today",
end_value: str | Literal["today"] = "today",
*,
label: str = "Date:",
label: str = "Date range:",
autoclose: bool = True,
datesdisabled: typing.Optional[list[str]] = None,
daysofweekdisabled: typing.Optional[list[int]] = None,
format: str = "yyyy-mm-dd",
language: str = "en",
max_date: typing.Optional[str] = None,
Expand All @@ -34,11 +32,9 @@ def expect_date_range(
start_value = str(datetime.date.today()) if start_value == "today" else start_value
end_value = str(datetime.date.today()) if end_value == "today" else end_value
date.expect_value((start_value, end_value))
date.expect_label(label)
autoclose_str = "true" if autoclose else "false"
date.expect_autoclose(autoclose_str)
# # Not supported in `input_date_range()`
# date.expect_datesdisabled(datesdisabled)
# date.expect_daysofweekdisabled(daysofweekdisabled)
date.expect_format(format)
date.expect_language(language)
date.expect_max_date(max_date)
Expand Down Expand Up @@ -88,3 +84,13 @@ def test_input_date_kitchen(page: Page, app: ShinyAppProc) -> None:
controller.InputDateRange(page, "daterange6"),
startview="decade",
)

expect_date_range(
controller.InputDateRange(page, "daterange7"),
width="600px",
)

expect_date_range(
controller.InputDateRange(page, "daterange8"),
autoclose=False,
)
Loading