-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Facility Organization Dropdown #10104
base: develop
Are you sure you want to change the base?
Changes from all commits
2331940
14813fd
84bf83e
7e0f0f2
5979374
40abd27
91951d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -49,27 +49,23 @@ export default function Autocomplete({ | |||||||||||||||
"data-cy": dataCy, | ||||||||||||||||
}: AutocompleteProps) { | ||||||||||||||||
const [open, setOpen] = React.useState(false); | ||||||||||||||||
const selectedOption = options.find((option) => option.value === value); | ||||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
<Popover open={open} onOpenChange={setOpen} modal={true}> | ||||||||||||||||
<PopoverTrigger asChild className={popoverClassName}> | ||||||||||||||||
<Button | ||||||||||||||||
title={ | ||||||||||||||||
value | ||||||||||||||||
? options.find((option) => option.value === value)?.label | ||||||||||||||||
: undefined | ||||||||||||||||
} | ||||||||||||||||
title={selectedOption?.label} | ||||||||||||||||
variant="outline" | ||||||||||||||||
role="combobox" | ||||||||||||||||
aria-expanded={open} | ||||||||||||||||
className="w-full justify-between" | ||||||||||||||||
disabled={disabled} | ||||||||||||||||
data-cy={dataCy} | ||||||||||||||||
onClick={() => setOpen(true)} | ||||||||||||||||
> | ||||||||||||||||
<span className="overflow-hidden"> | ||||||||||||||||
{value | ||||||||||||||||
? options.find((option) => option.value === value)?.label | ||||||||||||||||
: placeholder} | ||||||||||||||||
<span className={cn("truncate", !selectedOption && "text-gray-500")}> | ||||||||||||||||
{selectedOption ? selectedOption.label : placeholder} | ||||||||||||||||
</span> | ||||||||||||||||
<CaretSortIcon className="ml-2 size-4 shrink-0 opacity-50" /> | ||||||||||||||||
</Button> | ||||||||||||||||
|
@@ -98,7 +94,7 @@ export default function Autocomplete({ | |||||||||||||||
(option) => | ||||||||||||||||
option.label.toLowerCase() === v.toLowerCase(), | ||||||||||||||||
)?.value || ""; | ||||||||||||||||
onChange(currentValue === value ? "" : currentValue); | ||||||||||||||||
onChange(currentValue); | ||||||||||||||||
setOpen(false); | ||||||||||||||||
}} | ||||||||||||||||
Comment on lines
+97
to
99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize onSelect handler to prevent unnecessary updates. The current implementation doesn't check if the selected value is different from the current value, which could lead to unnecessary re-renders and might contribute to the reported dropdown behavior issues. Apply this optimization: - onChange(currentValue);
- setOpen(false);
+ if (currentValue !== value) {
+ onChange(currentValue);
+ setOpen(false);
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||
> | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix dropdown toggle behavior.
The current onClick implementation doesn't properly handle the toggle case, which explains the reported issue where "dropdown closes when clicked with a value selected". The dropdown should toggle between open/closed states.
Apply this fix:
📝 Committable suggestion