🔧 chore: follow select changes
This commit is contained in:
parent
30c50a3eec
commit
f77f7c120a
@ -1,7 +1,6 @@
|
|||||||
import React, {
|
import React, {
|
||||||
useState,
|
useState,
|
||||||
ComponentPropsWithoutRef,
|
ComponentPropsWithoutRef,
|
||||||
useCallback,
|
|
||||||
useRef,
|
useRef,
|
||||||
useEffect,
|
useEffect,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
@ -34,7 +33,7 @@ export const UserSelect = ({ options, value }: UserSelectProps) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [selectedItem, setSelectedItem] = useState<UserSelectOption | null>(
|
const [selectedItem, setSelectedItem] = useState<UserSelectOption | null>(
|
||||||
null,
|
(value as UserSelectOption) || null,
|
||||||
);
|
);
|
||||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||||
const [dropdownPosition, setDropdownPosition] = useState<'top' | 'bottom'>(
|
const [dropdownPosition, setDropdownPosition] = useState<'top' | 'bottom'>(
|
||||||
@ -75,10 +74,8 @@ export const UserSelect = ({ options, value }: UserSelectProps) => {
|
|||||||
navigate(`/${selectedItem?.value}`);
|
navigate(`/${selectedItem?.value}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSelected = useCallback(
|
const isSelected = (item: UserSelectOption) =>
|
||||||
(item: UserSelectOption) => selectedItem?.value === item.value,
|
selectedItem?.value === item.value;
|
||||||
[selectedItem],
|
|
||||||
);
|
|
||||||
|
|
||||||
const { isOpen, getMenuProps, highlightedIndex, getItemProps, openMenu } =
|
const { isOpen, getMenuProps, highlightedIndex, getItemProps, openMenu } =
|
||||||
useCombobox({
|
useCombobox({
|
||||||
@ -94,7 +91,7 @@ export const UserSelect = ({ options, value }: UserSelectProps) => {
|
|||||||
onIsOpenChange: ({ isOpen }) => {
|
onIsOpenChange: ({ isOpen }) => {
|
||||||
setDropdownOpen(isOpen ?? false);
|
setDropdownOpen(isOpen ?? false);
|
||||||
},
|
},
|
||||||
selectedItem: selectedItem,
|
selectedItem: value || null,
|
||||||
itemToString: (item) => (item ? item.label : ''),
|
itemToString: (item) => (item ? item.label : ''),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user