|
|
@ -26,14 +26,19 @@ export default function DropdownSearchList ({ |
|
|
|
hideItemIf, |
|
|
|
hideItemIf, |
|
|
|
listContainerClassName, |
|
|
|
listContainerClassName, |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function close() { |
|
|
|
|
|
|
|
setIsOpen(false) |
|
|
|
|
|
|
|
onClose && onClose() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const t = useContext(I18nContext) |
|
|
|
const t = useContext(I18nContext) |
|
|
|
const [isOpen, setIsOpen] = useState(false) |
|
|
|
const [isOpen, setIsOpen] = useState(false) |
|
|
|
const [selectedItem, setSelectedItem] = useState(startingItem) |
|
|
|
const [selectedItem, setSelectedItem] = useState(startingItem) |
|
|
|
const onClickItem = useCallback((item) => { |
|
|
|
const onClickItem = useCallback((item) => { |
|
|
|
onSelect && onSelect(item) |
|
|
|
onSelect && onSelect(item) |
|
|
|
setSelectedItem(item) |
|
|
|
setSelectedItem(item) |
|
|
|
setIsOpen(false) |
|
|
|
close(); |
|
|
|
onClose && onClose() |
|
|
|
|
|
|
|
}, [onClose, onSelect]) |
|
|
|
}, [onClose, onSelect]) |
|
|
|
|
|
|
|
|
|
|
|
const onClickSelector = useCallback(() => { |
|
|
|
const onClickSelector = useCallback(() => { |
|
|
@ -58,9 +63,10 @@ export default function DropdownSearchList ({ |
|
|
|
}, [externallySelectedItem, selectedItem, prevExternallySelectedItem]) |
|
|
|
}, [externallySelectedItem, selectedItem, prevExternallySelectedItem]) |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div |
|
|
|
<button |
|
|
|
className={classnames('dropdown-search-list', className)} |
|
|
|
className={classnames('dropdown-search-list', className)} |
|
|
|
onClick={onClickSelector} |
|
|
|
onClick={onClickSelector} |
|
|
|
|
|
|
|
onKeyUp={e => e.key === 'Escape' && close()} |
|
|
|
> |
|
|
|
> |
|
|
|
{!isOpen && ( |
|
|
|
{!isOpen && ( |
|
|
|
<div |
|
|
|
<div |
|
|
@ -124,7 +130,7 @@ export default function DropdownSearchList ({ |
|
|
|
/> |
|
|
|
/> |
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</div> |
|
|
|
</button> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|