|
3 | 3 | * scrolling body that says when the list is loading, could not be read, is empty, or is not all |
4 | 4 | * of it. The rows and the words are the caller's; the frame is the same either way. |
5 | 5 | * |
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. |
8 | 8 | */ |
| 9 | +import { SearchIcon } from "lucide-react"; |
9 | 10 | import type { ReactNode } from "react"; |
10 | 11 |
|
11 | 12 | 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"; |
14 | 21 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
15 | 22 | import { PullRequestPeopleGhost } from "./PullRequestGhosts"; |
16 | 23 |
|
@@ -81,64 +88,88 @@ export function PullRequestCandidatePicker<T>({ |
81 | 88 | ); |
82 | 89 | } |
83 | 90 |
|
| 91 | + const keys = candidates.map(candidateKey); |
| 92 | + |
84 | 93 | 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 |
87 | 114 | render={ |
88 | 115 | <Button size="icon-xs" variant="ghost" aria-label={label}> |
89 | 116 | {icon} |
90 | 117 | </Button> |
91 | 118 | } |
92 | 119 | /> |
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> |
143 | 174 | ); |
144 | 175 | } |
0 commit comments