TypeScript
fix(web): let the PR reviewer and label search boxes take keystrokes (#9479)
Julius Marminge0869ad648b67
diff --git a/apps/web/src/components/pullRequest/PullRequestCandidatePicker.tsx b/apps/web/src/components/pullRequest/PullRequestCandidatePicker.tsxindex b42061628d1..c8dd196f299 100644--- a/apps/web/src/components/pullRequest/PullRequestCandidatePicker.tsx+++ b/apps/web/src/components/pullRequest/PullRequestCandidatePicker.tsx@@ -2,12 +2,22 @@* The menu shell the reviewer and label pickers share: an icon trigger, a search box, and a* scrolling body that says when the list is loading, could not be read, is empty, or is not all* of it. The rows and the words are the caller's; the frame is the same either way.+ *+ * The same combobox as the project and branch pickers, and dressed the same, rather than a menu:+ * a menu's typeahead claims every keypress to jump between rows, which a search box cannot share.*/+import { SearchIcon } from "lucide-react";import type { ReactNode } from "react";import { Button } from "../ui/button";-import { Input } from "../ui/input";-import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";+import {+ Combobox,+ ComboboxInput,+ ComboboxItem,+ ComboboxList,+ ComboboxPopup,+ ComboboxTrigger,+} from "../ui/combobox";import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";import { PullRequestPeopleGhost } from "./PullRequestGhosts";@@ -78,27 +88,61 @@ export function PullRequestCandidatePicker<T>({);}+ const keys = candidates.map(candidateKey);+return (- <Menu open={open} onOpenChange={onOpenChange}>- <MenuTrigger+ <Combobox+ items={keys}+ // The caller narrows the list, so the combobox does no filtering of its own.+ filteredItems={keys}+ filter={null}+ autoHighlight+ value={null}+ onValueChange={(key) => {+ const candidate = candidates.find((entry) => candidateKey(entry) === key);+ if (candidate) onSelect(candidate);+ }}+ open={open}+ onOpenChange={(nextOpen, details) => {+ // Stays open on a pick: a change is confirmed by the row's own check turning over, and a+ // second label or reviewer is usually wanted right after the first. Cancelled rather than+ // ignored, so the combobox also skips its own close work: freezing the query and returning+ // focus to the trigger, either of which would take the next keystroke away from the box.+ if (!nextOpen && details.reason === "item-press") {+ details.cancel();+ return;+ }+ onOpenChange(nextOpen);+ }}+ >+ <ComboboxTriggerrender={<Button size="icon-xs" variant="ghost" aria-label={label}>{icon}</Button>}/>- <MenuPopup align="start" side="bottom" className="w-72 p-0">- <div className="border-b border-border/60 p-2">- <Input- autoFocus- value={query}- onChange={(event) => onQueryChange(event.currentTarget.value)}- placeholder={searchLabel}- aria-label={searchLabel}- size="compact"- />+ <ComboboxPopup align="start" side="bottom" className="w-72">+ <div className="shrink-0 px-3 pt-2.5">+ <div className="relative -translate-y-px border-b border-border/70 pb-1.5 transition-colors focus-within:border-ring">+ <SearchIcon+ aria-hidden="true"+ className="pointer-events-none absolute top-1.5 left-0 size-4 shrink-0 text-muted-foreground/55"+ />+ <ComboboxInput+ aria-label={searchLabel}+ className="[&_input]:h-6.5 [&_input]:ps-5 [&_input]:font-sans [&_input]:leading-6.5"+ inputClassName="rounded-none bg-transparent text-sm"+ placeholder={searchLabel}+ showTrigger={false}+ size="sm"+ unstyled+ value={query}+ onChange={(event) => onQueryChange(event.target.value)}+ />+ </div></div>- <div className="max-h-72 overflow-y-auto p-1">+ <ComboboxList className="max-h-72">{isPending ? (<PullRequestPeopleGhost rows={4} />) : error !== null ? (@@ -110,18 +154,18 @@ export function PullRequestCandidatePicker<T>({{query.length > 0 ? noMatchLabel : emptyLabel}</p>) : (- candidates.map((candidate) => (- // Stays open on press: a change is confirmed by the row's own check turning over,- // and a second label or reviewer is usually wanted right after the first.- <MenuItem- key={candidateKey(candidate)}- closeOnClick={false}+ candidates.map((candidate, index) => (+ <ComboboxItem+ key={keys[index]}+ hideIndicator+ index={index}+ value={keys[index]}disabled={disabled}- onClick={() => onSelect(candidate)}className="min-h-0 py-1.5 text-xs sm:min-h-0 sm:text-xs"+ contentClassName="flex min-w-0 items-center gap-2">{children(candidate)}- </MenuItem>+ </ComboboxItem>)))}{truncated ? (@@ -129,8 +173,8 @@ export function PullRequestCandidatePicker<T>({// list is rather than offering a search that would find nothing further.<p className="px-2 py-1.5 text-xs text-muted-foreground">{truncatedLabel}</p>) : null}- </div>- </MenuPopup>- </Menu>+ </ComboboxList>+ </ComboboxPopup>+ </Combobox>);}