Skip to content

fix(ui): fix Select keyboard navigation — first arrow key press now highlights first item#1798

Draft
franzheidl wants to merge 1 commit into
mainfrom
franz-fix-select-keyboard-nav-1781
Draft

fix(ui): fix Select keyboard navigation — first arrow key press now highlights first item#1798
franzheidl wants to merge 1 commit into
mainfrom
franz-fix-select-keyboard-nav-1781

Conversation

@franzheidl

@franzheidl franzheidl commented Jun 25, 2026

Copy link
Copy Markdown
Member

Problem

Dropdown options were always mounted in the DOM, hidden via display: none
on the Floating UI container. Headless UI's DOM-order sort ran against
elements in a hidden subtree on page load, producing an unreliable option
order. On first open, goToOption couldn't resolve the correct active index
and the first few arrow-down presses had no visible effect.

Fix

  • Conditionally render the portal only when open ({open && createPortal(...)})
    so options mount, register, and sort against visible DOM elements
  • Switch SelectOption from as={Fragment} to as="li" so HUI owns the
    element and sets data-active natively
  • Add tabIndex={-1} to the floating container to exclude it from sequential
    keyboard focus order

Closes #1781

Test plan

  • Open Select via keyboard, first arrow-down immediately highlights item 1
  • Open Select via mouse, item 1 (or selected item) is highlighted immediately on open
  • Arrow-up/down, Enter, Escape, Tab all behave correctly
  • Multi-select keyboard navigation works
  • No visual regressions in Select stories

Checklist

  • I have performed a self-review of my code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • My changes generate no new warnings or errors.
  • I have created a changeset for my changes.

PR Manifesto

Review the PR Manifesto for best practises.

…ocuses first menu item

Only mount portal when menu is open so headless sorts items in the actual rendered dom

Signed-off-by: Franz Heidl <f.heidl@sap.com>
@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e222a53

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

🚀 View preview at
https://cloudoperators.github.io/juno/pr-preview/pr-1798/

Built to branch gh-pages at 2026-06-25 13:33 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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.

[Task](ui): fix keyboard navigation in Select so first arrow key press focuses first menu item

1 participant