Skip to content

feat(usePopover): anchorOutOfViewBehavior hides a popover while its anchor is out of view (AST-116 FR7, FR8) - #11122

Draft
nynexman4464 wants to merge 19 commits into
nynexman4464/feat/popover-anchorfrom
nynexman4464/feat/popover-anchor-out-of-view
Draft

nynexman4464 wants to merge 19 commits into
nynexman4464/feat/popover-anchorfrom
nynexman4464/feat/popover-anchor-out-of-view

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Status: The spec this stack implements (#11112) is being revised after owner review: anchor becomes anchorRef (a ref only), hiding while the anchor is out of view becomes built-in layer behavior with no option, and onOutsidePress is not implemented. This PR will be reworked into the built-in behavior once the spec PR is updated. This head only carries the last review round's fixes. The first-load size exception described below goes away with the rework.

Stacked on #11117 (the AST-116 stack; its spec, #11112, is proposed and not on main yet, and an engineering owner approved its head, including the follow-ups).

User need

When an anchored popover's anchor scrolls out of a scrolling panel (an app whose content scrolls inside a main region, not the window), the layer runtime holds the popover in place (spec:AST-059 FR5). An inline editor or a filter panel then floats over unrelated content until the anchor returns. Callers whose popover belongs to a row or a header need it to disappear with that row, and come back with it, without losing state.

Problem and solution fit

usePopover's anchorOutOfViewBehavior: 'stay' | 'hideWhileOutOfView' (AST-116 FR7, FR8, DEC-8):

  • 'stay' is the default and today's behavior.
  • With 'hideWhileOutOfView', while the anchor is out of view, the layer is hidden and takes no pointer input. "Out of view" means clipped by the viewport or by any scrolling ancestor, or removed.
  • It stays open: no onHide, and it shows again in place when the anchor returns. The value says "while" because hide() and onHide mean close.

The hide is driven by the runtime's existing anchor-visibility observation (IntersectionObserver, no root), so it reads no layout per scroll frame and moves nothing (architecture:layer-runtime INV12, INV21).

Current specification

spec:AST-116 FR7, FR8, DEC-3, DEC-8 (proposed in #11112; not on main yet).

Public delta and caller burden

  • New optional anchorOutOfViewBehavior?: 'stay' | 'hideWhileOutOfView' on UsePopoverOptions. Default 'stay', unchanged. PopoverProps is unchanged.
  • Internal: utils/focusReturn.ts exports takesFocusAsIs, the test focusForLastInputTemporarily applied inline; no behavior changes there.
  • Internal: useLayerInternal takes a package-internal hidesWithAnchor. A layer with it set re-observes an anchor that is replaced while open. A layer without it keeps its released render behavior: replacing a trigger still renders the hook once (asserted by the existing useLayer test).
usePopover({anchor: () => pencilFor(rowId), anchorOutOfViewBehavior: 'hideWhileOutOfView', ...})

Design and alternatives

  • visibility: hidden rather than display: none, so the box and its place in the top layer hold while hidden.
  • Not used: position-visibility: anchors-visible. spec:AST-059 records that it does not hide a top-layer layer on a page scroll.

Evidence

PopoverAnchorOutOfView.test.tsx (stubbed IntersectionObserver):

  • 'hideWhileOutOfView': hidden with no pointer events while out of view, still open with no onHide, and visible again on return;
  • 'stay' (default) is unchanged;
  • an anchor replaced while open is observed afresh.

useLayer.test.tsx passes unchanged.

Real browser, Chromium, Firefox and WebKit, run against the earlier <Popover anchorOutOfView="hide"> shape (the same hook path; not re-run since the rename) (script and screenshots): with the anchor scrolled out of its panel the popover reads visibility: hidden and stays :popover-open; scrolled back, it is visible in place. WebKit 26.5 (Playwright WebKit on macOS) passes the same checks.

Chromium: hidden while the anchor is scrolled out

Scope

Components: usePopover, Layer (internal)

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

Changes since the last review

  • Focus moves to the anchor when it can take focus, as AST-116 AR1 says. "Can take focus" is the test the shared focus path already applied before giving an element a temporary tab stop, now exported as the internal takesFocusAsIs (utils/focusReturn.ts): a tab stop, an element with tabindex, an editable region, or a control the shared focusable selector lists. A box that is only a place to sit, such as a card, is not a candidate.
  • An anchor that passes that test but refuses focus (a disabled button) hands the move to the trigger.
  • The JSDoc, docs and release note say "the anchor when it can take focus, else the trigger".
  • Tests: "moves focus to an anchor that takes focus without being a tab stop", "moves focus to the trigger when the anchor refuses focus", and a takesFocusAsIs suite in focusReturn.test.ts.
  • First-load size: AST-116 FR24 and DEC-9 now keep this input in usePopover at its measured cost, and INV10 names the exception; see below.
  • An <svg> anchor that can take focus is not a focus target: the JSDoc, the docs and the release note now say "the anchor when it is an HTML element that can take focus", and the record carries an AR1 gap: line for it.

First-load size (INV10)

pnpm size:pages --page popover=Popover,Button,Text, this PR's change in gzip bytes against the PR below it (whole stack against the spec head: docs +340, form +363, menu +3,531, table +1,794, popover +3,514):

docs form menu table popover
+147 +138 +518 +168 +499

anchorOutOfViewBehavior is optional; the menu and Popover pages grow 518 B and 499 B. Measured in parts:

So the option costs a page that does not use it about 290 to 345 B once the stack has landed. Both figures are over INV10's 0.3 KB allowance and inside the 0.6 KB that AST-116 FR24 allows anchorOutOfViewBehavior: an engineering owner decided the three composition inputs load with usePopover (AST-116 DEC-9), and INV10 names the exception. A deferred load fits only the focus move, and it would leave focus inside a hidden surface until the code arrived, which AST-116 AR1 rules out.

@vercel

vercel Bot commented Nov 10, 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 Nov 18, 2026 10:11pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2026
@astracat-bot

astracat-bot Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 18, 2026, 10:34 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.

Approval waits on an engineering owner deciding the direction for anchorOutOfView, whose only governing text is the draft spec:AST-113 FR7, FR8 and DEC-3, including its name (architecture:public-component-api INV2 asks for a <thing>Behavior prop, and AST-113 OQ2 leaves the name open). An engineering owner records the decision by approving AST-113 or by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

These need changes either way:

  • With anchorOutOfView="hide", focus inside the open popover drops to the page body when it hides and is not restored when the anchor returns (in Chromium, an inline editor's input loses focus on a wheel scroll), which breaks component:Popover AR3 and contradicts the comment at useLayer.tsx:72-73.
  • The changeset says 'hide' stops a popover from floating over content when its anchor scrolls out of a scrolling panel, but in Chromium the base already neither paints nor hit-tests that popover (position-visibility: anchors-visible), so narrow the wording to the page-scroll case the change actually affects.
  • An anchor replaced while open is re-observed by bumping anchorGeneration in the trigger ref to re-run an Effect (useLayer.tsx:1841-1843, :2175), when the unobserve and observe belong in that callback ref, as the keep-clear observers already do at :1849-1860.

[Automated review]

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
Comment thread packages/core/src/Layer/useLayer.tsx Resolved
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor-out-of-view branch from fa323a6 to 3cf6201 Compare November 11, 2026 00:18
@nynexman4464
nynexman4464 changed the base branch from nynexman4464/feat/popover-return-focus to nynexman4464/feat/popover-anchor November 11, 2026 00:18

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

Approval waits on an engineering owner deciding the direction and the name for anchorOutOfView, whose only governing text is the draft spec:AST-113 FR7, FR8 and DEC-3 (architecture:public-component-api INV2 asks for a <thing>Behavior prop, and AST-113 OQ1 lists the names as proposed). An engineering owner records the decision by approving AST-113 or by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

These need changes either way:

  • With anchorOutOfView="hide", focus inside the open popover drops to the page body when it hides and is not restored when the anchor returns (Chromium and Firefox, page and panel scroll), which breaks component:Popover AR3 and contradicts the comment at useLayer.tsx:72-73.
  • An anchor replaced while open is re-observed by bumping anchorGeneration in the trigger ref to re-run an Effect (useLayer.tsx:1841-1843, :2175), when the unobserve and observe belong in that callback ref (architecture:react-component-runtime INV6), as the keep-clear observers already do at :1849-1861.

The earlier note on the changeset's scrolling-panel wording is withdrawn: in Firefox the base popover does float over the page when its anchor leaves a scrolling panel.

Automated review (maintainer link)

@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor-out-of-view branch from 3cf6201 to e91b0ff Compare November 11, 2026 15:43
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from b905360 to 199db1d Compare November 11, 2026 15:43
@nynexman4464 nynexman4464 changed the title feat(Popover): anchorOutOfView hides a popover while its anchor is out of view (AST-113 FR7, FR8) feat(Popover): anchorOutOfView hides a popover while its anchor is out of view (AST-116 FR7, FR8) Nov 11, 2026

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

Approval waits on an engineering owner deciding the direction and the name for anchorOutOfView, whose only governing text is the draft spec:AST-116 FR7, FR8 and DEC-3 (the record formerly numbered AST-113). architecture:public-component-api INV2 asks for a <thing>Behavior prop, and AST-116 OQ1 lists the name as proposed. An engineering owner records the decision by approving AST-116 or by commenting /approve-spec <full head SHA> on this pull request; the author may do so as an engineering owner.

These need changes either way:

  • With anchorOutOfView="hide", focus inside the open popover drops to the page body when it hides and is not restored when the anchor returns (Chromium and Firefox, page and panel scroll), which breaks component:Popover AR3 and contradicts the comment at useLayer.tsx:72-73.
  • An anchor replaced while open is re-observed by bumping anchorGeneration in the trigger ref to re-run an Effect (useLayer.tsx:1841-1843, :2175), when the unobserve and observe belong in that callback ref (architecture:react-component-runtime INV6), as the keep-clear observers already do at :1849-1861.

Automated review (maintainer link)

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor-out-of-view branch from e91b0ff to e18f427 Compare November 16, 2026 22:36
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from 199db1d to 4a33324 Compare November 16, 2026 22:36
@nynexman4464 nynexman4464 changed the title feat(Popover): anchorOutOfView hides a popover while its anchor is out of view (AST-116 FR7, FR8) feat(usePopover): anchorOutOfViewBehavior hides a popover while its anchor is out of view (AST-116 FR7, FR8) Nov 16, 2026

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

Approval waits on an engineering owner deciding the new usePopover option anchorOutOfViewBehavior, whose only governing text is the draft spec:AST-116 FR7, FR8, DEC-3 and DEC-8, which are not on main. An engineering owner records that decision by approving those claims or by commenting /approve-spec <full head SHA> here, which the author may do as an engineering owner; it should also settle the 'stay' value name and where focus goes when the surface hides.

These need fixing whatever the decision:

  • With 'hideWhileOutOfView', visibility: hidden drops focus from a control inside the open popover to the page body and never restores it, so someone typing in a row editor loses their place when the row scrolls away (useLayer.tsx:74-77, :2291; component:Popover AR3).
  • A replaced anchor is re-observed by bumping anchorGeneration state to re-run an Effect; move the unobserve and observe into the contextRef callback ref, as the keep-clear observers already are, and drop the state (useLayer.tsx:1841-1843, :2175).
  • Newly live check: hidesWithAnchorRef.current = hidesWithAnchor writes a ref during render; use useCommittedRef (on main) or pass the flag through the ref callback's dependencies (useLayer.tsx:1232).

Approval also needs the first-load gzip deltas that INV10 asks for: a page that renders Popover without the option, and the four reference pages, base against head.

Claims and files checked

Review mode: full; reason: rebase

  • Claim: usePopover takes anchorOutOfViewBehavior: 'stay' | 'hideWhileOutOfView', and PopoverProps is unchanged — verified (usePopover.tsx:185; the generated API delta has one row).
  • Claim: 'stay' is the default and today's behavior — verified (usePopover.tsx:481; the "stays by default" test; existing suites pass).
  • Claim: with 'hideWhileOutOfView' the popover is hidden and takes no pointer input while the anchor is out of view — verified (useLayer.tsx:74-77, :2291; jsdom test; Chromium probe).
  • Claim: out of view covers the viewport and any scrolling ancestor — verified (observer with no root, useLayer.tsx:2167; Chromium panel probe); the removed-anchor case — unverified (no test or browser check).
  • Claim: it stays open, fires no onHide and shows again in place — verified (test; Chromium probe shows the popover still open and visible again on return).
  • Claim: the hide reads no layout per scroll frame and moves nothing — verified (the observer callback only sets state; the style adds visibility and pointer-events only).
  • Claim: a layer with the internal flag re-observes a replaced anchor, and other layers still render once on replacement — verified (useLayer.tsx:1841-1843, :2175; the third new test; useLayer.test.tsx:3716-3719 passes).
  • Claim: visibility: hidden keeps the box and its place in the top layer — verified; the code comment's "focus order hold" — false (Chromium moves focus to the body).
  • Claim: an anchor scrolled out of a scrolling panel leaves the popover floating over unrelated content today — verified in Firefox in an earlier run; in Chromium the base already stops painting it.
  • Claim: the release note's description of the option, its default and that it stays open — verified against the code.
  • Claim: the focused vitest run, typecheck and lint pass — verified (8 files, 294 tests; tsc and eslint clean); the whole-project run on another pull request was not checked.
  • .changeset/popover-anchor-out-of-view.md — clear.
  • packages/core/src/Layer/useLayer.tsx — three findings above, plus two comment notes.
  • packages/core/src/Popover/PopoverAnchorOutOfView.test.tsx — clear; it cannot show the focus loss.
  • packages/core/src/Popover/usePopover.doc.mjs — clear.
  • packages/core/src/Popover/usePopover.tsx — clear.

Automated review (maintainer link)

Comment thread packages/core/src/Layer/useLayer.tsx Resolved
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from d1fafde to 1e95c9b Compare November 18, 2026 14:17
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor-out-of-view branch from 73ea344 to 32ef02e Compare November 18, 2026 14:17

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

Approval waits on an engineering owner deciding the new usePopover option anchorOutOfViewBehavior: its only governing text is spec:AST-116 FR7, FR8, AR1, DEC-3 and DEC-8, and that record is not on main yet (#11112 is still a draft). An engineering owner records the decision by merging #11112 or by commenting /approve-spec <full head SHA> here, which the author may do as an engineering owner; the decision should also settle the 'stay' value name and the documented AR1 gap for a popover with neither a focusable anchor nor a trigger.

These need fixing whatever the decision:

  • The option is off by default but adds 491 B gzip of first-load JavaScript to a page that renders Popover without it and 510 B to the menu page, over the 0.3 KB that architecture:component-import-boundaries INV10 allows, mostly through the static utils/focusReturn import at usePopover.tsx:36, so move the hide-time focus move behind its own import or a deferred load and report the per-page deltas again.
  • Miss: focus moves to the anchor only when it is a tab stop (usePopover.tsx:690-691) although the release note and the JSDoc promise "the anchor when it takes focus", and an anchor that is chosen but refuses focus, such as a disabled button, gets no fallback to the trigger, so test focusability as the shared focus path does and retry with the trigger when the first move fails, or narrow the wording to "a tab stop".

The four blocking findings from the previous round are fixed at this head. Non-blocking notes on comment wording and on keeping modality tracking active for the shared focus path are inline.

Claims and files checked

Review mode: full; reason: rebase

  • Claim: usePopover gains anchorOutOfViewBehavior: 'stay' | 'hideWhileOutOfView' and PopoverProps is unchanged — verified (usePopover.tsx:210; the generated API delta has one row).
  • Claim: 'stay' is the default and today's behavior — verified (usePopover.tsx:522; "stays by default" passes on the base and the head).
  • Claim: with 'hideWhileOutOfView' the popover is hidden and takes no pointer input while its anchor is clipped by the viewport or a scrolling ancestor, or removed — verified (useLayer.tsx:88-91, :2618; tests; Chromium).
  • Claim: it stays open, fires no onHide, and shows again in place — verified (tests; Chromium, with the typed text kept and the same position).
  • Claim: the hide uses the runtime's existing anchor observation, reads no layout per scroll frame and moves nothing — verified (the observer callback sets state and moves focus; the class writes visibility and pointer events only).
  • Claim: the governing record is proposed and not on main yet — verified.
  • Claim: a layer with the internal flag re-observes a replaced anchor, and other layers keep rendering once on a trigger swap — verified (the replaced-anchor test fails on the base; the existing layer suite passes).
  • Claim: visibility: hidden keeps the box and its place — verified (the hidden layer keeps its rectangle and stays open in Chromium).
  • Claim: anchors-visible CSS does not hide a top-layer layer on a page scroll — verified against the layer viewport record.
  • Claim: the new tests cover the hide, the default and a replaced anchor, and the existing layer test passes unchanged — verified (7 new tests pass; 5 fail on the base).
  • Claim: the earlier three-engine browser run of the older prop shape — not re-run; Chromium was checked at this head.
  • Claim: focused tests, typecheck and lint pass — verified (9 files, 330 tests; typecheck and lint clean); the top-of-stack run belongs to another pull request and was not checked.
  • Claim: the focus move goes through the shared focus-return path and the local loop is gone — verified (usePopover.tsx:688-701).
  • Claim: with neither a focusable anchor nor a trigger, focus falls to the body, a gap line says so, and the verification row drops that case — verified (record gap line and row; Chromium).
  • Claim: the observer keeps the node it watches, so a ref anchor removed and later replaced is unobserved first — verified (useLayer.tsx:2125-2131).
  • Claim: the removed-anchor test opens once and fails on the base — verified.
  • Claim: this pull request's first-load deltas (docs +147, form +138, menu +510, table +171, popover +491) — verified within 2 B; over the allowance on the popover and menu pages (finding).
  • Claim: the shared module becomes always-loaded later in the stack, so the stack total is unchanged — not checked; it covers other pull requests.
  • Claim: public text carries no internal context — verified.
  • Claim: release note for the option — verified.
  • Claim: release note for the focus move, "to the anchor when it takes focus" — false for an anchor that takes focus without being a tab stop (finding).
  • .changeset/popover-anchor-out-of-view.md — clear.
  • .changeset/popover-hidden-focus.md — the focus-target wording finding.
  • docs/architecture/layer-runtime.md — its new cross-reference names a record that is not on main (part of the owner decision).
  • docs/specs/AST-116-popover-anchoring/spec.md — waits on the owner decision; the gap line and row are consistent with the code.
  • packages/core/src/Layer/useLayer.tsx — clear apart from two comment notes.
  • packages/core/src/Popover/PopoverAnchorOutOfView.test.tsx — clear.
  • packages/core/src/Popover/usePopover.doc.mjs — clear.
  • packages/core/src/Popover/usePopover.tsx — the first-load size and focus-target findings, and two non-blocking notes.

Automated review (maintainer link)

}, [onShow]);

// Core layer for popover positioning
// Filled in once the content ref exists; the layer calls it as the surface

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.

Non-blocking (INV29): the existing // Core layer for popover positioning above now heads these anchorHiddenRef lines instead of the useLayerInternal call. Move this block above that comment.

{preventScroll: true},
);
};
useCommittedRefInto(anchorHiddenRef, moveFocusOutOfHiddenSurface);

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.

