combobox: highlighted item never scrolls into view when there's no content part (Ark Command)

Open Beginner friendly
#3,728 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript

Research direction

Start in combobox.dom.ts and trace how getItemEl finds an item when the component has no content part; the issue identifies the list as the fallback container. Reproduce with the provided Command example by moving the highlight past the visible items. Done when the highlighted item scrolls into view without a content part and existing content-part behavior still works.

Written by the indexing model from the issue text.

Description

🐛 Bug report

In a combobox without a content part, like Ark's Command, the highlighted item never scrolls into view. getItemEl only looks inside the content element, so it returns null. That leaves scrollToHighlightedItem with nothing to scroll, and scrollToIndexFn's getElement() returns null too.

💥 Steps to reproduce

  1. Render a Command with more items than fit in the list (snippet below).
  2. Focus the input.
  3. Press ArrowDown 15 times.
  4. "Item 15" is highlighted but off-screen. The list's scrollTop stays at 0.

💻 Link to reproduction

No sandbox yet. This is the snippet I used:

import { Command, createListCollection } from '@ark-ui/react/command'

const collection = createListCollection({
  items: Array.from({ length: 30 }, (_, i) => ({ value: `item-${i}`, label: `Item ${i}` })),
})

export const Repro = () => (
  <Command.Root collection={collection}>
    <Command.Input placeholder="Search" />
    <Command.List style={{ maxHeight: 200, overflow: 'auto' }}>
      {collection.items.map((item) => (
        <Command.Item key={item.value} item={item}>
          <Command.ItemText>{item.label}</Command.ItemText>
        </Command.Item>
      ))}
    </Command.List>
  </Command.Root>
)

🧐 Expected behavior

The list scrolls so the highlighted item stays visible, as it does when a content part is rendered.

🧭 Possible Solution

Fall back to the list in getItemEl (combobox.dom.ts):

return query(getContentEl(ctx) ?? getListEl(ctx), selector)

With that patched into the repro, the list scrolls (scrollTop 88) and "Item 15" is visible.

🌍 System information

Software Version(s)
Zag Version 2.0.0-next.4 (same code on v2 head)
Browser Chrome for Testing 151
Operating System macOS 15

📝 Additional information

Found while moving the Ark docs search to Command.

Dominant language
TypeScript
Stars
5.3k
Forks
320
Avg merge
1d 22h
Merged PRs (30d)
60

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from chakra-ui/zag

All issues in chakra-ui/zag

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.