Repository navigation
feat(DateInput): add exact theme-aware picker adaptations - #6133
imdreamrunner wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
b716028 to
41726f9
Compare
1000400 to
a80589e
Compare
41726f9 to
aab5641
Compare
a80589e to
1bf9995
Compare
aab5641 to
93d6ccb
Compare
1bf9995 to
88323e1
Compare
…ns policy
Both date fields now accept an ordered `adaptations={{default, rules}}` policy
over the three surfaces they already have, resolved through the package-internal
useComponentAdaptations against the nearest Theme's width points.
DateInputAdaptationValue and DateTimeInputAdaptationValue are each exactly
'native' | 'popover' | 'bottom-sheet', spelled as literals rather than aliased
to an internal type, and exported from the package root and from
@astryxdesign/core/DateInput and @astryxdesign/core/DateTimeInput. Both Props
stay interfaces: the new prop is one optional member, not a union arm.
A value is EXACT and holds on any pointer, which is the whole difference from
`nativePicker`: 'native' selects the platform control, 'popover' the typable
field with its anchored calendar (and, on DateTimeInput, the time list), and
'bottom-sheet' the touch field with its sheet. `default` is server truth, so a
policy also decides the tree the server renders, which a pointer test cannot.
`nativePicker` is untouched. With no `adaptations` prop both components run
exactly the media query and the branch they always did — including the
mid-interaction pointer switch and the quiet per-segment fallback for props the
platform cannot express — and the 472 existing DateInput/DateTimeInput tests
pass unchanged. The two props are mutually exclusive at runtime, checked on
`!== undefined` so an explicitly spread `undefined` beside a real value is an
ordinary call rather than a conflict. Type-level exclusivity would have cost the
interface shape, and these props are far apart in the table; the throw names both
and fires before a surface opens.
A policy naming 'native' is validated EAGERLY across `default` and every rule,
matched or not. DateInput rejects `numberOfMonths={2}` and any explicit
`weekStartsOn` (presence, not value: `weekStartsOn={0}` states Sunday, and the
OS picker follows its own locale); DateTimeInput rejects those plus `hasSeconds`,
a non-default `timeIncrement`, and any `timeOptionInterval`, because there its
'native' is a promise about both segments with no per-segment retreat. Checking
the unmatched rules is the point: the failure lands on the author's machine
rather than on the one device whose width and pointer select that rule. It
throws in production too — a silently dropped week start is a wrong calendar,
not a warning — and every message names the offending policy path. min, max and
dateConstraints stay supported: native mode forwards the bounds and refuses an
out-of-range commit. The legacy path keeps its own quieter fallback.
`hasSeconds` is rejected on TRUTHINESS, not on `=== true`, because that is how
the render reads it: `usesNativeTimePicker` is gated on `!hasSeconds`, so an
untyped caller's `hasSeconds={1}` retains the Astryx time field. Strict equality
would admit exactly that call under a policy promising two platform controls,
and the field would render one of each while reporting "native".
The resolved surface is LATCHED while the field is in use, which Selector did
not need: its surfaces live in one component, while these switch whole trees, so
publishing a new value mid-entry would unmount the focused control and take the
uncommitted draft, the caret and the open picker with it — on an ordinary
rotation or window resize. useAdaptationSurfaceLatch holds the rendered surface
while EITHER focus is in the field or the field still owns an open surface (an
expanded trigger, or a BottomSheet still mounted as an open dialog through its
exit). The second arm is what covers a PORTALED popover, which focus can enter
without ever naming an element the field contains, and it releases off a
disclosure-attribute observer when a surface closes with focus already gone.
Whether focus left is decided from the blur event's `relatedTarget`, in the
event that asks the question. The tempting implementation defers the decision to
a microtask and asks again once focus has landed; it is wrong, and jsdom hides
it, because there a programmatic blur()/focus() pair runs inside one task. A
real browser dispatches a user's Tab or click as focusout, drains microtasks,
and only then fires focusin — so the deferred check ran BETWEEN them, saw focus
nowhere, and released the latch in the middle of the interaction it exists to
protect: moving from the text field to its own calendar toggle swapped the tree
under the pointer and ate the click. A Chromium story-play regression pins it
(reverting to the deferred version fails that play and only it), alongside
relatedTarget tests for DateInput input->toggle and input->clear and for
DateTimeInput date->time.
Three suites, 149 tests, cover SSR and hydration, the exact md boundary and a
nested Theme, rule order and empty rules, all three surfaces on both pointers,
both props and their explicit undefineds, invalid and falsy policies, eager
rejection from an unmatchable rule, latching across viewport, theme and policy
changes with the entry and focus preserved, native min/max/dateConstraints, and
legacy parity. The third is a story smoke test, and it closes a real hole: an
eagerly-rejected policy makes a story throw, a story that throws renders an
empty page, and axe reports an empty page as zero violations — so the a11y gate
passed a broken story by being blank. It renders every story whose name marks it
as authoring a policy, so the next one is covered the day it lands, and it runs
under the `ui` vitest project, which now collects story-level suites.
The Storybook stories add a coarse-pointer native rule, a coarse-pointer popover
rule, both fine-pointer sheets, and the latch demonstration; two carry play
functions asserting what jsdom cannot — that the sheet opens as a genuinely
modal dialog (`:modal`) and that a real browser's focus move keeps the latch —
and both are registered with the story play guard so Chromium runs them in CI.
No spec record is touched: AST-031 is still a draft and neither component has a
current spec, so this behavior is carried by the consumer docs, the changeset,
and the tests.
93d6ccb to
c13e3b4
Compare
88323e1 to
9fd9fd0
Compare
|
AI review status for this pull request.
|
…docs (#7372) ## User impact Builders reading DateInput's API reference could not find `containerClassName`, `containerStyle`, `controlClassName`, or `controlStyle`, even though DateInput accepts them and they are the only class-name and inline-style hooks it has after root styling was removed. The English, Chinese, and dense references now list all six part-styling props, like the other field components. The draft contract now matches DateInput's current behavior. Runtime behavior does not change. ## Audit scope - Package/component: `core/DateInput` - Base: `1e883f86e7aa5c2be376671f746d79e5cfae769b` - Frozen head: `4faee79d299c5f4661bfecbb01a7aade966440ee` - Mode: Night Watch whole-component audit · Rubric: **1.16.6** - Runtime/API changes: none (API reference, draft contract, and a `[docs]` Changeset) - Landing: held until the 0.7.0 release is tagged. ## Score - Before: **85.6 / C** — 2 open BLOCKs; §5b not measured. - After: **87.3 / C**, confirmed by the exact-head checks — the same 2 BLOCKs, both owned by open contributor pull requests (see Needs Review). - Sensitivity: resolve the 2 open BLOCKs and change nothing else → **99.0 / A**. - Sections §1, §2, §3, §4, §5a, §5b, §6, §7, §8, §9, §10 — before `3, 5, 5, 3, 5, nm, 5, 5, 4, 5, 4`; after `3, 5, 5, 3, 5, nm, 5, 5, 5, 5, 4`. ## Findings | ID | Section | Finding | Authority | Result | |---|---|---|---|---| | D1 | §1 A5 — BLOCK | In the bottom-sheet calendar, the month arrows become natively disabled at the first or last reachable month, so a keyboard user who steps onto that month loses focus to the document. | `architecture:interaction-modality`; WCAG 2.2 SC 2.4.3 | **Open.** #6304 already fixes it; not duplicated here. | | D2 | §4 B15 — BLOCK | After a clear, the pointer surface passes `undefined` to Calendar, which treats it as uncontrolled, so reopening the calendar shows the cleared date as selected. A focused test at the exact head reproduces it: one day stays selected after clear and reopen. | DateInput clear contract (FR1, FR11); Calendar's documented controlled-empty `null`; WCAG 2.2 SC 4.1.2 | **Open.** #6935 already fixes it; not duplicated here. | | D3 | §8 X5b — FIX | The API reference omitted `containerClassName`, `containerStyle`, `controlClassName`, and `controlStyle`, which DateInput accepts under `family:input-fields/FR10`; the other field members list them. | `family:input-fields/FR10`; rubric X5b | **Fixed** in the English, Chinese, and dense references. | | D4 | §8 — FIX | The draft contract described the removed `date-input-clear-icon` alias and did not cite the FR10 base-prop and part-styling rule DateInput now follows. | Current source; `family:input-fields/FR10` | **Fixed.** The contract cites FR10 and the current clear-glyph target; the FR10 suite joins `verified_by`. No new component requirement is added. | Not scored: the bottom-sheet surface inherits BottomSheet's recorded shared-dismissal adoption gap (owned by BottomSheet under `family:overlay-dismissal`). The bottom-sheet calendar's day cells fade their colors without a reduced-motion collapse, but the motion record is still a draft, so no current authority applies. ## What changed - `DateInput.doc.mjs` — four props entries in `docs` and `docsZh`, four `docsDense` descriptions, matching the sibling field components. - `DateInput.spec.md` (draft) — cites `family:input-fields/FR10` in the governing rules and the family relationship, adds `DateInput.fr10.test.tsx` to `verified_by`, and names the current clear-glyph target. - `.changeset/date-input-part-style-props-docs.md` — `[docs]` patch, because the API reference ships in the package. ## Evidence - This PR changes no behavior, so no new functional test was added; typed docs validation and the doc-prop suites cover the docs change. - Exact-head checks on `4faee79`: CI run 38256902974 succeeded, including build, lint, unit tests, docsite tests, and the Storybook build. - `pr-a11y` audited all 26 DateInput stories: 0 violations and no new baseline entries. - `pr-rtl` (core): `core/DateInput` passes the automatic check and its curated calendar/clear control-order check. - Stable visual regression: see Visual acceptance. - Owner-exempt `review-required` is success on `4faee79`, set by GitHub Actions through the repository's Review signal workflow. `spec-owner-approval` is success (draft record only), and the CLA check passes. - A private review of the exact head, title, and description is clean. - Local runs on the first head: DateInput, doc-prop, and theming suites — 757/757; `typecheck:docs`; `pnpm build`; docsite generate and tests — 620 passed, 6 skipped; `check:knowledge`; `check:changesets`. Later commits changed only draft-contract text, with `check:knowledge` re-run after each, plus one empty commit that retriggered a failed preview deployment. - No local browser result is credited; browser evidence comes from the exact-head checks above. ## Closed evidence inventory | Surface | Evidence | Result | |---|---|---| | Controlled ISO value, typing, constraints, formats | source; focused suites | pass | | Five presentation values and deprecated mapping | `Presentation.test.tsx`; native and touch suites | pass | | Pointer calendar open, select, close | source; tests; `OpenCalendarAudit` story | pass | | Clear and calendar selection | source; focused test at the exact head | open — D2 | | Bottom-sheet calendar, wheels, save | `DateInputTouch.test.tsx` | pass | | Bottom-sheet month arrows at a bound | source | open — D1 | | Native picker, Action, clear, focus continuity | `NativeDateField.test.tsx` | pass | | Field states, status, disabled reason, InputGroup | focused suites; `AllVariations` | pass | | FR10 base props and part styling | `DateInput.fr10.test.tsx`; `StylingParts` story | pass | | API reference completeness | `DateInput.doc.mjs` | fixed — D3 | | Theming targets | `themingTargets.test.ts`; themed stories | pass | | Accessibility and RTL | exact-head `pr-a11y` (26 stories) and `pr-rtl` (core) | pass | | Narrow viewport and coarse pointer pixels | none | not measured | ## Visual acceptance Product visual delta: **N/A**. The change is limited to the API reference, the draft contract, and a Changeset; no component source, style, story, or rendered output changes. The exact-head stable visual gate passed with verdict `changed`: 448 shots, 356 unchanged, 42 changed, 50 added, 22 removed, 0 failed, against a baseline captured on 2026-09-26. #7370's exact-head report, from a PR that changed no DateInput file, lists the same 42 changed, 50 added, and 22 removed shots. 41 changed shots match it pixel for pixel; the 42nd, a SideNav resize shot, also varies between runs of this PR. No DateInput shot changed: its 8 added and 2 removed shots appear identically in #7370's report. The verdict reflects baseline drift, not this PR. ## Knowledge overlap search - Terms: `component:DateInput`, `DateInput.spec.md`, `containerClassName`, `controlClassName`, `FR10`, `date-input-clear-icon`, plus the path `packages/core/src/DateInput/`. - Canonical owner: the existing draft `component:DateInput` at `packages/core/src/DateInput/DateInput.spec.md`; the FR10 rule stays with `family:input-fields` and is linked, not copied. - Overlapping open work inspected: #6935 and #6304 own D2 and D1; #7358 changes translator imports; #6884, merged after this audit's base, changes only the bottom-sheet padding in `TouchDateField.tsx`; #6133 and #5939 are drafts. None edits `DateInput.spec.md`. DateRangeInput, DateTimeInput, and TimeInput carry the same API-reference gap; that is outside this audit. ## Review feedback - Automated review asked that the contract not restate part of `family:input-fields/FR10` and then that it not add a draft requirement that no current spec states. The contract now only cites FR10; the earlier FR13 row and its verification row are removed. The automated review approved the final head. ## Needs Review - **D1** — focus at the bottom-sheet month bounds: owned by #6304. - **D2** — stale calendar selection after clear: owned by #6935. - **Merge timing** — held until the 0.7.0 release is tagged. ## Writing rubric results - R1 narration: none; the contract states current behavior. - R2 research: none. - R3 evidence: facts and standards, not changes. - R4 rejected alternatives: none. - R5 change references: none. - R6 open questions: none. ## FR10 exact-head report ```json { "schemaVersion": 1, "component": "DateInput", "package": "core", "mode": "night-watch", "rubricVersion": "1.16.6", "repositoryBase": "1e883f86e7aa5c2be376671f746d79e5cfae769b", "repositoryHead": "4faee79d299c5f4661bfecbb01a7aade966440ee", "componentContractHead": "4faee79d299c5f4661bfecbb01a7aade966440ee", "inventory": {"closed": true, "rows": 13}, "score": {"before": 85.6, "after": 87.3, "beforeBlocks": 2, "afterBlocks": 2}, "unresolvedObjectiveGaps": [{"id": "D1", "rule": "A5", "owner": "#6304"}, {"id": "D2", "rule": "B15", "owner": "#6935"}], "unresolvedManualGaps": [], "remediations": [ {"id": "D3", "state": "verified-source", "evidence": "six part-styling props listed in all three references"}, {"id": "D4", "state": "verified-source", "evidence": "draft contract cites FR10 and names the shared clear glyph target"} ], "approvals": {"privateExactHeadSelfReview": "clean", "reviewSignal": "success (GitHub Actions)", "specOwner": "draft record only"}, "checks": {"local": "green; no local browser", "exactHeadCI": "success (run 38256902974)", "a11y": "0 violations across 26 owned stories", "rtl": "automatic and curated checks pass", "visual": "N/A product delta; gate drift matches an unrelated PR"}, "eligibility": {"eligible": false, "reasons": ["FR11 auto-merge inactive", "two open BLOCKs owned by contributor pull requests", "held until the 0.7.0 release is tagged"]} } ```
There was a problem hiding this comment.
Approval waits on a maintainer decision: current spec AST-043 already gives DateInput and DateTimeInput a presentation prop for choosing the picker surface and names it as the replacement for nativePicker, while this PR adds adaptations for the same choice under a draft record whose id main already uses for a different spec. A maintainer needs to either approve adaptations in current spec, saying how it combines with presentation and which prop nativePicker points to, or point this work at what AST-043 already covers. Whatever that decision, these fixes are needed:
- Point the
nativePickerdeprecation at the replacement current spec names, and if it stays, migrate the remainingnativePicker="never"uses in the DateInput CLI template, the locale story and the DateTimeInputTwoMonthCalendarstory. - Replace the production throw for
nativePickerplusadaptationswith a declared precedence and a development-only warning. - Keep the in-use latch when
adaptationsitself is added or removed; today the focused field is swapped out and loses focus. - Keep the latch's busy flag in React state, and attach the latch to a component-owned element rather than the caller's DOM handlers, which current spec routes to the input.
- Split the 4,845-line change, for example one component per pull request on a shared test harness.
[Automated review]
| * Mutually exclusive with `adaptations`. | ||
| * | ||
| * @default 'touch' | ||
| * @deprecated Use `adaptations`; the mapping above preserves idle surface |
There was a problem hiding this comment.
Current spec AST-043 (FR3, FR5) deprecates nativePicker toward presentation, which main already ships, so pointing it at adaptations gives one prop two different replacements. Please conform this deprecation to AST-043, or drop it until a maintainer updates that spec. The same applies to DateTimeInput.tsx:538.
| adaptations: ComponentAdaptations<DateInputAdaptationValue> | undefined, | ||
| ): void { | ||
| if (nativePicker !== undefined && adaptations !== undefined) { | ||
| throw new Error( |
There was a problem hiding this comment.
With nativePicker deprecated, AST-017 FR29d asks deprecated props to declare an old-plus-new precedence, and FR29 allows only a development-only diagnostic for that case; this throw crashes production renders. Consider letting adaptations win with a development-only warning, as AST-043 FR4 does for presentation.
| const {surface, onFocusCapture, onBlurCapture} = | ||
| useAdaptationSurfaceLatch(adaptedSurface); | ||
|
|
||
| if (adaptations !== undefined) { |
There was a problem hiding this comment.
This branch reads the raw prop, so adding or removing adaptations while the field is focused swaps the tree at once and drops the typed draft and focus (the same holds at DateTimeInput.tsx:2149). Latching whether a policy is present together with the surface would close this; focused and open-surface tests in both directions would pin it.
| } | ||
|
|
||
| return { | ||
| surface: isBusyRef.current ? rendered : resolved, |
There was a problem hiding this comment.
isBusyRef decides which tree renders, but handlers flip it without a render, which the react-component-runtime architecture's INV4 rules out: a transition rendered before focus can still commit a swap after focus enters. Holding the busy flag in state would let React see it.
|
(Posted by Cindy's agent.) Thank you, @imdreamrunner! Your theme-aware picker adaptations shaped where DateInput ended up: DateInput and DateTimeInput now take a |
Summary
native | popover | bottom-sheetadaptation values to DateInput and DateTimeInputnativePickerbehavior whenadaptationsis absentValidation
This draft is stacked on #6130 → #6127 → #6123 → #5543 and remains blocked on owner approval of AST-031. No spec approval was posted by the agent.