Skip to content

Commit 082beae

Browse files
committed
fix: maintain alphabetical order when searching
1 parent adfd577 commit 082beae

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/browser-sdk/src/toolbar/Features.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ export function FeaturesTable({
2525
.toLocaleLowerCase()
2626
.includes(searchQuery?.toLocaleLowerCase() ?? ""),
2727
);
28-
// List features that match the search query first
28+
29+
// List features that match the search query first then alphabetically
2930
const searchedFeatures =
3031
searchQuery === null
3132
? features
32-
: [...features].sort((a, _b) => (a.key.includes(searchQuery) ? -1 : 1));
33+
: [...features].sort((a, b) => {
34+
const aMatches = a.key.includes(searchQuery);
35+
const bMatches = b.key.includes(searchQuery);
36+
37+
// If both match or both don't match, sort alphabetically
38+
if (aMatches === bMatches) {
39+
return a.key.localeCompare(b.key);
40+
}
41+
42+
// Otherwise, matching features come first
43+
return aMatches ? -1 : 1;
44+
});
45+
3346
return (
3447
<table class="features-table" style={{ "--n": searchedFeatures.length }}>
3548
<tbody>

0 commit comments

Comments
 (0)