Skip to content

Add quick select to date input#10166

Merged
jrieke merged 6 commits intodevelopfrom
feature/date-input-quick-select
Jul 1, 2025
Merged

Add quick select to date input#10166
jrieke merged 6 commits intodevelopfrom
feature/date-input-quick-select

Conversation

@jrieke
Copy link
Copy Markdown
Collaborator

@jrieke jrieke commented Jan 12, 2025

Describe your changes

Adds BaseWeb's quick select dropdown to st.date_input when it's set up to select a date range:
CleanShot 2025-01-12 at 04 44 14

GitHub Issue Link (if applicable)

#11108

Testing Plan

  • Added small JS unit and e2e tests to test that the quick select feature shows up for range inputs and doesn't show up for single dates.
  • Updated snapshots.
  • Didn't add a test to actually click on the quick select feature and test its functioning, since that's a built-in BaseWeb feature anyway, so it seems a bit overkill to test that on our side.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@jrieke jrieke added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jan 12, 2025
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jun 21, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 21, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-10166/streamlit-1.46.1-py3-none-any.whl
🕹️ Preview app pr-10166.streamlit.app (☁️ Deploy here if not accessible)

@jrieke jrieke changed the title [Prototype] Add quick select to date input [WIP] Add quick select to date input Jun 21, 2025
@jrieke jrieke marked this pull request as ready for review June 21, 2025 17:48
@jrieke jrieke changed the title [WIP] Add quick select to date input Add quick select to date input Jun 21, 2025
@jrieke jrieke enabled auto-merge (squash) July 1, 2025 00:21
Comment on lines +441 to +461


def test_quick_select_feature_visibility(app: Page):
"""Test that quick select is visible for range inputs and hidden for single inputs."""
# Test range input (index 2 is "Range, no date")
range_date_input = app.get_by_test_id("stDateInput").nth(2)
range_date_input.click()

# Quick select should be visible for range inputs
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()

# Close the calendar
app.keyboard.press("Escape")

# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()

# Quick select should not be visible for single date inputs
expect(quick_select).not_to_be_visible()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test function is missing a return type annotation. Adding -> None would align with the project's typing standards for test functions and improve code clarity:

def test_quick_select_feature_visibility(app: Page) -> None:

This maintains consistency with the typing conventions used throughout the test suite.

Suggested change
def test_quick_select_feature_visibility(app: Page):
"""Test that quick select is visible for range inputs and hidden for single inputs."""
# Test range input (index 2 is "Range, no date")
range_date_input = app.get_by_test_id("stDateInput").nth(2)
range_date_input.click()
# Quick select should be visible for range inputs
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()
# Close the calendar
app.keyboard.press("Escape")
# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()
# Quick select should not be visible for single date inputs
expect(quick_select).not_to_be_visible()
def test_quick_select_feature_visibility(app: Page) -> None:
"""Test that quick select is visible for range inputs and hidden for single inputs."""
# Test range input (index 2 is "Range, no date")
range_date_input = app.get_by_test_id("stDateInput").nth(2)
range_date_input.click()
# Quick select should be visible for range inputs
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()
# Close the calendar
app.keyboard.press("Escape")
# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()
# Quick select should not be visible for single date inputs
expect(quick_select).not_to_be_visible()

Spotted by Diamond (based on custom rules)

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +450 to +461
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()

# Close the calendar
app.keyboard.press("Escape")

# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()

# Quick select should not be visible for single date inputs
expect(quick_select).not_to_be_visible()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test reuses the same quick_select locator for both test cases, which could lead to flaky results. When testing the single date input, the locator should be re-queried after opening that calendar to ensure it's testing the current DOM state rather than potentially referencing elements from the previous interaction. Consider creating a new locator after clicking on the single date input to make the test more reliable.

Suggested change
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()
# Close the calendar
app.keyboard.press("Escape")
# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()
# Quick select should not be visible for single date inputs
expect(quick_select).not_to_be_visible()
quick_select = app.locator('[data-baseweb="select"]')
expect(quick_select).to_be_visible()
# Close the calendar
app.keyboard.press("Escape")
# Test single date input (index 0 is "Single date")
single_date_input = app.get_by_test_id("stDateInput").first
single_date_input.click()
# Re-query the quick select locator to ensure we're testing the current DOM state
quick_select_for_single_date = app.locator('[data-baseweb="select"]')
# Quick select should not be visible for single date inputs
expect(quick_select_for_single_date).not_to_be_visible()

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@jrieke jrieke merged commit 13ee017 into develop Jul 1, 2025
38 checks passed
@jrieke jrieke deleted the feature/date-input-quick-select branch July 1, 2025 00:41
sfc-gh-bnisco added a commit that referenced this pull request Aug 22, 2025
#12295)

## Describe your changes

- Problem: BaseWeb’s quick select returns midday-anchored Date objects
(12:00), while our min/max bounds are midnight. Our validation compared
full datetimes, so same-day end dates were flagged as > max.
- Changes:
- Normalize all selected dates to `00:00` in `handleChange` before
validation and state updates.
  - Normalize stored values in `updateWidgetMgrState` before validation.
- Tests:
- Add unit test asserting a quick-select range ending "today" is
accepted with `max` set to today and no error icon is shown.
- Stabilize time by mocking `moment.now` and `Date`, avoiding fake
timers that interfere with BaseWeb popovers.

## GitHub Issue Link (if applicable)

Fixes #12293 
Ref #10166, #10764 

## Testing Plan

- ✅ Unit Tests (JS and/or Python)

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants