Skip to content

feat(core/dropdown): support roving tabindex keyboard navigation - #2659

Open
danielleroux wants to merge 8 commits into
mainfrom
feat/dropdown-roving-tabindex
Open

feat(core/dropdown): support roving tabindex keyboard navigation#2659
danielleroux wants to merge 8 commits into
mainfrom
feat/dropdown-roving-tabindex

Conversation

@danielleroux

@danielleroux danielleroux commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

🆕 What is the new behavior?

  • Support roving tabindex keyboard navigation for dropdown and dropdown-button
  • Simplify overlay/stacking controller

🏁 Checklist

A pull request can only be merged if all of these conditions are met (where applicable):

  • 🦮 Accessibility (a11y) features were implemented
  • 🗺️ Internationalization (i18n) - no hard coded strings
  • 📲 Responsiveness - components handle viewport changes and content overflow gracefully
  • 📕 Add or update a Storybook story
  • 📄 Documentation was reviewed/updated siemens/ix-docs
  • 🧪 Unit tests were added/updated and pass (pnpm test)
  • 📸 Visual regression tests were added/updated and pass (Guide)
  • 🧐 Static code analysis passes (pnpm lint)
  • 🏗️ Successful compilation (pnpm build, changes pushed)

Related

  • EIX-112

👨‍💻 Help & support

Summary by CodeRabbit

  • New Features

    • Added navigationMode="roving-tabindex" to dropdowns and dropdown buttons (default remains the existing mode).
    • Roving tabindex moves real DOM focus across items and supports custom focusable elements via data-ix-roving-item.
    • Enhanced keyboard behavior: Tab/Shift+Tab close dropdowns and move focus appropriately; Escape dismisses nested overlays in the correct hierarchy.
    • Added preview examples and a Storybook story demonstrating the new mode.
  • Bug Fixes

    • Improved nested dropdown/popover coordination, submenu roving behavior, and accessibility behavior (including correct aria-activedescendant handling) during mode changes and closing.

@netlify

netlify Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploy Preview for ix-storybook ready!

Name Link
🔨 Latest commit 4bbd405
🔍 Latest deploy log https://app.netlify.com/projects/ix-storybook/deploys/6a5f18002fca0600084f413f
😎 Deploy Preview https://deploy-preview-2659--ix-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4bbd405

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

This PR includes changesets to release 5 packages
Name Type
@siemens/ix Minor
@siemens/ix-angular Minor
@siemens/ix-docs Minor
@siemens/ix-react Minor
@siemens/ix-vue Minor

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

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds roving-tabindex navigation to dropdowns and dropdown buttons, including native opt-in items, focus restoration, nested submenu behavior, and coordinated dropdown/popover dismissal. Framework preview routes, Storybook coverage, typings, and regression tests are added.

Changes

Dropdown roving tabindex

Layer / File(s) Summary
Shared overlay and focus coordination
packages/core/src/components/utils/nested-overlay/..., packages/core/src/components/utils/focus/focus-trap.ts, packages/core/src/components/dropdown/dropdown-controller.ts, packages/core/src/components/popover/...
Overlay registries and coordinators manage nested dropdown/popover hierarchy, dismissal ordering, composed-tree containment, and adjacent focus targets.
Navigation mode and roving interaction contract
packages/core/src/components/dropdown/dropdown-focus.ts, packages/core/src/components/dropdown-button/dropdown-button.tsx, packages/core/src/components.d.ts, packages/angular/src/components.ts
Adds the navigationMode API and implements roving tabindex, native data-ix-roving-item participation, activation, capture handling, and restoration of original tabindex values.
Dropdown lifecycle and hierarchical focus behavior
packages/core/src/components/dropdown/dropdown.tsx, packages/core/src/components/dropdown-item/dropdown-item.tsx, packages/core/src/components/dropdown/test/*, packages/core/src/components/dropdown-button/dropdown-button.ct.ts
Integrates roving navigation into dropdown opening, submenu focus, mode changes, Tab/Escape handling, cleanup, native elements, and regression coverage.
Nested popover integration and validation
packages/core/src/components/popover/test/popover.ct.ts
Tests dropdown-triggered popovers, focus movement within popovers, and Escape ordering across nested overlays.
Preview examples and release documentation
packages/*-test-app/**/dropdown-roving-tabindex*, packages/storybook-docs/src/stories/dropdown-button.stories.ts, .changeset/dropdown-roving-tabindex.md
Adds roving-tabindex examples and routes for HTML, Angular, React, Vue, and Storybook, plus release documentation.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant IxDropdown
  participant DropdownFocus
  participant OverlayCoordinator
  participant Popover
  User->>IxDropdown: Open or navigate with keyboard
  IxDropdown->>DropdownFocus: Initialize roving tabindex
  DropdownFocus->>IxDropdown: Focus active item and update tabindex
  User->>IxDropdown: Press Tab or Escape
  IxDropdown->>OverlayCoordinator: Resolve hierarchy and dismissal
  OverlayCoordinator->>Popover: Dismiss child or parent overlay as applicable
  OverlayCoordinator->>IxDropdown: Return focus exit target
Loading

Possibly related PRs

  • siemens/ix#2574: Both changes modify nested overlay and popover hierarchy coordination.
  • siemens/ix#2641: Both changes modify dropdown keyboard-navigation behavior in dropdown-focus.ts.

Suggested reviewers: nuke-ellington, lzeiml

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: roving tabindex keyboard navigation for core dropdown components.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dropdown-roving-tabindex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a new navigationMode property to ix-dropdown and ix-dropdown-button components, enabling a roving-tabindex keyboard navigation strategy alongside the default active-descendant mode. It also coordinates nested overlay hierarchies between dropdowns and popovers to ensure seamless keyboard navigation and focus management. Key feedback highlights several critical issues: undefined functions focusLast and focusFirst are used in dropdown.tsx which will cause runtime errors; closestPassShadow fails to traverse across shadow boundaries due to unhandled ShadowRoot nodes; and negative tabindex elements are not excluded when calculating sequential tab order. Additionally, it is recommended to use a Set to track visited IDs in hierarchy traversals to prevent potential infinite loops.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 67 to 76
if (node instanceof HTMLElement) {
if (node.matches(selector)) {
return node;
} else {
return closestPassShadow(node.parentNode!, selector);
}

return closestPassShadow(node.assignedSlot ?? node.parentNode, selector);
}

return closestPassShadow(node.parentNode!, selector);
return closestPassShadow(node.parentNode, selector);
}

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.

critical

The closestPassShadow function fails to traverse across shadow boundaries because it does not handle ShadowRoot nodes. When node is a ShadowRoot, node instanceof HTMLElement is false, and node.parentNode is null, causing the traversal to stop prematurely and return null. To fix this, we should explicitly check if the node is an instance of ShadowRoot and traverse to its host element.

  if (node instanceof HTMLElement) {
    if (node.matches(selector)) {
      return node;
    }

    return closestPassShadow(node.assignedSlot ?? node.parentNode, selector);
  }

  if (node instanceof ShadowRoot) {
    return closestPassShadow(node.host, selector);
  }

  return closestPassShadow(node.parentNode, selector);

Comment on lines +508 to +512
if (event.key === 'ArrowUp' || event.key === 'End') {
focusLast(this.itemsHost);
} else {
focusFirst(this.itemsHost);
}

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.

critical

The functions focusLast and focusFirst are not imported or defined in this file, which will cause a runtime ReferenceError or compilation failure. They should be replaced with the imported focusLastDescendant and focusFirstDescendant utilities.

Suggested change
if (event.key === 'ArrowUp' || event.key === 'End') {
focusLast(this.itemsHost);
} else {
focusFirst(this.itemsHost);
}
if (event.key === 'ArrowUp' || event.key === 'End') {
focusLastDescendant(this.itemsHost);
} else {
focusFirstDescendant(this.itemsHost);
}

Comment on lines +975 to +982
const focusableElements = queryElements(
document.body,
focusableQueryString
).filter(
(element) =>
closestPassShadow(element, 'ix-dropdown') === null &&
element.getClientRects().length > 0
);

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.

high

When calculating the sequential tab order to exit the dropdown, elements with a negative tabindex (such as tabindex="-1") should be excluded, as they are not part of the sequential keyboard navigation flow. Otherwise, pressing Tab could incorrectly move focus to an unfocusable element. Additionally, querying the entire document.body on every Tab key press can be a performance bottleneck in large applications, and standard query selectors do not traverse shadow DOM boundaries.

    const focusableElements = queryElements(
      document.body,
      focusableQueryString
    ).filter(
      (element) =>
        element.tabIndex >= 0 &&
        closestPassShadow(element, 'ix-dropdown') === null &&
        element.getClientRects().length > 0
    );

Comment on lines +192 to 206
private getRootDropdown(dropdown: DropdownInterface) {
let root = dropdown;
let parentId = this.getParentDropdownId(root.getId());

while (parentId) {
const parent = this.registry.get(parentId);
if (!parent) {
break;
}
});
root = parent;
parentId = this.getParentDropdownId(root.getId());
}

return root;
}

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.

medium

To prevent potential infinite loops in case of circular parent-child relationships in the dropdown hierarchy, it is recommended to keep track of visited IDs using a Set.

  private getRootDropdown(dropdown: DropdownInterface) {
    let root = dropdown;
    let parentId = this.getParentDropdownId(root.getId());
    const visited = new Set<string>([root.getId()]);

    while (parentId && !visited.has(parentId)) {
      const parent = this.registry.get(parentId);
      if (!parent) {
        break;
      }
      root = parent;
      visited.add(parentId);
      parentId = this.getParentDropdownId(root.getId());
    }

    return root;
  }

Comment on lines +942 to +953
private getDropdownHierarchy() {
const hierarchy: Dropdown[] = [this];
let parentId = dropdownController.getParentDropdownId(this.getId());

while (parentId) {
const parent = dropdownController.getDropdownById(parentId) as Dropdown;
hierarchy.push(parent);
parentId = dropdownController.getParentDropdownId(parent.getId());
}

return hierarchy;
}

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.

medium

To prevent potential infinite loops in case of circular parent-child relationships in the dropdown hierarchy, it is recommended to keep track of visited IDs using a Set.

  private getDropdownHierarchy() {
    const hierarchy: Dropdown[] = [this];
    let parentId = dropdownController.getParentDropdownId(this.getId());
    const visited = new Set<string>([this.getId()]);

    while (parentId && !visited.has(parentId)) {
      const parent = dropdownController.getDropdownById(parentId) as Dropdown;
      if (!parent) {
        break;
      }
      hierarchy.push(parent);
      visited.add(parentId);
      parentId = dropdownController.getParentDropdownId(parent.getId());
    }

    return hierarchy;
  }

Comment on lines +191 to +202
private isDescendantOf(childKey: string, parentKey: string) {
let current = this.getParentKey(childKey);

while (current) {
if (current === parentKey) {
return true;
}
current = this.getParentKey(current);
}

return false;
}

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.

medium

