Skip to content

Commit 214936e

Browse files
authored
Merge pull request #45 from asfires/t3code/keyboard-font-search-selection
fix(web): font picker highlights and Enter-selects the first match after typing
2 parents 44d7688 + 910ad89 commit 214936e

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

apps/web/src/components/settings/FontFamilyPicker.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,14 @@ export function FontFamilyPicker({
190190
return candidate;
191191
}, [families, query, requireMonospace]);
192192

193-
const items = useMemo(() => {
193+
const collectionItems = useMemo(() => {
194+
const result = [DEFAULT_FONT_VALUE];
195+
if (manualFamily !== null) result.push(manualFamily);
196+
result.push(...families);
197+
return result;
198+
}, [families, manualFamily]);
199+
200+
const filteredItems = useMemo(() => {
194201
const normalizedQuery = query.trim().toLowerCase();
195202
const result: string[] = [];
196203
if (normalizedQuery.length === 0) result.push(DEFAULT_FONT_VALUE);
@@ -239,8 +246,8 @@ export function FontFamilyPicker({
239246

240247
return (
241248
<Combobox
242-
items={items}
243-
filteredItems={items}
249+
items={collectionItems}
250+
filteredItems={filteredItems}
244251
autoHighlight
245252
virtualized
246253
open={open}
@@ -301,12 +308,17 @@ export function FontFamilyPicker({
301308
<ComboboxListVirtualized className="size-full min-w-0 p-0">
302309
<LegendList<string>
303310
ref={listRef}
304-
data={items}
311+
data={filteredItems}
312+
// LegendList only re-renders a row when its item or extraData
313+
// changes, so a font that stays visible while the filter shifts
314+
// its position would keep a stale `index`. Base UI highlights and
315+
// Enter-selects by index, so every filter change must re-render.
316+
extraData={filteredItems}
305317
keyExtractor={(item) => item}
306318
renderItem={({ item, index }) => renderItem(item, index)}
307319
estimatedItemSize={30}
308320
drawDistance={360}
309-
style={{ height: Math.min(items.length * 30, 288) }}
321+
style={{ height: Math.min(filteredItems.length * 30, 288) }}
310322
/>
311323
</ComboboxListVirtualized>
312324
</div>

0 commit comments

Comments
 (0)