An open source design system that's fully customizable and agent ready
TypeScript
fix(Layer): a Tooltip scrolls by CSS, and nothing watches its trigger move (#10472)
Cindy Zhangdef46d15d915
diff --git a/.changeset/layer-scroll-by-css.md b/.changeset/layer-scroll-by-css.mdnew file mode 100644index 0000000000..7737fe7fb6--- /dev/null+++ b/.changeset/layer-scroll-by-css.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A Tooltip's content scrolls by CSS alone, and nothing watches its trigger move. A Tooltip now has `overflow-y: auto` from its first frame, with no overscroll containment. It scrolls only while its content overflows, so a wheel over a Tooltip that fits still scrolls the page. Once a tall Tooltip has scrolled to its end, the next wheel moves on to the page, where before the page held. A Tooltip is now always a scroll container, so `position: sticky` and `scroll(nearest)` timelines inside its content resolve against the Tooltip. The layer runtime no longer reads the Tooltip's scroll size after its trigger moves, and it no longer observes a trigger that moves without resizing.++@cixzhangdiff --git a/docs/architecture/layer-runtime.md b/docs/architecture/layer-runtime.mdindex 9ff6a796a7..44394852c9 100644--- a/docs/architecture/layer-runtime.md+++ b/docs/architecture/layer-runtime.md@@ -217,7 +217,9 @@ and no option lets it overlap the anchor. Content that fits on some side keepsits own size there, and no option is sized to whatever room is left: a browserkeeps an open layer on the option it last used while that option still fits,so an anchor that moves takes the layer to the side now roomier instead of-shrinking it. The layer scrolls only while its content overflows. Chromium+shrinking it. Its `overflow-y` is `auto`, with no overscroll containment, so it scrolls+only while its content overflows and a fitting layer has no scroll range;+no read decides it. Chromiumtries no more than five options, so this list replaces the standard listrather than extending it.During a scroll, Chromium does not choose a CSS-anchored layer's option again,@@ -252,7 +254,7 @@ observed while the layer is open, so a layer opened with its anchor already outof view holds from its first frame. Whether a layer that keeps its anchor clearcovers its anchor or leaves the viewport, judged from its box without its owntransform (so an entry animation that starts it closer to the anchor does not-count), and whether its content overflows, is read inside `show()` and the+count), is read inside `show()` and theopen-remount path right after the popover is shown, and again while it is openfrom ResizeObserver callbacks and resize events, all of which run before theframe paints; the observers move to the replacement when the caller replaces@@ -265,17 +267,9 @@ frame after reads and applies. The scroll listeners subscribe to the window's ineach shadow root along the anchor's flat-tree path, because `scroll` and`scrollend` are not composed. A `scroll` only cancels a pending check orstarts the timer, and no handler reads layout. Chromium fires `scrollend` per wheel step, so a long-wheel scroll is checked more than once, never during the scroll itself. An-anchor that moves on screen without resizing, in layout or by a scroll, is-reported only by an intersection observer on the anchor, whose root is the-viewport shrunk to the anchor's rectangle and which re-arms from each report-that differs from its threshold; a report that finds an anchor which has not-moved wholly outside that rectangle means a scrolled container clips it, and a-second intersection observer, rooted at the viewport with a threshold of 0,-waits for the anchor to come back into view and then re-arms. A reported move-updates only whether the layer scrolls, in the next frame: it never checks the-box and never places the layer afresh, so the layer never changes side in the-middle of a scroll. Apart from the read after a scroll stops, a layer never+wheel scroll is checked more than once, never during the scroll itself. Nothing watches an anchor that moves on screen without+resizing: every option keeps the layer clear of its anchor, so the layer never+changes side in the middle of a scroll. Apart from the read after a scroll stops, a layer neverpaints at a geometry it is about to correct.### Current browser support behavior@@ -557,10 +551,10 @@ layers use Layer rendering without joining Escape/platform dismissal.reported keeps its top until it closes: when the cap lifts it grows downwardin place; when the keyboard rises it moves up above it and then holds.- **INV12 — The first frame is the settled frame.** No input to a layer's- viewport geometry is measured after paint and then applied, with three+ viewport geometry is measured after paint and then applied, with twoexceptions. The runtime observes anchor visibility for every layer, and,for a layer that keeps its anchor clear, whether it covers its anchor or- leaves the viewport and whether its content overflows; each is read before+ leaves the viewport; each is read beforefirst paint and, while the layer is open, from callbacks that run before theframe paints. The first exception is the check after a scroll stops(`spec:AST-059` DEC-8): once a scroll of the page or of a scrolling ancestor@@ -570,11 +564,8 @@ layers use Layer rendering without joining Escape/platform dismissal.scroll handler checks the box, re-picks or forces layout for a layer, and nooption of the layer's list overlaps its anchor, so a frame painted duringthe scroll can show the layer past the viewport edge but never over its- anchor. The second exception is whether a layer that keeps its anchor- clear scrolls: a same-size anchor's move, which an intersection observer- reports after paint, re-reads the layer's scroll and client heights in the- next frame and updates it; it never checks the box or re-picks. The- third exception is the software keyboard's cap (`spec:AST-059` FR10).+ anchor. The+ second exception is the software keyboard's cap (`spec:AST-059` FR10).A box's height cannot change on the compositor, so the cap changes once perkeyboard movement: when a rising keyboard has arrived, at once as a fallingkeyboard starts down, and at once for a keyboard that changes without@@ -584,9 +575,7 @@ layers use Layer rendering without joining Escape/platform dismissal.that opens with a keyboard up, when the keyboard moves, and before the firstpaint of a layer element the runtime swaps in while the layer is open.Otherwise a layer never paints at a geometry it is about to- correct, and the runtime polls nothing: an anchor that a scrolled- container hides is followed again when an intersection observer reports it- back in view.+ correct, and the runtime polls nothing.- **INV13 — One exit copy per closing layer.** A layer's close plays on at mostone exit copy, made by `placeLayerExitCopy`: drawn where the layer was drawn,inert, hidden from assistive technology, without ids, form names, or formdiff --git a/docs/specs/AST-059-layer-viewport-inset/spec.md b/docs/specs/AST-059-layer-viewport-inset/spec.mdindex feca8a29ef..cbf8a91a2b 100644--- a/docs/specs/AST-059-layer-viewport-inset/spec.md+++ b/docs/specs/AST-059-layer-viewport-inset/spec.md@@ -258,7 +258,8 @@ the app reaches every layer instead of the components that happen to read it.`overflow-y: auto` with no overscroll containment, and the runtime readsnothing to decide it: a wheel over a layer that fits still scrolls the page,and a tall layer's scroll chains to the page at its end, as native scrolling- does (FR3). The runtime authors both orders; a component passes no fallbacks+ does (FR3). `component:Tooltip` records what that means for content inside+ the layer: it is always a scroll container. The runtime authors both orders; a component passes no fallbacksof its own to an anchor-mode layer.- **FR5 — An off-screen anchor holds.** A layer whose anchor has left theviewport does not slide. It keeps the position the flips give it and its@@ -402,10 +403,10 @@ When this ships:- Add an invariant for FR8: no geometry input is measured after paint andthen applied; the first painted frame is the settled frame; no scroll framereads or forces layout for a layer (DEC-7, DEC-8).-- Positioning and INV12 describe the anchor-move intersection observers, a- re-read in every frame of a scroll, a re-pick after a scroll other than the- one DEC-8 keeps, and the read that decides whether a layer scrolls as- current behavior; they follow FR4, FR8, DEC-7, and DEC-8 when those ship.+- Positioning and INV12 follow FR4, FR8, DEC-7 and DEC-8: one combined list+ from the first frame, CSS overflow for whether a layer scrolls, no observer+ of an anchor that moves without resizing, and one check in the first+ painted frame after a scroll stops.- INV11 and INV12 add the software keyboard's cap (FR9) and FR10's timing:the cap is read from the layer's own box without its entrance transform whenthe keyboard moves, and it changes once per keyboard movement, the onediff --git a/docs/specs/components/Tooltip/Tooltip.spec.md b/docs/specs/components/Tooltip/Tooltip.spec.mdindex 9f4a6be717..321a2371aa 100644--- a/docs/specs/components/Tooltip/Tooltip.spec.md+++ b/docs/specs/components/Tooltip/Tooltip.spec.md@@ -47,7 +47,7 @@ system_specs: [spec:AST-003, spec:AST-017, spec:AST-086/FR12, spec:AST-086/FR14]| Public contract | `Tooltip` with `content`, `children` or `anchorRef`, `placement` (`above`), `alignment` (`center`), `delay` (200), `hideDelay` (0), `focusTrigger` (`auto`), `touchTrigger` (`auto`), `isEnabled`, `isOpen`, `isDefaultOpen`, `onOpenChange`, and `hasHoverIndication`; target `tooltip`. `useTooltip` takes the same `touchTrigger`, and its return includes imperative `show` and `hide` (FR12). A tooltip pins through `show()` and `hide()` (FR9, FR10); Tooltip has no toggle prop or option, and `component:InfoTip` pins this way. || Behavior | A `role="tooltip"` layer that describes its trigger. It opens on hover after `delay`, on keyboard focus, and on a tap that `touchTrigger` allows; it stays open while the pointer moves onto it, and closes on leave, Escape, or pressing the trigger (a press that focuses a text field reopens it). With `touchTrigger="none"`, no touch or pen tap opens it. `useTooltip`'s `show()` pins it open until `hide()`, Escape, a press outside, or focus leaving, while hover and focus still preview an unpinned tooltip (FR9, FR12). `component:InfoTip`'s button pins and closes it on a click, tap, Enter, or Space. || End-user impact | Mouse, keyboard, and touch users can each reveal the hint, move onto it, and dismiss it; screen-reader users hear it as the trigger's description. Under the default `touchTrigger="auto"`, a tap on a trigger that performs an action performs only that action. When a button pins it through `show()`, as `component:InfoTip`'s does, people on touch, keyboard, or a screen reader can keep help open to read it, and hear it once when it pins. |-| Builder impact | `touchTrigger` answers one question: is it safe to consume a tap to show this tooltip (DEC-1)? Keep the default `auto` on a trigger that performs an action, pass `tap` where a tap only reveals the tooltip, and pass `none` where a tap must never show it. Help behind an info icon uses `component:InfoTip`; an app's own toggle-style trigger is a button that calls `useTooltip`'s `show()` and `hide()` (DEC-1). |+| Builder impact | `touchTrigger` answers one question: is it safe to consume a tap to show this tooltip (DEC-1)? Keep the default `auto` on a trigger that performs an action, pass `tap` where a tap only reveals the tooltip, and pass `none` where a tap must never show it. Help behind an info icon uses `component:InfoTip`; an app's own toggle-style trigger is a button that calls `useTooltip`'s `show()` and `hide()` (DEC-1). The layer is always a scroll container (`overflow-y: auto`), so `position: sticky` and `scroll(nearest)` timelines inside its content resolve against the layer, not the page. || Compatibility/readiness | `useTooltip` adds `show` and `hide` (FR12), an additive change. `touchTrigger` keeps its released values and its default `auto`, and pinning adds no public prop. Nine implementation gaps (see Current-state impact). || Review checks | Reject a tooltip that cannot be hovered or dismissed (WCAG 1.4.13), one that opens on a tap's focus or on pointer focus of a trigger that is not a text field, a lost `aria-describedby` link, a tap under `touchTrigger="auto"` that both performs the trigger's action and shows the tooltip, a pinned tooltip that closes on pointer leave or lets Escape pass to the layer beneath, a pinning trigger that is not a native button or lacks `aria-expanded`, or a toggle prop or option on Tooltip. || Governing rules | WCAG 1.4.13, 2.1.1; `family:overlay-dismissal`; `spec:AST-003` FR4; `spec:AST-017` (lifecycle); `architecture:public-component-api` INV9, INV21; `architecture:layer-runtime`; `architecture:interaction-modality`; `architecture:component-theming-surface`. |@@ -67,14 +67,20 @@ in `Tooltip.doc.mjs`.and its default `auto`. A disabled control is not an action, so its reasonopens on a tap (FR5); that restoration ships on its own as a patch `[fix]`- Compatibility class: additive: `useTooltip`'s return gains `show` and `hide`- (FR12); no public prop, default, DOM, styling, or target change; pinning- (FR9, FR10) runs through `show()` and `hide()` and adds no other public- surface+ (FR12); no public prop, default, DOM, or target change; pinning (FR9,+ FR10) runs through `show()` and `hide()` and adds no other public surface;+ one styling-output change, below- Controlled/uncontrolled behavior: uncontrolled by default; `isOpen` forces thestate, and a controlled tooltip reports close requests through`onOpenChange(false)` without closing itself (FR7); `show()` and `hide()` ona controlled tooltip report the request through `onShow` and `onHide` and donot change the state itself (FR12)+- Styling output: the layer is always a scroll container (`overflow-y: auto`,+ with no overscroll containment). Content that relied on the page as its+ scroll container for `position: sticky` or a `scroll(nearest)` timeline now+ resolves against the layer; such content names its timeline (for example+ `scroll(root)`) or moves the sticky element outside the tooltip. A patch+ `[fix]` styling-output change, with no prop or default change- Migration decision: none### CLN-0028 — Remove the surface registry behind `hasInteractiveAncestor`@@ -226,10 +232,10 @@ Consumer migration instructions belong in consumer docs and release notes.## Design relationships-| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |-| ---------------- | --------------------------------------------------- | ------------------------------ | -------------- | ------------------ |-| Tooltip surface | Presents the current painted overlay surface. | Current source and public docs | Supporting | FR1 |-| Tooltip text | Presents supplied content within the owned surface. | Current source and public docs | Prominent | FR1 |+| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |+| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | -------------- | ------------------ |+| Tooltip surface | Presents the current painted overlay surface. The layer is always a scroll container (`overflow-y: auto`), so `position: sticky` and `scroll(nearest)` timelines inside its content resolve against the layer, not the page. | Current source and public docs | Supporting | FR1 |+| Tooltip text | Presents supplied content within the owned surface. | Current source and public docs | Prominent | FR1 |The trigger is caller-owned and outside this anatomy. The current implementationhas no arrow element.@@ -255,18 +261,19 @@ has no arrow element.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |-| FR1 | `Tooltip.test.tsx` role/content suite | Rendered surface and supplied content | Removing the surface or content fails existing tooltip role and text assertions. | `audit:Tooltip/anatomy` |-| FR2–FR8 | `Tooltip.test.tsx`; `useTooltip.test.tsx` | Hover, focus, tap, Escape, controlled, default open; `auto` judged when focus arrives (roving member, `<summary>`, non-focusable wrapper) | Wrong open or close for an input fails. | `audit:Tooltip/behavior` |-| FR4, FR7 reattach | `useTooltip.test.tsx` detach-and-attach suite; `DropdownMenuTooltip.a11y.chromium.spec.ts` | A trigger that detaches while open; keyboard and pointer focus that arrive while detached; a data menu, a compound menu and a bottom sheet: a pointer pick, a keyboard pick, and Escape | A tooltip left open after its trigger detaches, a tooltip after a pointer pick, or none for returned keyboard focus, fails. | `audit:Tooltip/behavior` |-| AR1–AR4 | `Tooltip.a11y.test.tsx`; `Tooltip.a11y.chromium.spec.ts`; `TooltipHoverBridge.a11y.chromium.spec.ts`; `TooltipFocusReturn.a11y.chromium.spec.ts` | Real-browser hover bridge and focus return | A tooltip that vanishes on the way to it or strands focus fails. | `audit:Tooltip/accessibility` |-| AR5 | `Tooltip.a11y.test.tsx`; `Tooltip.a11y.chromium.spec.ts` | Wrapped, text, anchor, and hook triggers | A lost role, description, keyboard-focus show, or Escape dismissal fails; focus-leave hide, hover show, and leave hide run as advisory rows (Current-state impact). | `audit:Tooltip/accessibility` |-| FR5 | `Tooltip.test.tsx` touch suite; `TouchTrigger.a11y.chromium.spec.ts` finger and pen cases; `useTouchTrigger.test.ts` and `touchTriggerTargets.test.tsx` disabled-control cases | Tap open, scroll, second tap, tap outside; `touchTrigger` `auto`, `tap`, and `none`; an action trigger and a trigger that performs no action; a trigger in running text; a disabled control inside a clickable row | A tap that fails to open or close as stated, opens the tooltip on a trigger that performs an action under `auto` or on any tap under `none`, or leaves a disabled control's reason shut fails. | `audit:Tooltip/behavior` |-| FR9, FR10, AR6 | `InfoTip.pin.test.tsx`; `TouchTrigger.a11y.chromium.spec.ts` InfoTip pin and mouse cases; `layerDismissalFamilies.test.tsx` pinned Tooltip over a Dialog | Click, Enter, Space, and tap pin; second press, press outside, focus leaving, and Escape close; pointer leave keeps the pin; a mouse or pen press on a hover preview; a pinning button inside a ClickableCard, an Item row, and a `<label>` | A press that does not pin or close as stated, a pin lost on pointer leave, a hover preview that closes and reopens on a mouse or pen press, a missing or stale `aria-expanded` or `aria-controls`, a second announcement, or a pinning press that also activates the card, row, or labelled control around the button, fails. | `audit:Tooltip/behavior` |-| FR11 | `Tooltip.test.tsx` surface-press suite; `FileInputTooltipPress.a11y.chromium.spec.ts` | A tooltip inside a clickable container and inside a `<label>`; FileInput compact and dropzone status tooltips, with a click on the empty dropzone as the positive control | A click on tooltip text that runs the container's click handler, checks or focuses a labelled control, or opens the file picker fails. | — |-| FR12 | `useTooltip.showHide.test.tsx`; `InfoTip.pin.test.tsx` press-on-a-preview cases; `Tooltip.stories.tsx` `CustomToggleTrigger` | An app button calls `show()` and `hide()`; Escape, a press outside, and focus leaving close a shown tooltip; a controlled `isOpen`; `show()` while `isEnabled` is false; a `show()` hold begun during a trigger press that ends on the help or away from both | A tooltip that `show()` does not open or hold, `hide()` does not close, a close path that leaves it open, a missing `onShow` or `onHide`, a `show()` that overrides a controlled `isOpen`, a disabled tooltip that `show()` opens, or a hold begun during a trigger press that outlives a press ending off the trigger fails | — |-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current target | Missing, extra, prefixed, or stale mappings fail repository validation. | `audit:Tooltip/theming` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |+| FR1 | `Tooltip.test.tsx` role/content suite | Rendered surface and supplied content | Removing the surface or content fails existing tooltip role and text assertions. | `audit:Tooltip/anatomy` |+| FR1 scroll container | `TooltipTallContent.a11y.browser.spec.ts` sticky case | A tall tooltip whose content starts with a `position: sticky` child, scrolled inside | The sticky child scrolls away with the content, or pins to the page instead of the tooltip | — |+| FR2–FR8 | `Tooltip.test.tsx`; `useTooltip.test.tsx` | Hover, focus, tap, Escape, controlled, default open; `auto` judged when focus arrives (roving member, `<summary>`, non-focusable wrapper) | Wrong open or close for an input fails. | `audit:Tooltip/behavior` |+| FR4, FR7 reattach | `useTooltip.test.tsx` detach-and-attach suite; `DropdownMenuTooltip.a11y.chromium.spec.ts` | A trigger that detaches while open; keyboard and pointer focus that arrive while detached; a data menu, a compound menu and a bottom sheet: a pointer pick, a keyboard pick, and Escape | A tooltip left open after its trigger detaches, a tooltip after a pointer pick, or none for returned keyboard focus, fails. | `audit:Tooltip/behavior` |+| AR1–AR4 | `Tooltip.a11y.test.tsx`; `Tooltip.a11y.chromium.spec.ts`; `TooltipHoverBridge.a11y.chromium.spec.ts`; `TooltipFocusReturn.a11y.chromium.spec.ts` | Real-browser hover bridge and focus return | A tooltip that vanishes on the way to it or strands focus fails. | `audit:Tooltip/accessibility` |+| AR5 | `Tooltip.a11y.test.tsx`; `Tooltip.a11y.chromium.spec.ts` | Wrapped, text, anchor, and hook triggers | A lost role, description, keyboard-focus show, or Escape dismissal fails; focus-leave hide, hover show, and leave hide run as advisory rows (Current-state impact). | `audit:Tooltip/accessibility` |+| FR5 | `Tooltip.test.tsx` touch suite; `TouchTrigger.a11y.chromium.spec.ts` finger and pen cases; `useTouchTrigger.test.ts` and `touchTriggerTargets.test.tsx` disabled-control cases | Tap open, scroll, second tap, tap outside; `touchTrigger` `auto`, `tap`, and `none`; an action trigger and a trigger that performs no action; a trigger in running text; a disabled control inside a clickable row | A tap that fails to open or close as stated, opens the tooltip on a trigger that performs an action under `auto` or on any tap under `none`, or leaves a disabled control's reason shut fails. | `audit:Tooltip/behavior` |+| FR9, FR10, AR6 | `InfoTip.pin.test.tsx`; `TouchTrigger.a11y.chromium.spec.ts` InfoTip pin and mouse cases; `layerDismissalFamilies.test.tsx` pinned Tooltip over a Dialog | Click, Enter, Space, and tap pin; second press, press outside, focus leaving, and Escape close; pointer leave keeps the pin; a mouse or pen press on a hover preview; a pinning button inside a ClickableCard, an Item row, and a `<label>` | A press that does not pin or close as stated, a pin lost on pointer leave, a hover preview that closes and reopens on a mouse or pen press, a missing or stale `aria-expanded` or `aria-controls`, a second announcement, or a pinning press that also activates the card, row, or labelled control around the button, fails. | `audit:Tooltip/behavior` |+| FR11 | `Tooltip.test.tsx` surface-press suite; `FileInputTooltipPress.a11y.chromium.spec.ts` | A tooltip inside a clickable container and inside a `<label>`; FileInput compact and dropzone status tooltips, with a click on the empty dropzone as the positive control | A click on tooltip text that runs the container's click handler, checks or focuses a labelled control, or opens the file picker fails. | — |+| FR12 | `useTooltip.showHide.test.tsx`; `InfoTip.pin.test.tsx` press-on-a-preview cases; `Tooltip.stories.tsx` `CustomToggleTrigger` | An app button calls `show()` and `hide()`; Escape, a press outside, and focus leaving close a shown tooltip; a controlled `isOpen`; `show()` while `isEnabled` is false; a `show()` hold begun during a trigger press that ends on the help or away from both | A tooltip that `show()` does not open or hold, `hide()` does not close, a close path that leaves it open, a missing `onShow` or `onHide`, a `show()` that overrides a controlled `isOpen`, a disabled tooltip that `show()` opens, or a hold begun during a trigger press that outlives a press ending off the trigger fails | — |+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current target | Missing, extra, prefixed, or stale mappings fail repository validation. | `audit:Tooltip/theming` |Read from source, with no focused test yet:diff --git a/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json b/internal/eslint-plugin-astryx/no-comment-provenance.baseline.jsonindex 9d2ddbdcca..83c36ce4a7 100644--- a/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json+++ b/internal/eslint-plugin-astryx/no-comment-provenance.baseline.json@@ -539,7 +539,6 @@"FR1","FR1","FR3",- "FR3","FR4","FR4","FR4",diff --git a/internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.json b/internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.jsonindex 9703aa8ef0..3b6e7cc7e6 100644--- a/internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.json+++ b/internal/eslint-plugin-astryx/no-raw-private-attribute.baseline.json@@ -43,10 +43,6 @@"data-astryx-input-group-item","data-astryx-input-group-item"],- "packages/core/src/Layer/layerSlideRules.ts": [- "data-astryx-clears-anchor",- "data-astryx-layer-scrolls"- ],"packages/core/src/MultiSelector/MultiSelector.tsx": ["data-astryx-press","data-astryx-press",diff --git a/packages/core/src/Layer/layerSlideRules.ts b/packages/core/src/Layer/layerSlideRules.tsindex 29c28233d7..6e1ee52046 100644--- a/packages/core/src/Layer/layerSlideRules.ts+++ b/packages/core/src/Layer/layerSlideRules.ts@@ -235,19 +235,6 @@ export function getAnchorClearFallbacks(placement: LayerPlacement): string {return `flip-block, ${besideRuleName('end')}, ${besideRuleName('start')}, ${fitRuleName(placement)}, ${fitRuleName(opposite)}`;}-/**- * The attribute the runtime sets on a layer that keeps its anchor clear while- * its content overflows the box it was given; only then does it scroll, so a- * layer that fits stays a plain box and a wheel over it still scrolls the- * page.- */-export const LAYER_SCROLLS_ATTRIBUTE = 'data-astryx-layer-scrolls';--/** Lets a layer whose content overflows scroll it. */-function scrollsCss(): string {- return `[${LAYER_SCROLLS_ATTRIBUTE}]{overflow-y:auto;overscroll-behavior-block:contain;}`;-}-/*** Every slide rule, for every placement and alignment, and the beside and fit* rules.@@ -264,7 +251,6 @@ export function slideRulesCss(): string {besideRule('start'),fitRule('above'),fitRule('below'),- scrollsCss(),].join('');}diff --git a/packages/core/src/Layer/useLayer.test.tsx b/packages/core/src/Layer/useLayer.test.tsxindex 73383d6c5e..12ef2fa689 100644--- a/packages/core/src/Layer/useLayer.test.tsx+++ b/packages/core/src/Layer/useLayer.test.tsx@@ -3074,38 +3074,6 @@ describe('a layer that keeps its anchor clear (spec:AST-059 FR4)', () => {const TRIGGER = rect(300, 400, 30, 100);- /**- * An intersection report as an engine makes it: the target's box, and the- * root's box, which is the viewport shrunk by the observer's root margin.- */- function report(- options: IntersectionObserverInit | undefined,- box: DOMRect,- intersectionRatio: number,- isIntersecting = intersectionRatio > 0,- viewport = {- width: document.documentElement.clientWidth,- height: document.documentElement.clientHeight,- },- ) {- const [top = 0, right = 0, bottom = 0, left = 0] = (- options?.rootMargin ?? '0px 0px 0px 0px'- )- .split(' ')- .map(value => -parseFloat(value));- return {- intersectionRatio,- isIntersecting,- boundingClientRect: box,- rootBounds: rect(- top,- left,- viewport.height - bottom - top,- viewport.width - right - left,- ),- } as unknown as IntersectionObserverEntry;- }-/** Let the next animation frame run, as the browser does before it paints. */async function nextFrame() {await act(@@ -3306,8 +3274,8 @@ describe('a layer that keeps its anchor clear (spec:AST-059 FR4)', () => {const {container} = render(<ClearHarness />);await user.click(container.querySelector('button')!);// Mid-scroll: the trigger has moved under the layer's stale box, which- // reads as covering it and past the viewport. A scroll is read only once- // it has painted, by the anchor-move observer.+ // reads as covering it and past the viewport. A scroll is checked only+ // after it stops.spy.mockRestore();placeBoxes(rect(-40, 380, 30, 100), rect(-60, 350, 100, 200));act(() => {@@ -3481,29 +3449,22 @@ describe('a layer that keeps its anchor clear (spec:AST-059 FR4)', () => {expect(placedAfresh()).toBe(0);});- it('scrolls only while its content overflows the box it was given', async () => {+ it('scrolls once its content overflows, by CSS alone, with no read of its scroll size', async () => {const user = userEvent.setup();placeBoxes(TRIGGER, rect(200, 350, 100, 200));- let scrollHeight = 100;- vi.spyOn(HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(- () => scrollHeight,+ const scrollSizeReads = vi.spyOn(+ HTMLElement.prototype,+ 'scrollHeight',+ 'get',);- vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(100);const {container, getByText} = render(<ClearHarness />);await user.click(getByText('Trigger'));const layerEl = container.querySelector('[popover]') as HTMLElement;- // A layer that fits stays a plain box.- expect(layerEl).not.toHaveAttribute('data-astryx-layer-scrolls');-- await user.click(getByText('Hide'));- scrollHeight = 900;- await user.click(getByText('Trigger'));- expect(layerEl).toHaveAttribute('data-astryx-layer-scrolls');+ expect(layerEl.className).toContain('useLayer__styles.scrollsOnOverflow');+ expect(scrollSizeReads).not.toHaveBeenCalled();const css =document.getElementById('astryx-layer-slide-rules')?.textContent ?? '';- expect(css).toContain(- '[data-astryx-layer-scrolls]{overflow-y:auto;overscroll-behavior-block:contain;}',- );+ expect(css).not.toContain('overscroll-behavior');});it('re-reads its geometry while open when it or its content resizes', async () => {@@ -3544,291 +3505,6 @@ describe('a layer that keeps its anchor clear (spec:AST-059 FR4)', () => {vi.unstubAllGlobals();});- it('follows a trigger that moves in layout without resizing, and leaves its placement to the engine', async () => {- const observers: {- callback: (entries: IntersectionObserverEntry[]) => void;- options: IntersectionObserverInit;- disconnected: boolean;- }[] = [];- vi.stubGlobal(- 'IntersectionObserver',- class {- record: (typeof observers)[number];- constructor(- callback: (entries: IntersectionObserverEntry[]) => void,- options: IntersectionObserverInit,- ) {- this.record = {callback, options, disconnected: false};- observers.push(this.record);- }- observe() {}- disconnect() {- this.record.disconnected = true;- }- unobserve() {}- },- );- const user = userEvent.setup();- const spy = placeBoxes(TRIGGER, rect(200, 350, 100, 200));- const {getByText} = render(<ClearHarness />);- await user.click(getByText('Trigger'));- expect(placedAfresh()).toBe(0);- // The move observer's root is the viewport shrunk to the trigger's rect.- const move = observers.find(o => o.options?.root === document);- expect(move?.options.threshold).toBe(1);- expect(move?.options.rootMargin).toBe(- `-300px ${-(document.documentElement.clientWidth - 500)}px ${-(document.documentElement.clientHeight - 330)}px -400px`,- );-- // Its initial report: fully inside its own rect.- act(() => move?.callback([report(move.options, TRIGGER, 1)]));- expect(placedAfresh()).toBe(0);-- // The trigger moves, and the layer now reads as covering it.- spy.mockRestore();- placeBoxes(TRIGGER, rect(16, 350, 688, 300));- const before = observers.length;- act(() => move?.callback([report(move.options, TRIGGER, 0.4)]));- // Re-armed on the new rect at once.- expect(move?.disconnected).toBe(true);- expect(observers.length).toBe(before + 1);- // A move never places the layer afresh: CSS anchor positioning places it.- await nextFrame();- expect(placedAfresh()).toBe(0);- vi.unstubAllGlobals();- });-- it('follows a move from its report alone: no layout read, armed on the reported box', async () => {- type Record = {- callback: (entries: IntersectionObserverEntry[]) => void;- options: IntersectionObserverInit;- };- const observers: Record[] = [];- vi.stubGlobal(- 'IntersectionObserver',- class {- constructor(- callback: (entries: IntersectionObserverEntry[]) => void,- options: IntersectionObserverInit,- ) {- observers.push({callback, options});- }- observe() {}- disconnect() {}- unobserve() {}- },- );- const moves = () =>- observers.filter(- o => o.options?.root === document && o.options.rootMargin != null,- );- const latest = () => moves()[moves().length - 1];- vi.spyOn(document.documentElement, 'clientWidth', 'get').mockReturnValue(- 1280,- );- viewport720();- const user = userEvent.setup();- const spy = placeBoxes(TRIGGER, rect(200, 350, 100, 200));- const {getByText} = render(<ClearHarness />);- await user.click(getByText('Trigger'));- expect(latest().options.rootMargin).toBe('-300px -780px -390px -400px');-- // Every frame of a scroll reports a move. Following it reads no layout:- // the box and the viewport come from the report.- const width = vi.spyOn(document.documentElement, 'clientWidth', 'get');- const height = vi.spyOn(document.documentElement, 'clientHeight', 'get');- const triggerReads = () =>- spy.mock.contexts.filter(- el => !(el as HTMLElement).hasAttribute('popover'),- ).length;- const readsBefore = triggerReads();- width.mockClear();- height.mockClear();- const scrolled = rect(247.5, 400, 30, 100);- const screen = {width: 1280, height: 720};- act(() =>- latest().callback([- report(latest().options, scrolled, 0.4, true, screen),- ]),- );- // Armed on the reported box, as a fresh read of it would arm it.- expect(latest().options.rootMargin).toBe('-247px -780px -442px -400px');- // A move under a pixel leaves the ratio at 1; the reported box shows it.- const nudged = rect(247.25, 400, 30, 100);- act(() =>- latest().callback([report(latest().options, nudged, 1, true, screen)]),- );- expect(moves().length).toBe(3);- expect(latest().options.rootMargin).toBe('-247px -780px -442px -400px');- expect(triggerReads()).toBe(readsBefore);- expect(width).not.toHaveBeenCalled();- expect(height).not.toHaveBeenCalled();- vi.unstubAllGlobals();- });-- it('handles a move its observer reports in the next frame, never in the reporting task, and never checks the box or places the layer afresh', async () => {- // During a scroll, CSS anchor positioning alone places the layer- // (spec:AST-059 FR4). Several reports in one frame share one call.- const observers: {- callback: (entries: IntersectionObserverEntry[]) => void;- options: IntersectionObserverInit;- }[] = [];- vi.stubGlobal(- 'IntersectionObserver',- class {- constructor(- callback: (entries: IntersectionObserverEntry[]) => void,- options: IntersectionObserverInit,- ) {- observers.push({callback, options});- }- observe() {}- disconnect() {}- unobserve() {}- },- );- const latestMove = () =>- observers.filter(o => o.options?.rootMargin != null).at(-1);- const user = userEvent.setup();- const spy = placeBoxes(TRIGGER, rect(200, 350, 100, 200));- const {container, getByText} = render(<ClearHarness />);- await user.click(getByText('Trigger'));- const layerEl = container.querySelector('[popover]') as HTMLElement;- act(() => {- const move = latestMove();- move?.callback([report(move.options, TRIGGER, 1)]);- });- await nextFrame();- expect(placedAfresh()).toBe(0);-- // A scroll carries the trigger under the layer; the observer reports it- // after the frame that painted the move, twice before the next frame.- spy.mockRestore();- const reads = vi.fn();- const covering = rect(16, 350, 688, 300);- vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(- function (this: HTMLElement) {- if (!this.hasAttribute('popover')) {- return TRIGGER;- }- reads();- return covering;- },- );- act(() => {- const first = latestMove();- first?.callback([report(first.options, TRIGGER, 0.4)]);- const second = latestMove();- second?.callback([report(second.options, TRIGGER, 0.6)]);- });- expect(placedAfresh()).toBe(0);- expect(reads).not.toHaveBeenCalled();-- // The next frame neither reads the layer's box nor places it afresh, so- // the layer does not jump to another side mid-scroll.- await nextFrame();- expect(reads).not.toHaveBeenCalled();- expect(placedAfresh()).toBe(0);- expect(layerEl.style.display).not.toBe('none');-- // A later move does neither either.- act(() => {- const move = latestMove();- move?.callback([report(move.options, TRIGGER, 0.5)]);- });- await nextFrame();- expect(reads).not.toHaveBeenCalled();- expect(placedAfresh()).toBe(0);- vi.unstubAllGlobals();- });-- it('follows a move that spans several frames and never goes idle while a scrolled container clips its trigger', async () => {- type Entry = IntersectionObserverEntry;- const observers: {- callback: (entries: Entry[]) => void;- options: IntersectionObserverInit;- disconnected: boolean;- }[] = [];- vi.stubGlobal(- 'IntersectionObserver',- class {- record: (typeof observers)[number];- constructor(- callback: (entries: Entry[]) => void,- options: IntersectionObserverInit,- ) {- this.record = {callback, options, disconnected: false};- observers.push(this.record);- }- observe() {}- disconnect() {- this.record.disconnected = true;- }- unobserve() {}- },- );- const moves = () =>- observers.filter(- o => o.options?.root === document && o.options.rootMargin != null,- );- const visibilities = () =>- observers.filter(- o => o.options?.root === document && o.options.rootMargin == null,- );- const latest = () => moves()[moves().length - 1];- const user = userEvent.setup();- let spy = placeBoxes(TRIGGER, rect(200, 350, 100, 200));- const {getByText} = render(<ClearHarness />);- await user.click(getByText('Trigger'));- expect(placedAfresh()).toBe(0);-- // A fresh observer's first report already differs: the trigger kept- // moving after its rectangle was read, as in a smooth scroll. That is a- // move: it re-arms at the reported ratio, and leaves placement to CSS.- spy.mockRestore();- spy = placeBoxes(TRIGGER, rect(16, 350, 688, 300));- let armed = moves().length;- act(() => latest().callback([report(latest().options, TRIGGER, 0.7)]));- expect(moves().length).toBe(armed + 1);- expect(latest().options.threshold).toBe(0.7);- await nextFrame();- expect(placedAfresh()).toBe(0);-- // A first report of 0 for a trigger that moved since the observer read- // its rectangle re-arms at once on the new rectangle.- spy.mockRestore();- const moved = rect(260, 400, 30, 100);- spy = placeBoxes(moved, rect(16, 350, 688, 300));- armed = moves().length;- act(() => latest().callback([report(latest().options, moved, 0)]));- expect(moves().length).toBe(armed + 1);- expect(latest().options.threshold).toBe(1);-- // A first report of 0 for a trigger that has not moved: a scrolled- // container clips it. No timer runs; a visibility observer rooted at the- // viewport waits for it to come back into view, however long that takes.- const timers = vi.spyOn(globalThis, 'setTimeout');- armed = moves().length;- act(() => latest().callback([report(latest().options, moved, 0)]));- expect(moves().length).toBe(armed);- expect(timers).not.toHaveBeenCalled();- const visibility = visibilities()[visibilities().length - 1];- expect(visibility?.options.threshold).toBe(0);- act(() =>- visibility?.callback([report(visibility.options, moved, 0, false)]),- );- expect(moves().length).toBe(armed);- // Back in view: it re-reads and re-arms, and the visibility observer goes.- act(() =>- visibility?.callback([report(visibility.options, moved, 0.2, true)]),- );- expect(moves().length).toBe(armed + 1);- expect(visibility?.disconnected).toBe(true);- expect(timers).not.toHaveBeenCalled();- spy.mockRestore();- vi.unstubAllGlobals();- });-it('moves its open-state observers to a trigger the caller replaces while it is open', async () => {const observed: Element[] = [];const disconnected: Element[][] = [];@@ -3959,5 +3635,8 @@ describe('a layer that keeps its anchor clear (spec:AST-059 FR4)', () => {getPositionTryFallbacks('above', 'center'),);expect(layerEl.style.alignSelf).toBe('');+ expect(layerEl.className).not.toContain(+ 'useLayer__styles.scrollsOnOverflow',+ );});});diff --git a/packages/core/src/Layer/useLayer.tsx b/packages/core/src/Layer/useLayer.tsxindex 10b60e9757..eda855fde9 100644--- a/packages/core/src/Layer/useLayer.tsx+++ b/packages/core/src/Layer/useLayer.tsx@@ -42,7 +42,6 @@ import {settledBox} from './settledBox';import {layerInsetProperties} from './layerInset';import {LAYER_CLEARANCE_PROPERTY,- LAYER_SCROLLS_ATTRIBUTE,ensureSlideRules,anchorClearAlignment,getAnchorClearFallbacks,@@ -84,6 +83,13 @@ const styles = stylex.create({'--_layer-keyboard-overflow': overflow,'--_layer-keyboard-inset-block-end': inset,}),+ // A layer that keeps its anchor clear scrolls only once its content+ // overflows the box it was given. A layer that fits has no scroll range, so+ // a wheel over it scrolls the page. Nothing contains the scroll, so a tall+ // layer chains to the page at its end.+ scrollsOnOverflow: {+ overflowY: 'auto',+ },// Base reset for all layersbase: {marginBlockStart: 0,@@ -594,198 +600,19 @@ function failsAnchor(layer: HTMLElement, anchor: HTMLElement): boolean {* option of its one combined fallback list keeps it clear of its anchor, and* the engine picks one. Where the box still covers the anchor or, while the* anchor is in view, leaves the viewport on the block axis, the layer is- * placed afresh (`placeAfresh`) from that list. Then it scrolls only if its- * content overflows the box it was given (FR3). The runtime calls this in the+ * placed afresh (`placeAfresh`) from that list. The runtime calls this in the* same task as every show and remount, and while the layer is open whenever* its size, its content's size, its anchor's size or the viewport changes;* each of those reads lands before the next frame paints. It also runs once* in the first frame painted after a scroll of the anchor stops* (`observeScrollStop`), because during a scroll the browser does not choose- * an option again. A same-size anchor that moves on screen, in layout or- * because something scrolled, is reported after paint by the anchor-move- * observer. That call does not check the box and never places the layer- * afresh, so the layer never jumps to another side mid-scroll.+ * an option again. Nothing watches an anchor that moves without resizing, so+ * the layer never jumps to another side mid-scroll.*/-function keepAnchorClear(- layer: HTMLElement,- anchor: HTMLElement | null,- cause: 'change' | 'move' = 'change',-): void {- if (cause === 'change' && anchor && failsAnchor(layer, anchor)) {+function keepAnchorClear(layer: HTMLElement, anchor: HTMLElement | null): void {+ if (anchor && failsAnchor(layer, anchor)) {placeAfresh(layer);}- // A layer that fits has no scroll range and stays a plain box, so a wheel- // over it still scrolls the page.- layer.toggleAttribute(- LAYER_SCROLLS_ATTRIBUTE,- layer.scrollHeight > layer.clientHeight + 1,- );-}--/** An element's box in client px, as a rect read or an observer reports it. */-interface ClientBox {- readonly top: number;- readonly left: number;- readonly right: number;- readonly bottom: number;- readonly width: number;- readonly height: number;-}--/** The viewport's size in client px, without its scrollbars. */-interface ViewportSize {- readonly width: number;- readonly height: number;-}--/**- * Call `onMove` when an element moves on screen without changing size: in- * layout (a sibling above it grows, a margin changes) or because something- * scrolled. ResizeObserver sees only size. The element is observed by an- * IntersectionObserver whose root is the viewport shrunk, through- * `rootMargin`, to the element's own rectangle (the layout-shift technique of- * `@floating-ui/dom`'s `observeMove`), so any move changes the intersection- * ratio and fires the callback, which calls `onMove` and re-arms on the new- * rectangle. Intersection callbacks run after the frame that moved the- * element has painted, so the caller corrects that move in the next frame.- * The element's box and the viewport are read once, when observing starts.- * Each re-arm takes them from the report itself (its target box and its root- * box), so following a move reads no layout.- *- * A fresh observer's first report can already differ from its threshold: the- * element is partly outside the viewport, or it kept moving between the- * rectangle the observer was armed on and its first check, as it does every- * frame of a smooth scroll. Any such report calls `onMove` and re-arms, at the- * reported ratio, or at once on the element's new rectangle when the report- * is 0 and the element moved, so a move that spans many frames is followed- * frame by frame. A report of 0 for an element that has not moved means a- * scrolled container clips it wholly; re-arming then would report 0 again- * every frame. Instead a second IntersectionObserver, rooted at the viewport- * with a threshold of 0 (it counts every ancestor's overflow clip), waits for- * the element to come back into view, then calls `onMove` and re-arms. Nothing- * runs on a timer. Returns the function that stops observing.- */-function observeMove(element: HTMLElement, onMove: () => void): () => void {- const doc = element.ownerDocument;- if (typeof IntersectionObserver === 'undefined') {- return () => {};- }- const root = doc.documentElement;- let observer: IntersectionObserver | null = null;- let visibility: IntersectionObserver | null = null;- const stop = () => {- observer?.disconnect();- observer = null;- visibility?.disconnect();- visibility = null;- };- const moved = (threshold: number, box: ClientBox, viewport: ViewportSize) => {- onMove();- arm(threshold, box, viewport);- };- const arm = (threshold: number, rect: ClientBox, viewport: ViewportSize) => {- stop();- if (rect.width === 0 || rect.height === 0) {- return;- }- const top = Math.floor(rect.top);- const left = Math.floor(rect.left);- const right = Math.floor(viewport.width - rect.right);- const bottom = Math.floor(viewport.height - rect.bottom);- const hasMoved = (now: ClientBox) =>- now.top !== rect.top ||- now.left !== rect.left ||- now.width !== rect.width ||- now.height !== rect.height;- // A report's root box is the viewport, here shrunk by the root margin.- // If the report has no root box, read the viewport's size.- const viewportOf = (- rootBounds: DOMRectReadOnly | null,- marginRight: number,- marginBottom: number,- ): ViewportSize =>- rootBounds == null- ? {width: root.clientWidth, height: root.clientHeight}- : {- width: rootBounds.right + marginRight,- height: rootBounds.bottom + marginBottom,- };- // Clipped by a scrolled container: wait, without a timer, for the- // element to come back into view. A first report that already finds it- // in view only counts if it has moved, so a clip the move observer and- // this one judge differently cannot re-arm every frame.- const awaitVisible = () => {- let isFirstVisible = true;- visibility = new IntersectionObserver(- entries => {- const entry = entries[entries.length - 1];- const firstVisible = isFirstVisible;- isFirstVisible = false;- if (- entry?.isIntersecting &&- (!firstVisible || hasMoved(entry.boundingClientRect))- ) {- moved(- 1,- entry.boundingClientRect,- viewportOf(entry.rootBounds, 0, 0),- );- }- },- {root: doc, threshold: 0},- );- visibility.observe(element);- };- let isFirst = true;- observer = new IntersectionObserver(- entries => {- const entry = entries[entries.length - 1];- if (entry == null) {- return;- }- const ratio = entry.intersectionRatio;- const box = entry.boundingClientRect;- const first = isFirst;- isFirst = false;- const followMove = (nextThreshold: number) =>- moved(- nextThreshold,- box,- viewportOf(entry.rootBounds, right, bottom),- );- if (ratio === threshold) {- // Still over its own rectangle, but a move smaller than the- // rounding of the root margin can leave the ratio at 1.- if (ratio === 1 && hasMoved(box)) {- followMove(1);- }- return;- }- if (!first || ratio > 0) {- followMove(first ? ratio : 1);- return;- }- if (hasMoved(box)) {- followMove(1);- return;- }- if (visibility === null) {- awaitVisible();- }- },- {- root: doc,- rootMargin: `${-top}px ${-right}px ${-bottom}px ${-left}px`,- threshold,- },- );- observer.observe(element);- };- arm(1, element.getBoundingClientRect(), {- width: root.clientWidth,- height: root.clientHeight,- });- return stop;}/**@@ -903,18 +730,13 @@ function observeScrollStop(/*** Watch an open layer that keeps its anchor clear, and its anchor, for every- * change that can re-settle the layer over the anchor or give it a scroll- * range (spec:AST-059 FR4, FR8): the layer, its content or the anchor- * resizing (ResizeObserver, before paint), the viewport resizing (before- * paint), a scroll of the anchor stopping (`observeScrollStop`, in the first- * frame painted after it), and the anchor moving on screen without resizing,- * in layout or by a scroll (`observeMove`, reported after paint). Each calls- * `keepAnchorClear` for this layer and anchor while `isCurrent` says they- * are still the live pair. A move is handled in the next animation frame, not- * in the task that reports it, and only updates whether the layer scrolls: it- * never checks the box and never places the layer afresh. Reports in one- * frame share one call. Returns the function that removes every observer and- * listener it added.+ * change that can re-settle the layer over the anchor (spec:AST-059 FR4, FR8):+ * the layer, its content or the anchor resizing (ResizeObserver, before+ * paint), the viewport resizing (before paint), and a scroll of the anchor+ * stopping (`observeScrollStop`, in the first frame painted after it). Each+ * calls `keepAnchorClear` for this layer and anchor while `isCurrent` says+ * they are still the live pair. Returns the function that removes every+ * observer and listener it added.*/function observeAnchorClearance(layer: HTMLElement,@@ -925,46 +747,26 @@ function observeAnchorClearance(if (!view) {return () => {};}- const reread = (cause: 'change' | 'move' = 'change') => {+ const reread = () => {if (isCurrent()) {- keepAnchorClear(layer, anchor, cause);+ keepAnchorClear(layer, anchor);}};- const rereadAfterChange = () => reread('change');let observer: ResizeObserver | null = null;if (typeof ResizeObserver !== 'undefined') {- observer = new ResizeObserver(rereadAfterChange);+ observer = new ResizeObserver(reread);observer.observe(layer);for (const child of Array.from(layer.children)) {observer.observe(child);}observer.observe(anchor);}- let moveFrame: number | null = null;- const stopObservingMove = observeMove(anchor, () => {- if (moveFrame !== null) {- return;- }- moveFrame = view.requestAnimationFrame(() => {- moveFrame = null;- reread('move');- });- });- view.addEventListener('resize', rereadAfterChange);- const stopObservingScrollStop = observeScrollStop(- view,- anchor,- rereadAfterChange,- );+ view.addEventListener('resize', reread);+ const stopObservingScrollStop = observeScrollStop(view, anchor, reread);return () => {observer?.disconnect();- stopObservingMove();stopObservingScrollStop();- if (moveFrame !== null) {- view.cancelAnimationFrame(moveFrame);- moveFrame = null;- }- view.removeEventListener('resize', rereadAfterChange);+ view.removeEventListener('resize', reread);};}@@ -1583,7 +1385,6 @@ function useLayerImplementation(// before the writes of the show, so the read lays nothing out.const closeTransitionHolds = closeTransitionKeepsShown(popover);const closedAnimations = animationNames(popover);- popover.removeAttribute(LAYER_SCROLLS_ATTRIBUTE);applyDeferredWritingContext(popover);// The trigger takes the layer's anchor name in the task that shows the// layer, so the layer's first frame is placed against it.@@ -2117,6 +1918,7 @@ function useLayerImplementation(keyboardCap == null ? 'visible' : 'auto',keyboardInset == null ? 'initial' : `${keyboardInset}px`,),+ keepsAnchorClear && styles.scrollsOnOverflow,viewportStyles,offsetStyle,xstyle,diff --git a/packages/core/src/Tooltip/__tests__/TooltipTallContent.a11y.browser.spec.ts b/packages/core/src/Tooltip/__tests__/TooltipTallContent.a11y.browser.spec.tsindex 8231b7c9f8..c166443fa0 100644--- a/packages/core/src/Tooltip/__tests__/TooltipTallContent.a11y.browser.spec.ts+++ b/packages/core/src/Tooltip/__tests__/TooltipTallContent.a11y.browser.spec.ts@@ -364,6 +364,58 @@ test('desktop, with motion allowed: a tall tooltip opens beside its trigger, andexpect(await sitsBesideTrigger(page)).toBe(true);});+test('a wheel at the end of a tall tooltip moves on to the page', async ({+ page,+}) => {+ // Nothing contains the tooltip's scroll: once it has scrolled to its end,+ // the next wheel scrolls the page.+ const viewport = {width: 1280, height: 720};+ await hoverTallTrigger(page, viewport, 360);+ await page.addStyleTag({content: 'body{min-height:300vh}'});+ const s = await rect(page, TOOLTIP);+ await page.mouse.move((s.left + s.right) / 2, (s.top + s.bottom) / 2, {+ steps: 4,+ });+ await page.evaluate(sel => {+ const el = document.querySelector(sel) as HTMLElement;+ el.scrollTop = el.scrollHeight;+ }, TOOLTIP);+ await page.waitForTimeout(300);+ const before = await page.evaluate(() => window.scrollY);+ await page.mouse.wheel(0, 200);+ await expect+ .poll(async () => page.evaluate(() => window.scrollY))+ .toBeGreaterThan(before);+});++test('a sticky child pins inside the tooltip, which is its scroll container', async ({+ page,+}) => {+ const viewport = {width: 1280, height: 720};+ await hoverTallTrigger(page, viewport, 360);+ const pinned = await page.evaluate(async sel => {+ const tooltip = document.querySelector(sel) as HTMLElement;+ const content = tooltip.firstElementChild as HTMLElement;+ const sticky = document.createElement('div');+ sticky.textContent = 'Sticky heading';+ sticky.style.position = 'sticky';+ sticky.style.insetBlockStart = '0';+ content.prepend(sticky);+ tooltip.scrollTop = 200;+ await new Promise(resolve => requestAnimationFrame(resolve));+ return {+ tooltipTop: tooltip.getBoundingClientRect().top,+ stickyTop: sticky.getBoundingClientRect().top,+ scrolled: tooltip.scrollTop,+ };+ }, TOOLTIP);+ expect(pinned.scrolled).toBeGreaterThan(0);+ // It stays at the tooltip's top edge (inside its padding) as the content+ // scrolls under it.+ expect(pinned.stickyTop - pinned.tooltipTop).toBeGreaterThanOrEqual(0);+ expect(pinned.stickyTop - pinned.tooltipTop).toBeLessThan(24);+});+test('phone: with no room beside, it opens below when below has more room', async ({page,}) => {@@ -460,8 +512,8 @@ test('a wheel over a tooltip that fits still scrolls the page', async ({test('a horizontal wheel over a tall tooltip still scrolls a wide page', async ({page,}) => {- // The tooltip scrolls only on the block axis, so only that axis is- // contained (spec:AST-025 FR14): a horizontal wheel over it moves on to the+ // The tooltip scrolls only on the block axis, and nothing contains its+ // scroll (spec:AST-025 FR14): a horizontal wheel over it moves on to the// page.const viewport = {width: 1280, height: 720};await page.setViewportSize(viewport);diff --git a/packages/core/src/Tooltip/__tests__/TooltipTallContentTracking.a11y.browser.spec.ts b/packages/core/src/Tooltip/__tests__/TooltipTallContentTracking.a11y.browser.spec.tsindex 0ebd3996d2..937714f40a 100644--- a/packages/core/src/Tooltip/__tests__/TooltipTallContentTracking.a11y.browser.spec.ts+++ b/packages/core/src/Tooltip/__tests__/TooltipTallContentTracking.a11y.browser.spec.ts@@ -794,12 +794,13 @@ const STATE_ROWS: Record<timeline: {set: 'a.timeline = new ScrollTimeline({source: document.documentElement})',},+ // The tooltip is a scroll container, so these follow the page by name.rangeStart: {- css: 'animation-timeline:scroll(nearest block);animation-range:entry 10% exit 80%',+ css: 'animation-timeline:scroll(root block);animation-range:entry 10% exit 80%',set: "a.rangeStart = 'cover 20%'",},rangeEnd: {- css: 'animation-timeline:scroll(nearest block);animation-range:entry 10% exit 80%',+ css: 'animation-timeline:scroll(root block);animation-range:entry 10% exit 80%',set: "a.rangeEnd = 'cover 70%'",},effect: {