Skip to content

Commit e90acbd

Browse files
Refactor: Stabilize platform selector search value updates
Co-authored-by: shannon.anahata <[email protected]>
1 parent ff37338 commit e90acbd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/platformSelector/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use client';
2-
import {Fragment, Ref, useEffect, useMemo, useRef, useState} from 'react';
2+
import {Fragment, Ref, useCallback, useEffect, useMemo, useRef, useState} from 'react';
33
import {Combobox, ComboboxItem, ComboboxList, ComboboxProvider} from '@ariakit/react';
44
import {CaretRightIcon, CaretSortIcon, MagnifyingGlassIcon} from '@radix-ui/react-icons';
55
import * as RadixSelect from '@radix-ui/react-select';
@@ -63,6 +63,11 @@ export function PlatformSelector({
6363
const currentPlatformKey = currentPlatform?.key;
6464
const [open, setOpen] = useState(false);
6565
const [searchValue, setSearchValue] = useState('');
66+
67+
// Stabilize search value updates to prevent focus issues
68+
const handleSearchValueChange = useCallback((value: string) => {
69+
setSearchValue(value);
70+
}, []);
6671

6772
const matches = useMemo(() => {
6873
if (!searchValue) {
@@ -143,7 +148,7 @@ export function PlatformSelector({
143148
open={open}
144149
setOpen={setOpen}
145150
includesBaseElement={false}
146-
setValue={setSearchValue}
151+
setValue={handleSearchValueChange}
147152
>
148153
<RadixSelect.Trigger aria-label="Platform" className={styles.select}>
149154
<RadixSelect.Value placeholder="Choose your SDK" />

0 commit comments

Comments
 (0)