Skip to content

feat(refactor): position the dropbox without popover-plugin (2/3) - #504

Draft
gnbm wants to merge 19 commits into
gm/replace-plugins-1-safety-netfrom
gm/replace-plugins-2-positioner
Draft

gnbm wants to merge 19 commits into
gm/replace-plugins-1-safety-netfrom
gm/replace-plugins-2-positioner

Conversation

@gnbm

@gnbm gnbm commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Issue number: none


Part 2 of 3 stacked PRs, based on #503. Review after #503; GitHub retargets this one to vs-major-2.0.x once #503 merges and its branch is deleted. Replaces #500.

What is the current behavior?

  • popover-plugin places and animates the dropbox. It ships inside virtual-select.min.js and sets the window.PopoverComponent and window.PopperComponent globals.
  • An outside click or Escape reaches both the component and the plugin, so afterClose fires twice.
  • Escape with focus outside the component hides the dropdown without beforeClose and leaves aria-expanded="true".
  • A silent close (opening another dropdown from script) leaves pop-comp-active and the plugin's scroll listeners behind, and the next open() shows nothing.
  • In an instance rendered inside a shadow root, every click inside it (the search box, a multi-select option) closes the dropdown: the document sees the click on the shadow host.
  • open() on a dropdown already opening or open sends a second beforeOpen with no afterOpen.

