feat(DateRangeInput): add maxRangeSpan/minRangeSpan to constrain range size - #5145
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
d869ab1 to
eb0024a
Compare
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCalendar (@astryxdesign/core) · View in Storybook
DateRangeInput (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 critical. DateRangeInput - 1 issue(s)
Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for this — the grid work is solid, and I checked both maxRangeSpan boundaries in Chrome; the window is exactly right.
minRangeSpan isn't enforced yet: with minRangeSpan={2}, clicking Aug 10 twice commits a one-day range, which is the case the prop says it forbids. Once the anchor is placed the span is knowable, same as the max — so the days inside it should be disabled as end dates.
One catch to get right: with those days disabled you can't click Aug 11 to start over there. So clicking the anchor again should toggle it off and clear the selection, rather than restart — otherwise moving the start a day over is impossible.
Separately, a Last 30 days preset applies under maxRangeSpan={7}. Should a preset override the cap, or be disabled when it violates one?
[Reviewed by Robohands]
eb0024a to
ef470b9
Compare
|
Thanks — all three addressed:
Anchor toggle-to-clear. Clicking the in-progress start again clears it instead of committing a zero-length range, so you can move the start even when Preset vs cap. A preset whose range violates Tests added for the anchor-clear and the disabled-preset paths; full suite green (Calendar + DateRangeInput, 125 tests), build/typecheck/lint/i18n-catalog clean. |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, all three land. Walked it in Chrome: the forbidden band is right, the anchor clears, the 30-day preset is disabled.
[Reviewed by Robohands]
All three asks addressed; walked the flow in Chromium.
Summary
DateRangeInput(and the underlyingCalendarinmode="range") can constrain where dates fall (min/max,dateConstraints) but not how wide the selected range may be. There is no way to express "once the user picks a start date, the end date can't be more than a week away" — a rolling window relative to the chosen start.This adds two props to express that:
maxRangeSpan?: number— the maximum number of days a range may span, counting both endpoints (maxRangeSpan={7}= a 7-day window, start + 6). Once a start is picked, days beyond that distance from it are disabled in either direction.minRangeSpan?: number— the minimum span, both endpoints counted (minRangeSpan={2}forbids a single-day range). Defaults to 1.Design notes
dateConstraintsclosure.maxRangeSpan={7}is discoverable and reads at a glance; an anchor-relative closure is neither. Arbitrary anchor-relative rules that aren't a day-count remain out of scope by design — if a real one shows up, extendingdateConstraintswith the pending anchor is the future escape hatch.span - 1days.valuethat is already wider than the cap. Surface such a value withstatusif you need to flag it.useCalendarConstraints, which disables candidate days outside[anchor − (max−1), anchor + (max−1)]and inside the min band. Span constraints apply in range mode only.Test plan
pnpm -F @astryxdesign/core test— Calendar, DateRangeInput, and plainDate suites pass (207 tests). New coverage:maxRangeSpan(both directions, boundary days), enforcesminRangeSpan, and does not apply span constraints in single mode.maxRangeSpanto the calendar.plainDateDiffDaysunit tests (forward/backward/zero, month + year rollover, DST-safe).pnpm -F @astryxdesign/core build— clean.pnpm -F @astryxdesign/core typecheck— clean..doc.mjsfor both components, EN + zh + dense), Storybook stories, and a changeset are included.