Non-blocking: moveFocusLeftBehind asks its caller to keep modality tracking active (utils/focusReturn.ts:66-68). usePopover does not, so on a page where nothing else tracks it, the store keeps its 'keyboard' default and the move is a plain focus(), leaving the ring to the browser instead of architecture:interaction-modality INV1's last-input rule. Consider useInteractionModalityTrackingFor(contentRef, hidesWithAnchor), loaded with the deferred feature so it does not add to INV10's count.

@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from 1e95c9b to e08d149 Compare November 18, 2026 20:22
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor-out-of-view branch from 32ef02e to 25310be Compare November 18, 2026 20:22

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

Approval waits on an engineering owner deciding the new usePopover option anchorOutOfViewBehavior: its only governing text, spec:AST-116 FR7, FR8, AR1, DEC-3 and DEC-8, is approved on #11112 at that pull request's head but is not on main, and this pull request edits the record again (the AR1 verification row and gap, and the layer-runtime INV12 cross-reference). An engineering owner records the decision by commenting /approve-spec <full head SHA> here, which the author may do as an engineering owner.

These need fixing whatever the decision:

  • The option is off by default but adds 499 B gzip of first-load JavaScript to a page that renders Popover without it and 518 B to the menu page, over the 0.3 KB that architecture:component-import-boundaries INV10 allows, mostly through the static utils/focusReturn import at usePopover.tsx:36-40, so move the hide-time focus move behind its own import or a deferred load and report the per-page deltas again.
  • Miss: an <svg> anchor that can take focus, which AST-116 FR2 accepts, is skipped because takesFocus accepts only HTML elements (usePopover.tsx:697-698), so focus goes to the trigger although the release note, the JSDoc and the docs promise "the anchor when it can take focus"; accept SVG elements there with a test, or narrow the three texts to an HTML anchor.