What is the new behavior?

  • src/utils/placement.js: computePlacement(), a pure port of the plugin's placement maths, with unit tests.

  • src/dropbox-positioner.js: the show/hide state machine.

    • It keeps the same classes (pop-comp-ele, pop-comp-wrapper, pop-comp-active, pop-comp-disable-events, position-*), the same placement and the same timing.
    • Scroll and resize listeners exist only while the dropbox is shown, with at most one reposition per animation frame.
  • One beforeClose and one afterClose per close.

  • Escape from outside the component is a real close. It ignores keys another widget already handled and IME composition keys.

  • A silent close resets the positioner and aria-expanded.

  • Interrupted transitions:

    • open() during the close animation finishes the close first (afterClose included), then opens.
    • A second click on the toggle, Enter or an arrow key during the close reopens the dropdown instead of being ignored.
    • close() during the open animation fires no afterOpen, and neither does an instance closed because another one opened.
    • open() on a dropdown already opening or open is ignored (popup and keepAlwaysOpen instances keep their current behaviour, where every open reaches afterOpen).
  • Fixed while porting:

    • An empty or unknown position falls back to auto instead of throwing.
    • Hosts inside a shadow root, including ones slotted into another component's shadow tree, follow scrolls, and clicks inside such an instance no longer close it: the outside-click check reads the node actually clicked (composedPath()[0]).
    • Under a scaled ancestor the dropbox opens against the host's edge and no longer drifts. Rotated and mirrored ancestors are re-measured too; a plain scale or rotate: 0deg is not.
    • destroy() during the close transition no longer leaves pop-comp-active behind.
  • popover-plugin is removed; the two CSS rules still needed move to src/sass/partials/popover.scss.

  • Bundle size (gzip -9, the build check's method):

    File Before After Budget
    virtual-select.min.js 23,207 19,916 19,916
    virtual-select.min.css 2,803 2,623 2,623

    Both files sit exactly at their budgets, so the next byte either gains needs a budget decision. The shadow-root click fix took the JS from 19,900 to 19,916.

Does this introduce a breaking change?

  • Yes
  • No

The documented API (open(), close(), events, options) is unchanged. Removed, none of it documented:

  • the window.PopoverComponent and window.PopperComponent globals;
  • $ele.popComp, $ele.show(), $ele.hide() and $ele.updatePosition(). Use $ele.open() and $ele.close();
  • data-popover-* attributes on the host overriding popover options;
  • data-top, data-left, data-from-top and data-from-left on the dropbox container.

Behaviour changes:

  • Consumers counting a second afterClose get one per close.
  • A dropdown closed during its open animation fires beforeOpen but no afterOpen.
  • open() on a dropdown already opening or open fires nothing.
  • A closed dropbox no longer has a position-* class or an inline transform before its first open.

Other information

  • The positioning baseline from test: pin dropbox placement, events and bundle size before replacing the popover plugins (1/3) #503 passes unchanged on this code (136/136, same fixture, including the after-close state, a custom wrapper and the pages that load tooltip-plugin). Its record mode refuses on this code, which no longer has popover-plugin; re-record on master.
  • cypress/e2e/dropbox-lifecycle.cy.ts pins the interrupted transitions, repeated opens, real clicks inside a shadow-root instance, the shadow-root and slotted hosts, and which transforms trigger a re-measure.
  • Locally: typecheck, lint, stylelint, unit tests and build checks pass; e2e 614/614 in 32 specs.

gnbm and others added 8 commits November 24, 2026 20:53
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Virtual Select positions the dropbox itself, so the bundled popover-plugin goes. The two
CSS rules still needed (.pop-comp-wrapper, .pop-comp-disable-events) move to
src/sass/partials/popover.scss; the arrow and content rules are dropped.

Removed surface (none of it documented, all of it existed only because the plugin was bundled):
- window.PopoverComponent and window.PopperComponent.
- $ele.popComp, $ele.show(), $ele.hide(), $ele.updatePosition(). The documented open() and
  close() are untouched.
- data-popover-* attributes on the host element overriding popover options.
- data-top, data-left, data-from-top, data-from-left on the dropbox container.
- The <i class="pop-comp-arrow"> element is never rendered, as today. Its CSS goes.

virtual-select.min.js gzip budget lowered by 3500 bytes (23207 baseline, 19707 max).
destroy() cleared the hide timer, so a destroy during the hide transition
cancelled the afterHide() that removes pop-comp-active and left it on the host for
good. OutSystems UI hits this: changeProperty() closes synchronously and redraws
(destroy + init on the same element) on a 0 ms timer. destroy() now removes the
class itself; reset() already calls destroy(). This also fixes destroying an open
dropdown, which left the class stale on master too.

The reduced-motion test now restores its matchMedia stub, which had leaked into
the following test (testIsolation is off and cy.visit does not reload).
updatePosition() took the untransformed origin as the rect minus the current
translate. The rect is in viewport pixels and the translate in the element's own,
so under a scaled ancestor the origin was off by translate * (1 - scale) and each
reposition moved the dropbox further (32px, 38px, then 40px after seven calls in a
scale(0.8) container with dropboxWrapper 'self'; popover-plugin stayed at 32px).
The translate is now scaled by rect width / offsetWidth before it comes off; a gap
under one pixel is offsetWidth's rounding and counts as no scale, so the unscaled
path is unchanged.
…and axis scales

- An empty, null or unknown position falls back to 'auto', as popover-plugin did for an empty one; computePlacement() used to throw on open and leave the dropbox stuck in its show state.

- Scroll listeners go on every root from the host's shadow root up to the document, and the ancestor test walks up through shadow hosts: scroll events do not leave a shadow root and Node.contains() does not look into one.

- updatePosition() takes the ancestor scale per axis (height for the y translate), so an ancestor scaled on one axis no longer makes the dropbox drift on each reposition.
…against scaled hosts

- A silent close (another dropdown opened from script) now sets aria-expanded false; it still fires no events.

- The document Escape handler ignores keydowns another widget already handled (defaultPrevented) and IME composition keys.

- The placement is computed in viewport pixels and now written in the dropbox's own: x, y and the from-translate are divided by the ancestor scale per axis, so a dropbox under a scaled ancestor opens against the host's edge instead of popover-plugin's offset.

virtual-select.min.js budget raised to 19,750 B gzip (user decision): measured 19,726, 3,481 B below the 23,207 baseline.
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Test Results — ✅ all checks passed

Check Result Time
Typecheck ✅ 2s
ESLint ✅ 1s
Stylelint ✅ 1s
CI Scripts ✅ 0s
Build ✅ 3s
a11y-aria-label.cy.ts ✅ 10/10 5s
a11y-close-clears-highlight.cy.ts ✅ 7/7 5s
a11y-escape-close.cy.ts ✅ 6/6 1s
a11y-listbox-multiselectable.cy.ts ✅ 3/3 1s
a11y-live-region.cy.ts ✅ 18/18 5s
a11y-reduced-motion.cy.ts ✅ 3/3 1s
a11y-required-error.cy.ts ✅ 20/20 3s
a11y-search-arrow-navigation.cy.ts ✅ 13/13 6s
a11y-select-all.cy.ts ✅ 7/7 3s
a11y-server-search-announcements.cy.ts ✅ 6/6 4s
a11y-target-size.cy.ts ✅ 5/5 2s
build-stylesheet-integrity.cy.ts ✅ 4/4 1s
disabled-interactions.cy.ts ✅ 7/7 1s
dropbox-lifecycle.cy.ts ✅ 49/49 21s
dropbox-positioning-baseline.cy.ts ✅ 136/136 29s
examples.cy.ts ✅ 219/219 1m18s
observer-listener-lifecycle.cy.ts ✅ 7/7 1s
perf-resize-throttle.cy.ts ✅ 3/3 1s
perf-scroll-aria.cy.ts ✅ 6/6 3s
secure-option-values.cy.ts ✅ 2/2 1s
secure-text-warning.cy.ts ✅ 4/4 1s
security-ampersand-storage.cy.ts ✅ 16/16 3s
security-chrome-label-props.cy.ts ✅ 10/10 1s
security-classnames-xss.cy.ts ✅ 2/2 1s
security-customdata-xss.cy.ts ✅ 2/2 1s
security-global-defaults.cy.ts ✅ 11/11 1s
security-hidden-input-name.cy.ts ✅ 7/7 1s
security-proto-value.cy.ts ✅ 9/9 1s
security-quote-escaping.cy.ts ✅ 12/12 2s
single-select-new-option-height.cy.ts ✅ 2/2 2s
tag-tooltip-overflow.cy.ts ✅ 6/6 11s
timer-cleanup.cy.ts ✅ 2/2 1s

Tested commit: 9844ab2 · Run #93

@gnbm gnbm changed the title feat!: position the dropbox without popover-plugin (2/3) feat(refactor): position the dropbox without popover-plugin (2/3) Nov 24, 2026
gnbm added 10 commits November 24, 2026 22:15
…ioner

Brings in PR 1's two test fixes (ancestor-scroll measurement, matchMedia restore). This branch already carries equivalent changes to dropbox-lifecycle.cy.ts, so the conflict resolves to this branch's version and the tree is unchanged.
…ioner

Brings in PR 1's tightened checks. The budget-loop conflict resolves to PR 1's gzipSizeOf() helper, keeping this branch's maxGzip <= baselineGzip assertion (the same line).
No per-axis scale can undo a translate under a rotation or skew, so the matrix-based origin compounded an error on every reposition (seven repositions moved a dropbox under rotate(90deg) from x 204 to -3660). show() already forces a read after writing the from-translate; it now checks that the box moved the way the per-axis scales predict, and if not, repositions measure with transform: none, as popover-plugin did. Everyone else keeps the one-read, one-write path.

virtual-select.min.js budget raised to 19,850 B gzip (user decision): measured 19,808.
The open-time check compared how far the from-translate moved the box with what the per-axis scales predict, so a mirror went unnoticed whenever the dropbox opened with no translate on the mirrored axis; once the host moved sideways every reposition drifted (100 to 25,500 in seven). show() now walks the dropbox's ancestors once, through shadow hosts, and repositions measure with transform: none when any of them rotates, skews or mirrors it, from transform or the standalone rotate and scale properties. The shadow-host step is shared with onScroll().

virtual-select.min.js budget raised to 19,900 B gzip (user decision): measured 19,857.
A host slotted into a web component is rendered inside that component's shadow tree, which its parentNode chain never enters. The ancestor walk now prefers assignedSlot, so a mirrored or rotated wrapper in the shadow tree switches repositions to re-measuring, and a scroll box there is listened to and followed.
… as values

open() during the close animation used to be ignored by the positioner, leaving the dropdown closed but announced as expanded. It now finishes the close first (afterClose included), then opens normally. An open interrupted by a close keeps firing no afterOpen, now pinned by tests for both the normal and the silent close.

The re-measure check no longer treats rotate: 0deg or a z-only mirror as a rotation. isShown() was unused and isHiding() had one caller, so both are gone to keep the core bundle within its gzip budget.
isOpened() stays true until the close animation ends, so a second toggle click, Enter or an arrow key during it ran another close, which the hiding guard swallowed. They now check isStayingOpen() and reopen, the same way open() does.

The mirrored-ancestor test waits for the scroll's reposition instead of a fixed time, and the no-afterOpen rule for an interrupted open is documented on hide() and reset(). The document Escape handler reads e.key only, which keeps the core bundle within its gzip budget.
From the positioner change on, the code has no popover-plugin engine, so record mode always refuses. The header and the refusal now say to re-record on master instead of 'this PR's code'.
…03 -> 2623)

The size check asks for maxGzip to follow a file down when a change shrinks it; dropping popover-plugin's styles shrank virtual-select.min.css to 2623 B gzip.
…n() is ignored

- onDocumentClick() takes the node actually clicked (composedPath()[0]). At
  the document, a click inside a shadow root targets the shadow host, which no
  .vscomp-wrapper contains, so every click in an instance rendered there (its
  search box, a multi-select option) closed it as if outside.
- openDropbox() returns once a positioner-backed dropbox is opening or open:
  the positioner would not show it again, so a second open() sent a second
  beforeOpen with no afterOpen. Popup and keepAlwaysOpen keep every open.
- Specs: open() twice and open() while open fire the open events once; real
  clicks in a shadow-root instance's search box and options keep it open, and
  an outside click still closes it. The four fail on the code before.
- virtual-select.min.js budget 19900 -> 19916: the shadow-root fix costs
  16 B gzip, the guard nothing measurable (user decision).
gnbm added a commit that referenced this pull request Nov 25, 2026
…s-3-tooltip

Budgets: the core takes #504's shadow-root click fix, 16 B gzip (user decision), so 19873 -> 19889.
…s-2-positioner

# Conflicts:
#	cypress/e2e/dropbox-positioning-baseline.cy.ts

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant