Skip to content

Commit 192ed9b

Browse files
[WEB-5654]fix: custom select selection and dropdown close #8324
1 parent 119cf39 commit 192ed9b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

packages/ui/src/dropdowns/custom-select.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,13 @@ function Option(props: ICustomSelectItemProps) {
146146
const { children, value, className } = props;
147147
const closeDropdown = useContext(DropdownContext);
148148

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

154158
return (
@@ -163,9 +167,10 @@ function Option(props: ICustomSelectItemProps) {
163167
className
164168
)
165169
}
170+
onClick={handleClick}
166171
>
167172
{({ selected }) => (
168-
<div onMouseDown={handleMouseDown} className="flex items-center justify-between gap-2 w-full">
173+
<div className="flex items-center justify-between gap-2 w-full">
169174
{children}
170175
{selected && <Check className="h-3.5 w-3.5 flex-shrink-0" />}
171176
</div>

0 commit comments

Comments
 (0)