Repository navigation
feat(Selector): add theme-aware presentation adaptations - #6130
imdreamrunner wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
fd9005a to
f1100aa
Compare
b716028 to
41726f9
Compare
f1100aa to
f5f7b46
Compare
41726f9 to
aab5641
Compare
f5f7b46 to
689b632
Compare
aab5641 to
93d6ccb
Compare
Admit the AST-031 authoring vocabulary — ComponentAdaptations,
ComponentAdaptationRule, ComponentAdaptationCondition — from the package
entry point, and add Selector's `adaptations={{default, rules}}` prop over a
new public SelectorAdaptationValue ('popover' | 'bottom-sheet') exported from
both the root and @astryxdesign/core/Selector. The condition compiler and the
useComponentAdaptations resolver stay package-internal.
The public value type is spelled as literals rather than aliased to the
internal ResolvedAdaptivePresentation, so consumer diagnostics never name an
unexported type; aliasing the other way would put the adaptive hook that
DropdownMenu and ContextMenu also use behind one component's public API. A
compile-time equality assertion keeps the two unions from drifting.
`presentation` keeps its meaning and its default. The two props are exclusive
at type level through a two-arm policy union INTERSECTED with the hasClear
union rather than folded into it, so the value contract keeps two arms instead
of four; a call with both defined throws before a surface opens, while an
explicitly spread `undefined` does not.
`presentation` is also validated at runtime rather than trusted. Its closed
set is popover, bottom-sheet, and adaptive; anything else — from JavaScript,
an untyped props bag, config, or a stale `presentation="modal"` — used to
index the policy map to undefined and resolve to an anchored popover,
reporting a wrong surface as a correct one. It now throws, naming the prop and
the value. Documented in the changeset and on the prop.
BREAKING: `presentation="adaptive"` is now `default: 'popover'` plus a
`{width: {below: 'md'}, pointer: 'coarse'}` bottom-sheet rule resolved against
the nearest Theme's `md`. The released query was `(max-width: 768px)`, which
included equality, so at exactly 768px a coarse-pointer Selector now anchors.
No per-callsite migration exists; moving the theme's `md` is the global one.
useSelectorPresentation now takes an already-resolved value and owns only
disclosure, latching, and the focus handoff. MultiSelector calls the unchanged
legacy adaptive hook itself, immediately where the controller used to, so its
query, its inclusive 768px edge, and its hook order are untouched. Menus are
not migrated.
Both pointer/surface combinations are covered, for different reasons. A coarse
pointer holding the anchored popover keeps its pointer-gated floors, which are
CSS media rules no policy can reach: measured in Chromium under a touch
context at 16px trigger text and a 24x24 clear-button hit area, and asserted
structurally plus through the injected CSS. A fine pointer opening the modal
sheet is NOT newly reachable — plain `presentation="bottom-sheet"` has always
rendered it on any pointer — so what the new Storybook play function adds is
real-browser evidence for that surface's keyboard contract, which had none:
jsdom stubs showModal and never runs the exit transition, so its focus
assertions test a simulation. The CI story-play guard runs it in Chromium. A
second story exercises a pointer-only `adaptations` rule so the docsite, a11y,
RTL, and visual passes see the new API.
Selector.spec.md is deliberately untouched: it is a `current`, approved record
and AST-031 is still a draft, so the contract edits wait for that approval.
Consumer docs carry the behavior as implementation evidence, projected into
the dense and translated surfaces as well as the English one, including the
pre-existing SSR limitation where `isDefaultOpen` plus a policy that changes
across hydration comes up closed — reproduced on unmigrated MultiSelector,
characterized in tests, and worked around with a non-changing policy.
689b632 to
68e51bf
Compare
93d6ccb to
c13e3b4
Compare
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This PR is on hold for a maintainer decision: no current spec on main covers the new Selector adaptations prop or its exported types, and making presentation="adaptive" exclusive at the theme's md changes behavior the current Selector contract keeps (DEC-1: "adaptive keeps its width-and-pointer query"). A Selector maintainer needs to provide or identify the governing spec for adaptations, and to update the Selector contract for the exact-768px edge and the new runtime throw on invalid presentation values, or to decline them. Whatever that decision, two changes are needed:
- Bring the PR under 2,000 authored lines: about 550 lines of tests and stories cover behavior that already ships (the coarse-popover, fine-sheet and SSR default-open suites and the
KeyboardBottomSheetPolicystory) and can move to their own PR. - Renumber the adaptations record and its 19 code citations, because
spec:AST-031onmainis now an unrelated record.
[Automated review]
| { | ||
| default: 'popover', | ||
| rules: [ | ||
| {when: {width: {below: 'md'}, pointer: 'coarse'}, value: 'bottom-sheet'}, |
There was a problem hiding this comment.
This rule makes adaptive exclusive at the theme's md: a coarse pointer at exactly 768px now gets the anchored popover instead of the bottom sheet. The current Selector contract (DEC-1) keeps adaptive's width-and-pointer query, so this edge needs a Selector maintainer to update that contract before it can land.
| if ( | ||
| !Object.prototype.hasOwnProperty.call(PRESENTATION_POLICIES, presentation) | ||
| ) { | ||
| throw new Error( | ||
| `<Selector presentation> must be one of ${Object.keys( | ||
| PRESENTATION_POLICIES, | ||
| ).join(', ')}; received ${JSON.stringify(presentation)}.`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
An unknown presentation used to open a popover; it now throws during render. The current Selector contract documents only TypeScript rejection for invalid values, so this behavior change needs the same maintainer decision.
|
|
||
| // The legacy `(max-width: 768px) and (pointer: coarse)` policy, resolved | ||
| // HERE rather than inside the shared controller. MultiSelector is explicitly | ||
| // out of scope for spec:AST-031's first migration, so it keeps its released |
There was a problem hiding this comment.
On main, spec:AST-031 is now an unrelated record (runtime integration feature composition). This and the other 18 citations of the adaptations record need its new id once a maintainer assigns one.
|
(Posted by Cindy's agent.) Thank you, @imdreamrunner! Your Selector adaptations fed into how Selector chooses its surface: it now has a |
Summary
Selector.adaptations={{default, rules}}using theme-aware width/pointer conditionspresentationas compatibility syntax;adaptivenow resolves through the active Theme'smdSelectorAdaptationValueCompatibility
At the default
md = 768,presentation="adaptive"now treats exactly 768px as the wider side, matching AST-012's exclusivebelowedge. Directpopoverandbottom-sheetbehavior is unchanged.Evidence
This draft is stacked on #6127 → #6123 → #5543 and remains blocked on owner approval of AST-031. No spec approval was posted by the agent.