Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/ui/src/dropdowns/custom-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ function Option(props: ICustomSelectItemProps) {
const { children, value, className } = props;
const closeDropdown = useContext(DropdownContext);

const handleMouseDown = useCallback(() => {
const handleClick = useCallback(() => {
// Close dropdown for both new and already-selected options.
requestAnimationFrame(() => closeDropdown());
// Use setTimeout to ensure HeadlessUI's onChange handler fires first for new selections.
// For already-selected options, this ensures the dropdown closes since onChange won't fire.
setTimeout(() => {
closeDropdown();
}, 0);
}, [closeDropdown]);

return (
Expand All @@ -163,9 +167,10 @@ function Option(props: ICustomSelectItemProps) {
className
)
}
onClick={handleClick}
>
{({ selected }) => (
<div onMouseDown={handleMouseDown} className="flex items-center justify-between gap-2 w-full">
<div className="flex items-center justify-between gap-2 w-full">
{children}
{selected && <Check className="h-3.5 w-3.5 flex-shrink-0" />}
</div>
Expand Down
Loading