Skip to content

fix(combobox): only scroll the content when scrolling the highlighted item into view - #3574

Open
lord-0011 wants to merge 1 commit into
chakra-ui:mainfrom
lord-0011:fix/combobox-scroll-document
Open

lord-0011 wants to merge 1 commit into
chakra-ui:mainfrom
lord-0011:fix/combobox-scroll-document

Conversation

@lord-0011

Copy link
Copy Markdown

Closes #3567

📝 Description

scrollToHighlightedItem scrolled the highlighted item into view with scrollIntoView(itemEl, { rootEl: contentEl, block: "nearest" }), which calls the native element.scrollIntoView(). The native method scrolls every scrollable ancestor, including the document, so an open combobox with a highlighted item could scroll the whole page on mount even when the item was already visible in its own list.

This PR switches both scrollToHighlightedItem actions in the combobox machine to scrollToNearest(itemEl, { rootEl: contentEl }) from @zag-js/dom-query (added in #3542 for the same problem in TOC). It only scrolls the content element, and does nothing when the item is already visible.

⛳️ Current behavior (updates)

An inline combobox rendered below the fold with open and defaultHighlightedValue scrolls the document on mount (in the new example page, window.scrollY goes from 0 to 463) without any user input.

🚀 New behavior

  • Only the combobox content scrolls to reveal the highlighted item, and only if it isn't already visible. The document and other ancestors are no longer scrolled.
  • No change for virtualized lists: the scrollToIndexFn path is untouched.

Changes:

  • packages/machines/combobox/src/combobox.machine.ts: use scrollToNearest instead of scrollIntoView in both scrollToHighlightedItem actions.
  • New example page examples/next-ts/pages/combobox/highlighted-on-mount.tsx and route entry, following the pattern of fix(toc): only auto-scroll the toc's own scroll container #3542.
  • New e2e test "combobox / highlighted on mount › does not scroll the document on mount" (window.scrollY and the content's scrollTop stay 0).
  • Changeset (patch) for @zag-js/combobox.

Note on the example page: the example app's layout sets overflow: hidden on body/.page, so the document can't scroll there. The page overrides that (html, body, .page, .page main { height: auto; overflow: visible }) so it reproduces the issue the way the reporter saw it, with the document as the scroll container. Happy to change this if you'd prefer a different setup.

💣 Is this a breaking change (Yes/No):

No.

📝 Additional Information

Testing:

  • The new e2e test fails on main (Expected: 0, Received: 463 for window.scrollY) and passes with this change.
  • pnpm e2e-react -- e2e/combobox.e2e.ts: 54/54 pass.
  • pnpm typecheck, pnpm lint and Prettier pass.

Select, Listbox, Menu and Cascade Select use the same scrollIntoView(itemEl, { rootEl: contentEl, block: "nearest" }) pattern. I kept this PR to the combobox as reported; happy to open a follow-up for those if you'd like.

AI disclosure: I used an AI coding assistant to help prepare this change. I reviewed the diff line by line, and confirmed the new test fails without the fix and passes with it.

@changeset-bot

changeset-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4ecea72

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 85 packages
Name Type
@zag-js/combobox Patch
@zag-js/anatomy-icons Patch
@zag-js/anatomy Patch
@zag-js/core Patch
@zag-js/docs Patch
@zag-js/preact Patch
@zag-js/react Patch
@zag-js/solid Patch
@zag-js/svelte Patch
@zag-js/vanilla Patch
@zag-js/vue Patch
@zag-js/accordion Patch
@zag-js/angle-slider Patch
@zag-js/async-list Patch
@zag-js/avatar Patch
@zag-js/carousel Patch
@zag-js/cascade-select Patch
@zag-js/checkbox Patch
@zag-js/clipboard Patch
@zag-js/collapsible Patch
@zag-js/color-picker Patch
@zag-js/date-input Patch
@zag-js/date-picker Patch
@zag-js/dialog Patch
@zag-js/drawer Patch
@zag-js/editable Patch
@zag-js/file-upload Patch
@zag-js/floating-panel Patch
@zag-js/hover-card Patch
@zag-js/image-cropper Patch
@zag-js/listbox Patch
@zag-js/marquee Patch
@zag-js/menu Patch
@zag-js/navigation-menu Patch
@zag-js/number-input Patch
@zag-js/pagination Patch
@zag-js/password-input Patch
@zag-js/pin-input Patch
@zag-js/popover Patch
@zag-js/presence Patch
@zag-js/progress Patch
@zag-js/qr-code Patch
@zag-js/radio-group Patch
@zag-js/rating-group Patch
@zag-js/scroll-area Patch
@zag-js/select Patch
@zag-js/signature-pad Patch
@zag-js/slider Patch
@zag-js/splitter Patch
@zag-js/steps Patch
@zag-js/switch Patch
@zag-js/tabs Patch
@zag-js/tags-input Patch
@zag-js/timer Patch
@zag-js/toast Patch
@zag-js/toc Patch
@zag-js/toggle-group Patch
@zag-js/toggle Patch
@zag-js/tooltip Patch
@zag-js/tour Patch
@zag-js/tree-view Patch
@zag-js/store Patch
@zag-js/types Patch
@zag-js/aria-hidden Patch
@zag-js/auto-resize Patch
@zag-js/collection Patch
@zag-js/color-utils Patch
@zag-js/utils Patch
@zag-js/date-utils Patch
@zag-js/dismissable Patch
@zag-js/dom-query Patch
@zag-js/file-utils Patch
@zag-js/focus-trap Patch
@zag-js/focus-visible Patch
@zag-js/highlight-word Patch
@zag-js/hotkeys Patch
@zag-js/i18n-utils Patch
@zag-js/interact-outside Patch
@zag-js/json-tree-utils Patch
@zag-js/live-region Patch
@zag-js/popper Patch
@zag-js/rect-utils Patch
@zag-js/remove-scroll Patch
@zag-js/scroll-snap Patch
@zag-js/stringify-state Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
zag-nextjs Ready Ready Preview Oct 31, 2026 10:34am UTC
zag-solid Ready Ready Preview Oct 31, 2026 10:34am UTC
zag-svelte Ready Ready Preview Oct 31, 2026 10:34am UTC
zag-vue Ready Ready Preview Oct 31, 2026 10:34am UTC
1 Skipped Deployment
Project Deployment Actions Updated
zag-website Ignored Ignored Preview Oct 31, 2026 10:34am UTC

Request Review

@lord-0011 lord-0011 changed the title fix(combobox): only scroll the content when scrolling the highlighted… fix(combobox): only scroll the content when scrolling the highlighted item into view Oct 31, 2026

This branch was successfully deployed

4 active deployments
Preview – zag-solid — 4ecea72f Deployed Oct 31, 2026 by vercel[bot]
Preview – zag-vue — 4ecea72f Deployed Oct 31, 2026 by vercel[bot]
Preview – zag-nextjs — 4ecea72f Deployed Oct 31, 2026 by vercel[bot]
Preview – zag-svelte — 4ecea72f Deployed Oct 31, 2026 by vercel[bot]
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.

Combobox: initially highlighted item scrolls the document on mount

1 participant