The previous round's focus-target finding is fixed; non-blocking notes on modality tracking and comment wording stay open inline.

Claims and files checked

Review mode: full; reason: rebase

  • Claim: usePopover gains anchorOutOfViewBehavior: 'stay' | 'hideWhileOutOfView' and PopoverProps is unchanged — verified (usePopover.tsx:215; the generated API delta has one row).
  • Claim: 'stay' is the default and today's behavior — verified (usePopover.tsx:527; "stays by default" passes on the base and the head).
  • Claim: with 'hideWhileOutOfView' the popover is hidden and takes no pointer input while its anchor is clipped by the viewport or a scrolling ancestor, or removed — verified (useLayer.tsx:88-91, :2618; tests; Chromium and Firefox with the anchor clipped by a panel).
  • Claim: it stays open, fires no onHide, and shows again in place — verified (tests; in Chromium and Firefox it stays open and keeps the typed text).
  • Claim: the hide is driven by the existing anchor observation, reads no layout per scroll frame and moves nothing — verified (useLayer.tsx:1355-1366, :2470-2502).
  • Claim: an inline editor floats over unrelated content when its anchor scrolls out of a panel — verified in Firefox; Chromium already left it unpainted on the base, with focus still inside it.
  • Claim: the governing record is proposed, not on main, and an engineering owner approved its pull request's head — verified.
  • Claim: takesFocusAsIs is the existing inline test, with no behavior change there — verified (focusReturn.ts:97-117; the focus-return suite passes).
  • Claim: a layer with the internal flag re-observes a replaced anchor, and other layers keep their released render behavior — verified (the replaced-anchor test fails on the base; the existing layer suite passes).
  • Claim: visibility: hidden keeps the box and its place — verified (the editor returns to the same place in both engines).
  • Claim: anchors-visible CSS does not hide a top-layer layer on a page scroll — verified against the layer viewport record.
  • Claim: the new tests cover hide, default and a replaced anchor, and the existing layer test passes unchanged — verified (9 new tests pass; 7 fail on the base).
  • Claim: earlier three-engine browser run of the older prop shape — not re-run; Chromium and Firefox were checked at this head, WebKit was not.
  • Claim: focused tests pass, typecheck and lint are clean — verified (10 files, 370 tests; typecheck and lint clean); the top-of-stack suite run belongs to another pull request and was not checked.
  • Claim: focus moves to the anchor when it can take focus (a tab stop, a tabindex, an editable region, a focusable control), else to the trigger — verified for HTML anchors; false for an SVG anchor that can take focus (finding).
  • Claim: an anchor that refuses focus, such as a disabled button, hands the move to the trigger — verified (test; Chromium and Firefox).
  • Claim: the JSDoc, docs and release note say "the anchor when it can take focus, else the trigger" — the wording is there; false for SVG anchors (finding).
  • Claim: the named new tests and the takesFocusAsIs suite exist and pass — verified (they fail on the base).
  • Claim: this pull request's first-load deltas (docs +147, form +138, menu +518, table +168, popover +499) — verified within 1 B; over the allowance on the popover and menu pages (finding).
  • Claim: a later pull request makes the shared module always-loaded, so the stack total does not change — not checked; it concerns other pull requests.
  • Claim: public text carries no internal context — verified.
  • Release note for the option — verified.
  • Release note for the focus move — false for SVG anchors (finding).
  • .changeset/popover-anchor-out-of-view.md — clear.
  • .changeset/popover-hidden-focus.md — the SVG anchor wording finding.
  • docs/architecture/layer-runtime.md — its cross-reference names a record that is not on main (part of the owner decision).
  • docs/specs/AST-116-popover-anchoring/spec.md — waits on the owner decision; the AR1 gap line and row match the code.
  • packages/core/src/Layer/useLayer.tsx — clear apart from two comment notes.
  • packages/core/src/Popover/PopoverAnchorOutOfView.test.tsx — clear.
  • packages/core/src/Popover/usePopover.doc.mjs — the SVG anchor wording finding.
  • packages/core/src/Popover/usePopover.tsx — the first-load size and SVG anchor findings, and two non-blocking notes.
  • packages/core/src/utils/focusReturn.test.ts — clear.
  • packages/core/src/utils/focusReturn.ts — clear.

