Home / Function/ ComboBox() — supabase Function Reference

ComboBox() — supabase Function Reference

Architecture documentation for the ComboBox() function in ProjectConfigVariables.ComboBox.tsx from the supabase codebase.

Entity Profile

Dependency Diagram

graph TD
  43a612a3_ae1c_06b7_bda8_994be99d8dd4["ComboBox()"]
  49800345_99af_55a9_d6fd_a34b97143772["useIntersectionObserver()"]
  43a612a3_ae1c_06b7_bda8_994be99d8dd4 -->|calls| 49800345_99af_55a9_d6fd_a34b97143772
  style 43a612a3_ae1c_06b7_bda8_994be99d8dd4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/docs/components/ProjectConfigVariables/ProjectConfigVariables.ComboBox.tsx lines 26–161

export function ComboBox<Opt extends ComboBoxOption>({
  isLoading,
  disabled,
  name,
  options,
  selectedOption,
  selectedDisplayName,
  onSelectOption = noop,
  className,
  search = '',
  hasNextPage = false,
  isFetching = false,
  isFetchingNextPage = false,
  fetchNextPage,
  setSearch = () => {},
  useCommandSearch = true,
}: {
  isLoading: boolean
  disabled?: boolean
  name: string
  options: Opt[]
  selectedOption?: string
  selectedDisplayName?: string
  onSelectOption?: (newValue: string) => void
  className?: string
  search?: string
  hasNextPage?: boolean
  isFetching?: boolean
  isFetchingNextPage?: boolean
  fetchNextPage?: () => void
  setSearch?: (value: string) => void
  useCommandSearch?: boolean
}) {
  const [open, setOpen] = useState(false)

  const scrollRootRef = useRef<HTMLDivElement | null>(null)
  const [sentinelRef, entry] = useIntersectionObserver({
    root: scrollRootRef.current,
    threshold: 0,
    rootMargin: '0px',
  })

  useEffect(() => {
    if (!isLoading && !isFetching && !isFetchingNextPage && hasNextPage && entry?.isIntersecting) {
      fetchNextPage?.()
    }
  }, [isLoading, isFetching, isFetchingNextPage, hasNextPage, entry?.isIntersecting, fetchNextPage])

  return (
    <Popover
      open={open}
      onOpenChange={(value) => {
        setOpen(value)
        if (!value) setSearch('')
      }}
    >
      <PopoverTrigger asChild>
        <Button
          variant="outline"
          role="combobox"
          disabled={disabled}
          aria-expanded={open}
          className={cn(
            'overflow-hidden',
            'h-auto min-h-10',
            'flex justify-between',
            'border-none',
            'py-0 pl-0 pr-1 text-left',
            className
          )}
        >
          {selectedDisplayName ??
            (isLoading && options.length > 0
              ? 'Loading...'
              : options.length === 0
                ? `No ${name} found`
                : `Select a ${name}...`)}
          <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
        </Button>
      </PopoverTrigger>
      <PopoverContent className="p-0" side="bottom" align="start">
        <Command shouldFilter={useCommandSearch}>
          <CommandInput
            placeholder={`Search ${name}...`}
            className="border-none ring-0"
            showResetIcon
            value={search}
            onValueChange={setSearch}
            handleReset={() => setSearch('')}
          />
          <CommandList>
            <CommandGroup>
              {isLoading ? (
                <div className="px-2 py-1 flex flex-col gap-2">
                  <ShimmeringLoader className="w-full" />
                  <ShimmeringLoader className="w-4/5" />
                </div>
              ) : (
                <>
                  {search.length > 0 && options.length === 0 && (
                    <p className="text-xs text-center text-foreground-lighter py-3">
                      No {name}s found based on your search
                    </p>
                  )}
                  <ScrollArea className={options.length > 7 ? 'h-[210px]' : ''}>
                    {options.map((option) => (
                      <CommandItem
                        key={option.id}
                        value={option.value}
                        onSelect={(selectedValue: string) => {
                          setOpen(false)
                          onSelectOption(selectedValue)
                        }}
                        className="cursor-pointer"
                      >
                        <Check
                          className={cn(
                            'mr-2 h-4 w-4',
                            selectedOption === option.value ? 'opacity-100' : 'opacity-0'
                          )}
                        />
                        {option.displayName}
                      </CommandItem>
                    ))}
                    <div ref={sentinelRef} className="h-1 -mt-1" />
                    {hasNextPage && <ShimmeringLoader className="px-2 py-3" />}
                  </ScrollArea>
                </>
              )}
            </CommandGroup>
          </CommandList>
        </Command>
      </PopoverContent>
    </Popover>
  )
}

Subdomains

Frequently Asked Questions

What does ComboBox() do?
ComboBox() is a function in the supabase codebase.
What does ComboBox() call?
ComboBox() calls 1 function(s): useIntersectionObserver.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free