Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions shiny/api-examples/input_date/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
value="2016-02-29",
datesdisabled=["2016-03-01", "2016-03-02"],
),
# Set min and max dates.
ui.input_date(
"date9", "Date:", value="2016-02-03", min="2016-02-01", max="2016-02-29"
),
# Set width of the date field
ui.input_date("date10", "Date:", width="600px"),
# Set autoclose to false
ui.input_date("date11", "Date:", autoclose=False),
)


Expand Down
4 changes: 4 additions & 0 deletions shiny/api-examples/input_date_range/app-core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
ui.input_date_range("daterange5", "Date range:", language="de", weekstart=1),
# Start with decade view instead of default month view
ui.input_date_range("daterange6", "Date range:", startview="decade"),
# Set width of the daterange field
ui.input_date_range("daterange7", "Date range:", width="600px"),
# Set autoclose to false
ui.input_date_range("daterange8", "Date range:", autoclose=False),
)


Expand Down
32 changes: 27 additions & 5 deletions shiny/playwright/controller/_input_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,39 @@
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 +449,8 @@ def expect_autoresize(


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

Expand Down Expand Up @@ -669,7 +693,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 +957,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