Automated review (maintainer link)

Comment on lines +36 to +40
import {
moveFocusLeftBehind,
noteFocusWithin,
takesFocusAsIs,
} from '../utils/focusReturn';

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 static import puts noteFocusWithin, moveFocusLeftBehind, takesFocusAsIs and the temporary tab-stop map into every page that renders Popover or DropdownMenu, whether or not anchorOutOfViewBehavior is set. Measured with the option unused: the Popover page grows 499 B gzip and the menu page 518 B, over the 307 B that architecture:component-import-boundaries INV10 allows for an optional feature. Suggested fix: load the hide-time focus move only when anchorOutOfViewBehavior is 'hideWhileOutOfView' (its own import, INV7, or a deferred load, DEC-1), then report the per-page deltas again.

…in usePopover over INV10's allowance; INV10 names the exception
…nchor is out of view, and focus inside it moves out (spec:AST-116 FR7, FR8, AR1)

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

Approval waits on an engineering owner deciding the new usePopover option anchorOutOfViewBehavior: its only governing text, spec:AST-116 FR7, FR8, AR1, DEC-3, DEC-8 and DEC-9, is not on main yet, and this pull request also edits that record and architecture:layer-runtime INV12. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request (the author may, as an engineering owner), or this pull request waits for the revised AST-116 its description mentions. What must be settled: the option and its values, the hide-time focus move, the record edits, and the first-load cost over architecture:component-import-boundaries INV10 (499 B gzip on the Popover page and 518 B on the menu page with the option unused).

