Command palette
What Enter does in a command palette is decided at the keystroke, and results that arrive later can’t change it.
The problem
Type “ale” in a palette and hit Enter. If remote results arrive between your last keystroke and your Enter, the top row can change under your finger, and you open something you never saw. How fast the network is decides what Enter means.
What I concluded
The default row is chosen only from rows known at the keystroke. Local matches (pages, actions) are ranked right away. Remote results render below them when they arrive, and they never take the default.
// text is the query, already trimmed and lowercased
const tier = (title, text, words) => {
const t = title.toLowerCase();
if (t === text) return 0; // exact
if (t.startsWith(text)) return 1; // prefix
if (startsWords(title, words)) return 2; // each word starts one
return -1;
};
Matching is “every typed word starts some word of the title”, so “min” never finds “Admin”. When nothing local matches, the default is a search row (or, for a longer phrase, “Ask the assistant”), which is also known at the keystroke.
Rules
- The default comes from what’s known now. Local rows and fixed fallbacks only.
- Late results go below. They append. They never insert above or move the default.
- Rank by tier, then order. Exact, then prefix, then word starts. Predictable beats clever.
- Word starts, not substrings. Substring matches surface noise the person didn’t mean.
- Screen readers get the same guarantee. Focus stays in the input and
aria-activedescendantpoints at the default row, so the row announced is the row Enter opens.
What you get
A palette people can type into at full speed and trust. Enter means the same thing before and after the network answers.
The demo shows the ranking and the default row: flip the toggle to watch the default change under your finger when the rule is off. Related: Navigation.