Skip to content

Commit f6ade78

Browse files
Copilotjeswr
andcommitted
Fix inefficient indexOf call in UrlCombobox
Co-authored-by: jeswr <63333554+jeswr@users.noreply.github.com>
1 parent 80e6318 commit f6ade78

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

app/components/shared/UrlCombobox.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface UrlComboboxProps {
2727
"aria-describedby"?: string;
2828
className?: string;
2929
inputClassName?: string;
30-
renderOption?: (option: ComboboxOption, isHighlighted: boolean) => ReactNode;
30+
renderOption?: (option: ComboboxOption, isHighlighted: boolean, index: number) => ReactNode;
3131
}
3232

3333
export default function UrlCombobox({
@@ -149,10 +149,10 @@ export default function UrlCombobox({
149149
const paddingLeft = leftIcon ? "pl-9" : "px-4";
150150
const paddingRight = showChevron ? "pr-10" : "pr-4";
151151

152-
const defaultRenderOption = (option: ComboboxOption, isHighlighted: boolean) => (
152+
const defaultRenderOption = (option: ComboboxOption, isHighlighted: boolean, index: number) => (
153153
<button
154154
key={option.value}
155-
id={`${inputId}-option-${filteredOptions.indexOf(option)}`}
155+
id={`${inputId}-option-${index}`}
156156
type="button"
157157
onClick={() => handleSelect(option)}
158158
className={`w-full px-4 py-3 text-left focus:outline-none ${
@@ -245,8 +245,8 @@ export default function UrlCombobox({
245245
>
246246
{filteredOptions.map((option, index) => (
247247
renderOption
248-
? renderOption(option, highlightedIndex === index)
249-
: defaultRenderOption(option, highlightedIndex === index)
248+
? renderOption(option, highlightedIndex === index, index)
249+
: defaultRenderOption(option, highlightedIndex === index, index)
250250
))}
251251
</div>
252252
)}

0 commit comments

Comments
 (0)