This needs fixing either way:

  • Miss: a 'hideWhileOutOfView' popover opened while its anchor is already clipped by a scrolling panel shows for two frames before it hides, and focus passes through it, because the opening read at useLayer.tsx:2475-2481 checks only the viewport; clip that read by the anchor's scrolling ancestors and add a test that opens with the anchor clipped.
Claims and files checked

Review mode: full; reason: rebase

  • Claim, 'stay' is the default and keeps today's behavior: verified (usePopover.tsx:527; "stays by default" passes on base and head).
  • Claim, the hidden popover takes no pointer input while its anchor is clipped by the viewport or a scrolling ancestor, or removed: verified (useLayer.tsx:88-91, :2618; tests; Chromium and Firefox runs).
  • Claim, it stays open with no onHide and shows again in place: verified (tests; the layer stays :popover-open and keeps typed text in both engines).
  • Claim, the hide uses the existing observer, reads no layout per scroll frame and moves nothing: verified (useLayer.tsx:2486-2492); the read before the first frame misses scrolling-ancestor clips (finding above).
  • Claim, the Popover component's props are unchanged: verified (the API comparison lists only the hook option).
  • Claim, the exported focusability helper is the old inline test with no behavior change: verified (focusReturn.ts:98-105 is the exact negation of the removed check; the existing suite passes).
  • Claim, layers without the internal flag keep their released render behavior: verified (the rebind is gated at useLayer.tsx:2124-2133; useLayer.test.tsx passes).
  • Claim, position-visibility is not used because it does not hide a top-layer layer on a page scroll: verified against the layer viewport record.
  • Claim, the listed tests exist and pass, and the typecheck and lint are clean: verified; 7 of the 9 new popover tests fail on the base.
  • Claim, the earlier real-browser run used the previous prop shape: as stated; this review's Chromium and Firefox runs confirm the hide and the focus move at this head.
  • Claim, focus moves to the anchor when it is an HTML element that can take focus, else the trigger, and a disabled anchor hands off to the trigger: verified (usePopover.tsx:693-718; tests; browser runs).
  • Claim, the docs and release note now say "an HTML element", and the record states the SVG gap: verified.
  • Claim, the unused option costs 499 B and 518 B gzip under an exception the stack's spec grants: figures as reported, not re-measured; the exception is not on main (held above).
  • Claim, the option will be reworked into built-in behavior: not settled by any record (held above).
  • Release note, hidden with no pointer input until the anchor returns, still open, 'stay' default: verified; it no longer floats in Firefox and on a page scroll, while Chromium already left a panel-clipped popover unpainted.
  • Release note, focus moves to the anchor or the trigger and is not moved back: verified ("does not move it back" test; focus stays on the row in both engines).
  • File .changeset/popover-anchor-out-of-view.md: clear.
  • File .changeset/popover-hidden-focus.md: clear.
  • File docs/architecture/layer-runtime.md: held (the INV12 clause names a record not on main).
  • File docs/specs/AST-116-popover-anchoring/spec.md: held (record edits wait on the owner).
  • File packages/core/src/Layer/useLayer.tsx: the open-while-clipped finding above; two comment notes.
  • File packages/core/src/Popover/PopoverAnchorOutOfView.test.tsx: clear; no case opens with the anchor already clipped.
  • File packages/core/src/Popover/usePopover.doc.mjs: clear.
  • File packages/core/src/Popover/usePopover.tsx: held for the INV10 cost of its static focus import; modality and comment notes.
  • File packages/core/src/utils/focusReturn.test.ts: clear.
  • File packages/core/src/utils/focusReturn.ts: clear.

Automated review (maintainer link)

viewportStyles,
offsetStyle,
xstyle,
hidesWithAnchor && !isAnchorInView && styles.anchorOutOfView,

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.

Miss: a 'hideWhileOutOfView' popover opened while its anchor is already clipped by a scrolling panel shows for two frames before this style applies. The opening read (:2475-2481) tests the anchor only against the viewport, so the hide waits for IntersectionObserver's first report: Chromium and Firefox read visibility visible, visible, hidden on the first animation frames, Firefox paints the editor outside its panel, and auto-focus puts focus in the editor before the hide moves it to the row. architecture:layer-runtime INV12 says anchor visibility is read before first paint. Suggested fix: for a layer that hides with its anchor, clip the opening read by the anchor's scrolling ancestors (one read at open), and add a test that opens with the anchor already clipped.

@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from 6dcfdc9 to bbff687 Compare November 18, 2026 23:54
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/popover-anchor branch from bbff687 to f42ee7f Compare November 19, 2026 03:08
@github-actions
github-actions Bot deleted the branch nynexman4464/feat/popover-anchor November 20, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 48a1e5f7 Deployed Nov 18, 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.

1 participant