Skip to content

refactor: Share listbox option props, mouse handlers and keyboard navigation - #5249

Merged
amanabiy merged 3 commits into
mainfrom
refactor/share-listbox-helpers
Nov 6, 2026
Merged

amanabiy merged 3 commits into
mainfrom
refactor/share-listbox-helpers

Conversation

@amanabiy

@amanabiy amanabiy commented Nov 4, 2026

Copy link
Copy Markdown
Member

Description

Moves the option props, mouse handlers and arrow-key navigation from useSelect into pure helpers in src/internal/components/listbox/utils/, and the list prop types into listbox/interfaces.ts, with no behavior change for Select or Multiselect.

Related links, issue #, if available: n/a

How has this been tested?

  • New unit tests for the helpers (option-props.test.ts, navigation.test.ts).
  • Existing Select, Multiselect, Autosuggest, Property filter and listbox unit tests pass unchanged. No existing test file was edited.
  • Documenter and test-utils snapshots are unchanged.
  • Existing integration tests run in CI.
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (58d8f11) to head (a5aa797).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5249      +/-   ##
==========================================
+ Coverage   97.82%   97.83%   +0.01%     
==========================================
  Files        1005     1007       +2     
  Lines       32553    32568      +15     
  Branches    12092    12090       -2     
==========================================
+ Hits        31845    31863      +18     
- Misses        666      699      +33     
+ Partials       42        6      -36     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

🟢 Approval recommended

There are no active review issues blocking the shared listbox helper extraction.

No open issues 🎉

What changed in this PR

Extracts shared listbox logic from useSelect into internal helpers, preserving existing Select and Multiselect behavior while making the logic reusable.

Changes:

  • Moves option props, selection announcements, mouse handlers, and arrow-key navigation into shared helpers.
  • Centralizes list prop types in the listbox module.
  • Adds unit tests for the extracted helpers.
File Description
src/​select/​utils/​use-select.ts Delegates existing logic to shared listbox helpers.
src/​internal/​components/​listbox/​utils/​option-props.ts Provides option props, selection checks, and mouse handlers.
src/​internal/​components/​listbox/​utils/​navigation.ts Extracts arrow-key movement and wraparound handlers.
src/​internal/​components/​listbox/​parts/​plain-list.tsx Imports prop types from the listbox module.
src/​internal/​components/​listbox/​interfaces.ts Defines shared list and option prop types.
src/​internal/​components/​listbox/​__tests__/​option-props.test.ts Tests option state, selection checks, and mouse handling.
src/​internal/​components/​listbox/​__tests__/​navigation.test.ts Tests keyboard movement and wraparound behavior.

Review effort: Balanced

Base automatically changed from refactor/move-shared-listbox-parts to main November 6, 2026 08:37
Adds isHighlightable, getListboxOptionProps, isAnnouncedSelected, getSelectableOption and getListMouseHandlers in listbox/utils/option-props.ts and uses them in useSelect. No behavior change.
Move Select's arrow key wrap logic (goUp/goDown) into a shared helper,
getListboxNavigation, in src/internal/components/listbox/utils/navigation.ts,
and use it in useSelect. The helper keeps Select's current behavior exactly,
including wrapping at the first and last rows. Home/End handling stays in
useMenuKeyboard unchanged.

No behavior change for Select or Multiselect.
ListElementProps (formerly MenuProps) and GetOptionProps now live in src/internal/components/listbox/interfaces.ts. PlainList imports them from there, so the shared list no longer depends on Select's hook module. No behavior change.
@amanabiy
amanabiy force-pushed the refactor/share-listbox-helpers branch from e468024 to a5aa797 Compare November 6, 2026 08:37
const isSelectAll = option.type === 'select-all';
const groupState = isSelectAll || isGroup(option.option) ? selection.getGroupState(option) : undefined;
const selected = isSelectAll ? !!groupState?.selected : selectedSet.has(option) || !!groupState?.selected;
const optionProps: any = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

non-blocking: could we avoid using any here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I will address this in a follow up PR.

@amanabiy
amanabiy added this pull request to the merge queue Nov 6, 2026
@amanabiy
amanabiy removed this pull request from the merge queue due to a manual request Nov 6, 2026
@amanabiy
amanabiy added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 6, 2026
@amanabiy
amanabiy added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit e54ea56 Nov 6, 2026
68 checks passed
@amanabiy
amanabiy deleted the refactor/share-listbox-helpers branch November 6, 2026 10:05

This branch was successfully deployed

3 active deployments
dev-pages-react18 — a5aa7970 Deployed Nov 6, 2026 by amanabiy via deploy (React 18) / deploy #3207
dev-pages-react16 — a5aa7970 Deployed Nov 6, 2026 by amanabiy via deploy (React 16) / deploy #3207
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.

3 participants