Skip to content

Commit eb4f6e8

Browse files
fix(web): build the PR candidate pickers on the shared combobox
Same Combobox wrapper and search-box treatment as the project and branch pickers, so the three read as one control. Co-Authored-By: Claude Code <[email protected]>
1 parent f121bc4 commit eb4f6e8

1 file changed

Lines changed: 87 additions & 56 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestCandidatePicker.tsx‎

Lines changed: 87 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
* scrolling body that says when the list is loading, could not be read, is empty, or is not all
44
* of it. The rows and the words are the caller's; the frame is the same either way.
55
*
6-
* Built on a popover and the command list rather than a menu: a menu's typeahead claims every
7-
* keypress to jump between rows, which is exactly what a search box cannot share.
6+
* The same combobox as the project and branch pickers, and dressed the same, rather than a menu:
7+
* a menu's typeahead claims every keypress to jump between rows, which a search box cannot share.
88
*/
9+
import { SearchIcon } from "lucide-react";
910
import type { ReactNode } from "react";
1011

1112
import { Button } from "../ui/button";
12-
import { Command, CommandInput, CommandItem, CommandList } from "../ui/command";
13-
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
13+
import {
14+
Combobox,
15+
ComboboxInput,
16+
ComboboxItem,
17+
ComboboxList,
18+
ComboboxPopup,
19+
ComboboxTrigger,
20+
} from "../ui/combobox";
1421
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
1522
import { PullRequestPeopleGhost } from "./PullRequestGhosts";
1623

@@ -81,64 +88,88 @@ export function PullRequestCandidatePicker<T>({
8188
);
8289
}
8390

91+
const keys = candidates.map(candidateKey);
92+
8493
return (
85-
<Popover open={open} onOpenChange={onOpenChange}>
86-
<PopoverTrigger
94+
<Combobox
95+
items={keys}
96+
// The caller narrows the list, so the combobox does no filtering of its own.
97+
filteredItems={keys}
98+
filter={null}
99+
autoHighlight
100+
value={null}
101+
onValueChange={(key) => {
102+
const candidate = candidates.find((entry) => candidateKey(entry) === key);
103+
if (candidate) onSelect(candidate);
104+
}}
105+
open={open}
106+
onOpenChange={(nextOpen, details) => {
107+
// Stays open on a pick: a change is confirmed by the row's own check turning over, and a
108+
// second label or reviewer is usually wanted right after the first.
109+
if (!nextOpen && details.reason === "item-press") return;
110+
onOpenChange(nextOpen);
111+
}}
112+
>
113+
<ComboboxTrigger
87114
render={
88115
<Button size="icon-xs" variant="ghost" aria-label={label}>
89116
{icon}
90117
</Button>
91118
}
92119
/>
93-
<PopoverPopup
94-
align="start"
95-
side="bottom"
96-
className="w-72 before:hidden [--viewport-inline-padding:0]"
97-
viewportClassName="overflow-hidden p-0"
98-
>
99-
{/* The caller narrows the list, so the command does no filtering of its own. */}
100-
<Command mode="none" value={query} onValueChange={onQueryChange}>
101-
<CommandInput
102-
wrapperClassName="border-b border-border/60 px-2 py-2 [&_[data-slot=autocomplete-start-addon]]:ps-2"
103-
className="*:data-[slot=autocomplete-input]:ps-8!"
104-
placeholder={searchLabel}
105-
aria-label={searchLabel}
106-
size="sm"
107-
/>
108-
<CommandList className="max-h-72 not-empty:p-1">
109-
{isPending ? (
110-
<PullRequestPeopleGhost rows={4} />
111-
) : error !== null ? (
112-
<p className="p-2 text-xs text-muted-foreground">
113-
{errorLabel} {error}
114-
</p>
115-
) : candidates.length === 0 ? (
116-
<p className="p-2 text-xs text-muted-foreground">
117-
{query.length > 0 ? noMatchLabel : emptyLabel}
118-
</p>
119-
) : (
120-
candidates.map((candidate) => (
121-
// Stays open on press: a change is confirmed by the row's own check turning over,
122-
// and a second label or reviewer is usually wanted right after the first.
123-
<CommandItem
124-
key={candidateKey(candidate)}
125-
value={candidateKey(candidate)}
126-
disabled={disabled}
127-
onClick={() => onSelect(candidate)}
128-
className="min-h-0 cursor-pointer gap-2 py-1.5 text-xs sm:min-h-0 sm:text-xs"
129-
>
130-
{children(candidate)}
131-
</CommandItem>
132-
))
133-
)}
134-
{truncated ? (
135-
// Typing filters what arrived; it does not ask the host again, so this says what the
136-
// list is rather than offering a search that would find nothing further.
137-
<p className="px-2 py-1.5 text-xs text-muted-foreground">{truncatedLabel}</p>
138-
) : null}
139-
</CommandList>
140-
</Command>
141-
</PopoverPopup>
142-
</Popover>
120+
<ComboboxPopup align="start" side="bottom" className="w-72">
121+
<div className="shrink-0 px-3 pt-2.5">
122+
<div className="relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring">
123+
<SearchIcon
124+
aria-hidden="true"
125+
className="pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55"
126+
/>
127+
<ComboboxInput
128+
aria-label={searchLabel}
129+
className="[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5"
130+
inputClassName="rounded-none bg-transparent text-sm"
131+
placeholder={searchLabel}
132+
showTrigger={false}
133+
size="sm"
134+
unstyled
135+
value={query}
136+
onChange={(event) => onQueryChange(event.target.value)}
137+
/>
138+
</div>
139+
</div>
140+
<ComboboxList className="max-h-72">
141+
{isPending ? (
142+
<PullRequestPeopleGhost rows={4} />
143+
) : error !== null ? (
144+
<p className="p-2 text-xs text-muted-foreground">
145+
{errorLabel} {error}
146+
</p>
147+
) : candidates.length === 0 ? (
148+
<p className="p-2 text-xs text-muted-foreground">
149+
{query.length > 0 ? noMatchLabel : emptyLabel}
150+
</p>
151+
) : (
152+
candidates.map((candidate, index) => (
153+
<ComboboxItem
154+
key={keys[index]}
155+
hideIndicator
156+
index={index}
157+
value={keys[index]}
158+
disabled={disabled}
159+
className="min-h-0 py-1.5 text-xs sm:min-h-0 sm:text-xs"
160+
contentClassName="flex min-w-0 items-center gap-2"
161+
>
162+
{children(candidate)}
163+
</ComboboxItem>
164+
))
165+
)}
166+
{truncated ? (
167+
// Typing filters what arrived; it does not ask the host again, so this says what the
168+
// list is rather than offering a search that would find nothing further.
169+
<p className="px-2 py-1.5 text-xs text-muted-foreground">{truncatedLabel}</p>
170+
) : null}
171+
</ComboboxList>
172+
</ComboboxPopup>
173+
</Combobox>
143174
);
144175
}

0 commit comments

Comments
 (0)