Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix combobox empty state

Tim Wilson3ae0cddcdd29
diff --git a/apps/web/ui/modals/link-builder/webhook-select.tsx b/apps/web/ui/modals/link-builder/webhook-select.tsx
index d0d0a2b177..0e07ea0332 100644
--- a/apps/web/ui/modals/link-builder/webhook-select.tsx
+++ b/apps/web/ui/modals/link-builder/webhook-select.tsx
@@ -83,13 +83,13 @@ const NoWebhooksFound = () => {
const { slug } = useWorkspace();
return (
- <div className="flex h-full flex-col items-center justify-center gap-2 p-2 text-center text-sm">
+ <div className="flex h-full flex-col items-center justify-center gap-2 px-2 py-4 text-center text-sm">
<div className="flex items-center justify-center rounded-2xl border border-gray-200 bg-gray-50 p-3">
<Globe className="size-6 text-gray-700" />
</div>
<p className="mt-2 font-medium text-gray-950">No webhooks found</p>
<p className="mx-auto mt-1 w-full max-w-[180px] text-gray-700">
- Add a webhook to receive click event when someone clicks your link.
+ Add a webhook to receive a click event when someone clicks your link.
</p>
<div>
<Button
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index dac4ab2a92..86adf760c7 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -1,7 +1,9 @@
import { cn } from "@dub/utils";
-import { Command, CommandEmpty, CommandInput, CommandItem } from "cmdk";
+import { Command, CommandInput, CommandItem, useCommandState } from "cmdk";
import { ChevronDown } from "lucide-react";
import {
+ forwardRef,
+ HTMLProps,
isValidElement,
PropsWithChildren,
ReactNode,
@@ -257,11 +259,11 @@ export function Combobox({
</CommandItem>
)}
{shouldFilter ? (
- <CommandEmpty className="flex h-12 items-center justify-center text-sm text-gray-500">
+ <Empty className="flex min-h-12 items-center justify-center text-sm text-gray-500">
{emptyState ? emptyState : "No matches"}
- </CommandEmpty>
+ </Empty>
) : sortedOptions.length === 0 ? (
- <div className="flex h-12 items-center justify-center text-sm text-gray-500">
+ <div className="flex min-h-12 items-center justify-center text-sm text-gray-500">
{emptyState ? emptyState : "No matches"}
</div>
) : null}
@@ -324,7 +326,7 @@ const Scroll = ({ children }: PropsWithChildren) => {
return (
<>
<div
- className="scrollbar-hide max-h-[min(50vh,240px)] w-screen overflow-y-scroll sm:w-auto"
+ className="scrollbar-hide max-h-[min(50vh,250px)] w-screen overflow-y-scroll sm:w-auto"
ref={ref}
onScroll={updateScrollProgress}
>
@@ -392,3 +394,15 @@ function Option({
const isReactNode = (element: any): element is ReactNode =>
isValidElement(element);
+
+// Custom Empty component because our current cmdk version has an issue with first render (https://github.com/pacocoursey/cmdk/issues/149)
+const Empty = forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(
+ (props, forwardedRef) => {
+ const render = useCommandState((state) => state.filtered.count === 0);
+
+ if (!render) return null;
+ return (
+ <div ref={forwardedRef} cmdk-empty="" role="presentation" {...props} />
+ );
+ },
+);