Skip to content

feat(Selector): add theme-aware presentation adaptations - #6130

Closed
imdreamrunner wants to merge 1 commit into
feat/component-adaptations-infrafrom
feat/selector-adaptations
Closed

imdreamrunner wants to merge 1 commit into
feat/component-adaptations-infrafrom
feat/selector-adaptations

Conversation

@imdreamrunner

Copy link
Copy Markdown
Contributor

Summary

  • add Selector.adaptations={{default, rules}} using theme-aware width/pointer conditions
  • preserve presentation as compatibility syntax; adaptive now resolves through the active Theme's md
  • keep MultiSelector on its existing inclusive 768px legacy policy
  • latch the selected surface for the lifetime of an open interaction
  • export the shared component-adaptation types and SelectorAdaptationValue

Compatibility

At the default md = 768, presentation="adaptive" now treats exactly 768px as the wider side, matching AST-012's exclusive below edge. Direct popover and bottom-sheet behavior is unchanged.

Evidence

  • focused Selector/MultiSelector/theme tests
  • Core and Storybook typechecks
  • real Chromium story play for fine-pointer bottom-sheet keyboard/focus/exit behavior
  • coarse-pointer popover measurements: 16px trigger text and 24×24 clear hit target
  • Selector a11y, RTL, and modal-close guards
  • full build and repository checks

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.

@vercel

vercel Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 9, 2026 4:53am UTC

Request Review

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.
@astracat-bot

astracat-bot Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 19, 2026, 10:35 PM UTC

@astracat-bot astracat-bot Bot left a comment

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.

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 KeyboardBottomSheetPolicy story) and can move to their own PR.
  • Renumber the adaptations record and its 19 code citations, because spec:AST-031 on main is now an unrelated record.

[Automated review]

{
default: 'popover',
rules: [
{when: {width: {below: 'md'}, pointer: 'coarse'}, value: 'bottom-sheet'},

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.

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.

Comment on lines +562 to +570
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)}.`,
);
}

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.

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

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.

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.

@cixzhang

cixzhang commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

(Posted by Cindy's agent.) Thank you, @imdreamrunner! Your Selector adaptations fed into how Selector chooses its surface: it now has a presentation prop, with adaptive as the default. Closing this one since that change covers it.

@cixzhang cixzhang closed this Nov 8, 2026
@github-actions
github-actions Bot deleted the feat/selector-adaptations branch November 9, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — c13e3b4d Deployed Sep 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants