Skip to content

Rank Select options with match-sorter#26170

Open
dennisoelkers wants to merge 5 commits into
masterfrom
feat/select-match-sorter-ranking
Open

Rank Select options with match-sorter#26170
dennisoelkers wants to merge 5 commits into
masterfrom
feat/select-match-sorter-ranking

Conversation

@dennisoelkers
Copy link
Copy Markdown
Member

@dennisoelkers dennisoelkers commented May 29, 2026

Description

Use match-sorter inside the shared Select component to filter and rank options by match quality (exact → starts-with → word-starts-with → contains → ...) so the best prefix matches bubble to the top of typeahead suggestions across every caller (e.g. FieldSelect and the rest).

Async selects are left untouched — their results are server-driven, so we keep the existing filterOption path for them.

Motivation and Context

The default sorting is a substring match that preserves the original option order. With long lists (fields, lookup tables, streams, ...) this means typing a perfectly matching prefix can leave the desired entry buried below incidental substring hits:

image

Fig 1. Before: User desparately searching for the source field although it was already completely typed in

Switching synchronous selects to match-sorter reorders the dropdown by relevance, which matches what users intuitively expect:

image

Fig 2. After: The user is happy now, the right field is presented just after two characters!

How Has This Been Tested?

  • yarn tsc
  • Manually exercised FieldSelect typeahead and a few other Select callers in the dev server — exact and prefix matches now appear at the top of the menu; async selects (e.g. user pickers) behave unchanged.

Screenshots (if appropriate):

Types of changes

  • Refactoring (non-breaking change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

Fixes #11485

dennisoelkers and others added 2 commits May 29, 2026 13:23
Use match-sorter inside the shared `Select` component to filter and sort
options by match quality (exact, starts-with, word-starts-with, contains, ...)
so prefix matches bubble to the top of typeahead suggestions across every
caller (FieldSelect and the rest). Async selects keep server-driven results
untouched.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dennisoelkers dennisoelkers marked this pull request as draft May 29, 2026 12:26
dennisoelkers and others added 2 commits May 29, 2026 14:35
After match-sorter re-ranks options on each keystroke, react-select's
MenuList kept its previous scroll offset, so the highest-ranked matches
ended up scrolled out of view. Make `inputValue` a controlled prop on
react-select and have `CustomMenuList` snap `scrollTop` back to 0
whenever it changes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dennisoelkers dennisoelkers marked this pull request as ready for review June 3, 2026 15:04
@linuspahl linuspahl added the e2e-tests Run PR build with e2e tests. label Jun 4, 2026

const sortedOptions =
!async && inputValue
? matchSorter(rawOptions, inputValue, {
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.

I can see a benefit in memoizing the result of matchSorter, so it is not called on every render. Especially in forms we often face the challenge that elements rerender frequently when interacting with the form. Since I did not notice any performance problems, this is not a high priority for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-tests Run PR build with e2e tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefer exact field name matches when filtering list of fields

2 participants