Skip to content

Commit

Permalink
Revert useHighlightedIndex and check log
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Aug 19, 2024
1 parent d4b0cb5 commit 72e9509
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/components/BaseSelect/useHighlightedIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function useHighlightedIndex<T extends Option>(

// Find highlighted index in items to select base on selected item value
// If there is no match, leave highlighted index as -1
console.log('Has selected', selectedItem);
setHighlightedIndex(getIndexToHighlight(items, selectedItem));
}, [items, selectedItem]);

Expand Down Expand Up @@ -69,8 +70,10 @@ function getIndexToHighlight<T extends Option>(
selectedItem: T
): number {
if (typeof selectedItem === "string") {
console.log(items, selectedItem, items.findIndex((item) => item.value === selectedItem));
return items.findIndex((item) => item.value === selectedItem);
}
console.log(items, selectedItem, items.findIndex((item) => item.value === selectedItem?.value));

return items.findIndex((item) => item.value === selectedItem?.value);
}
13 changes: 7 additions & 6 deletions src/components/Combobox/Common/useCombobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FocusEvent, useState } from "react";
import {
Option,
SingleChangeHandler,
// useHighlightedIndex,
useHighlightedIndex,
} from "~/components/BaseSelect";

const getItemsFilter = <T extends Option>(
Expand Down Expand Up @@ -48,10 +48,10 @@ export const useCombobox = <T extends Option, V extends string | Option>({
const typed = Boolean(selectedItem || active || inputValue);

const itemsToSelect = getItemsFilter<T>(inputValue, options);
// const { highlightedIndex, onHighlightedIndexChange } = useHighlightedIndex(
// itemsToSelect,
// selectedItem
// );
const { highlightedIndex, onHighlightedIndexChange } = useHighlightedIndex(
itemsToSelect,
selectedItem
);

const {
isOpen,
Expand All @@ -60,11 +60,12 @@ export const useCombobox = <T extends Option, V extends string | Option>({
getMenuProps,
getInputProps: _getInputProps,
getItemProps,
highlightedIndex,
} = useDownshiftCombobox({
items: itemsToSelect,
itemToString: (item) => item?.label ?? "",
selectedItem,
highlightedIndex,
onHighlightedIndexChange,
isItemDisabled: (item) => item.disabled ?? false,
onStateChange: ({ inputValue: newInputValue, type }) => {
switch (type) {
Expand Down

0 comments on commit 72e9509

Please sign in to comment.