To prevent potential infinite loops in case of circular parent-child relationships in the overlay hierarchy, it is recommended to keep track of visited IDs using a Set.

  private isDescendantOf(childKey: string, parentKey: string) {
    let current = this.getParentKey(childKey);
    const visited = new Set<string>();

    while (current && !visited.has(current)) {
      if (current === parentKey) {
        return true;
      }
      visited.add(current);
      current = this.getParentKey(current);
    }

    return false;
  }

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/components/dropdown-button/dropdown-button.ct.ts`:
- Around line 174-217: Add makeAxeBuilder() accessibility assertions to the
roving-tabindex regression tests in the dropdown-button test file, covering the
rendered dropdown in its new focus/tabindex state. Apply the same axe coverage
to the additional roving-tabindex test range, while preserving the existing
hydration and focus/ARIA behavior assertions.

In `@packages/core/src/components/dropdown/dropdown.tsx`:
- Around line 983-992: Replace the inline tab-order sorting in the dropdown’s
focusable-elements flow with the shared sortByTabOrder comparator from
focus-trap.ts. Export the existing helper if necessary, import and reuse it
here, and preserve the current positive-tabIndex ordering with document-order
tie-breaking.

In `@packages/core/src/components/dropdown/test/dropdown.ct.ts`:
- Around line 793-813: Add an accessibility check using makeAxeBuilder() to the
Roving tabindex navigation tests, covering the mounted
navigation-mode="roving-tabindex" dropdown fixture. Reuse the existing
regressionTest setup and assert the axe scan passes alongside the current focus
and tabindex behavior checks.

In `@packages/core/src/components/utils/nested-overlay/overlay-coordinator.ts`:
- Around line 153-164: In dismissCrossTypeChildren, split the
children.reverse().forEach(...) chain into separate statements: reverse children
first, then invoke forEach to dismiss each entry with the existing reason.
Preserve the current reverse-order dismissal behavior.

In `@packages/react-test-app/src/preview-examples/dropdown-roving-tabindex.tsx`:
- Line 18: Replace the anonymous default-export arrow function with a named
function component in the default export, preserving its existing JSX and
behavior so React DevTools and Fast Refresh can identify it.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e1296fe7-18c4-4500-99e4-09a05f513a63

📥 Commits

Reviewing files that changed from the base of the PR and between 9e17b20 and c1ab471.

⛔ Files ignored due to path filters (9)
  • packages/angular/standalone/src/components.ts is excluded by !packages/angular/standalone/src/components.ts
  • packages/react/src/components/components.server.ts is excluded by !packages/react/src/components/**
  • packages/vue/src/components/ix-dropdown-button.ts is excluded by !packages/vue/src/components/**
  • packages/vue/src/components/ix-dropdown.ts is excluded by !packages/vue/src/components/**
  • testing/framework-tests/tests/generated/axe.ts is excluded by !**/generated/**
  • testing/framework-tests/tests/generated/dropdown-roving-tabindex-axe.spec.ts is excluded by !**/generated/**
  • testing/framework-tests/tests/generated/dropdown-roving-tabindex.spec.ts is excluded by !**/generated/**
  • testing/framework-tests/tests/generated/index.ts is excluded by !**/generated/**
  • testing/framework-tests/tests/generated/test-ids.autogenerated.ts is excluded by !**/generated/**
📒 Files selected for processing (33)
  • .changeset/dropdown-roving-tabindex.md
  • packages/angular-standalone-test-app/src/app/app.routes.ts
  • packages/angular-standalone-test-app/src/preview-examples/dropdown-roving-tabindex.ts
  • packages/angular-test-app/src/app/app-routing.module.ts
  • packages/angular-test-app/src/app/app.module.ts
  • packages/angular-test-app/src/preview-examples/dropdown-roving-tabindex.ts
  • packages/angular/src/components.ts
  • packages/core/src/components.d.ts
  • packages/core/src/components/dropdown-button/dropdown-button.ct.ts
  • packages/core/src/components/dropdown-button/dropdown-button.tsx
  • packages/core/src/components/dropdown/dropdown-controller.ts
  • packages/core/src/components/dropdown/dropdown-focus.ts
  • packages/core/src/components/dropdown/dropdown.tsx
  • packages/core/src/components/dropdown/test/dropdown.ct.ts
  • packages/core/src/components/popover/popover-controller.ts
  • packages/core/src/components/popover/popover.tsx
  • packages/core/src/components/popover/test/popover-controller.spec.ts
  • packages/core/src/components/popover/test/popover.ct.ts
  • packages/core/src/components/utils/focus/focus-trap.ts
  • packages/core/src/components/utils/nested-overlay/index.ts
  • packages/core/src/components/utils/nested-overlay/nested-overlay-registry.ts
  • packages/core/src/components/utils/nested-overlay/overlay-coordinator.ts
  • packages/core/src/components/utils/nested-overlay/test/nested-overlay.spec.ts
  • packages/core/src/components/utils/nested-overlay/test/overlay-coordinator.spec.ts
  • packages/core/src/components/utils/overlay.ts
  • packages/core/src/components/utils/shadow-dom.ts
  • packages/core/src/components/utils/test/shadow-dom.spec.ts
  • packages/html-test-app/src/preview-examples/dropdown-roving-tabindex.html
  • packages/react-test-app/src/main.tsx
  • packages/react-test-app/src/preview-examples/dropdown-roving-tabindex.tsx
  • packages/storybook-docs/src/stories/dropdown-button.stories.ts
  • packages/vue-test-app/src/Root.vue
  • packages/vue-test-app/src/preview-examples/dropdown-roving-tabindex.vue
💤 Files with no reviewable changes (1)
  • packages/core/src/components/utils/overlay.ts

Comment thread packages/core/src/components/dropdown-button/dropdown-button.ct.ts
Comment thread packages/core/src/components/dropdown/dropdown.tsx Outdated
Comment thread packages/core/src/components/dropdown/test/dropdown.ct.ts
Comment thread packages/react-test-app/src/preview-examples/dropdown-roving-tabindex.tsx Outdated
@sonarqubecloud

Copy link
Copy Markdown

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