🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Update Funnel components and InputWithSuggestions for improved user experience
Bill Yangecda0a30359e
diff --git a/client/package-lock.json b/client/package-lock.jsonindex 0e5620bcd..9c3982ec9 100644--- a/client/package-lock.json+++ b/client/package-lock.json@@ -90,6 +90,7 @@"@types/mapbox-gl": "^3.4.1","@types/node": "^20.14.8","@types/react": "19.2.7",+ "@types/react-dom": "^19.2.3","@types/react-syntax-highlighter": "^15.5.13","eslint": "^9.39.1","eslint-config-next": "^16.0.7",@@ -5849,6 +5850,16 @@"csstype": "^3.2.2"}},+ "node_modules/@types/react-dom": {+ "version": "19.2.3",+ "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz",+ "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==",+ "devOptional": true,+ "license": "MIT",+ "peerDependencies": {+ "@types/react": "^19.2.0"+ }+ },"node_modules/@types/react-reconciler": {"version": "0.28.9","resolved": "https://registry.npmjs.org/@types/react-reconciler/-/react-reconciler-0.28.9.tgz",diff --git a/client/package.json b/client/package.jsonindex a03c6f4f7..2f0210f71 100644--- a/client/package.json+++ b/client/package.json@@ -94,6 +94,7 @@"@types/mapbox-gl": "^3.4.1","@types/node": "^20.14.8","@types/react": "19.2.7",+ "@types/react-dom": "^19.2.3","@types/react-syntax-highlighter": "^15.5.13","eslint": "^9.39.1","eslint-config-next": "^16.0.7",diff --git a/client/src/app/[site]/funnels/components/Funnel.tsx b/client/src/app/[site]/funnels/components/Funnel.tsxindex 39bb94dfc..55642ed89 100644--- a/client/src/app/[site]/funnels/components/Funnel.tsx+++ b/client/src/app/[site]/funnels/components/Funnel.tsx@@ -243,7 +243,7 @@ export function Funnel({ data, steps, isError, error, isPending }: FunnelProps)) : (<div className="h-[400px] flex items-center justify-center"><div className="text-neutral-500 dark:text-neutral-400 text-sm">- {isPending ? "Analyzing funnel..." : "Configure your funnel steps and click 'Analyze Funnel'"}+ {isPending ? "Analyzing funnel..." : "Configure your funnel steps"}</div></div>)}diff --git a/client/src/app/[site]/funnels/components/FunnelForm.tsx b/client/src/app/[site]/funnels/components/FunnelForm.tsxindex 5a66e6291..e530d53c6 100644--- a/client/src/app/[site]/funnels/components/FunnelForm.tsx+++ b/client/src/app/[site]/funnels/components/FunnelForm.tsx@@ -209,12 +209,10 @@ export function FunnelForm({if (steps.some(step => !step.value)) {funnelArea = (- <div className="flex items-center justify-center bg-neutral-50 dark:bg-neutral-900 rounded-lg h-full">+ <div className="flex items-center justify-center rounded-lg h-full"><div className="text-center p-6"><div className="text-lg font-medium mb-2">Funnel Preview</div>- <p className="text-sm text-neutral-500">- Configure your funnel steps and click "Query Funnel" to preview results- </p>+ <p className="text-sm text-neutral-500">Configure your funnel steps</p></div></div>);@@ -222,7 +220,7 @@ export function FunnelForm({if (isPending) {funnelArea = (- <div className="flex items-center justify-center bg-neutral-50 dark:bg-neutral-900 rounded-lg h-full">+ <div className="flex items-center justify-center rounded-lg h-full"><ThreeDotLoader /></div>);diff --git a/client/src/components/Loaders.tsx b/client/src/components/Loaders.tsxindex 1de8bcff2..cb3580b86 100644--- a/client/src/components/Loaders.tsx+++ b/client/src/components/Loaders.tsx@@ -2,7 +2,7 @@ import { cn } from "../lib/utils";export function ThreeDotLoader({ className }: { className?: string }) {return (- <div className={cn("flex justify-center items-center h-[500px]", className)}>+ <div className={cn("flex justify-center items-center", className)}><div className="animate-pulse flex items-center"><div className="h-2 w-2 bg-neutral-600 dark:bg-neutral-500 rounded-full mr-1 animate-bounce"></div><div className="h-2 w-2 bg-neutral-600 dark:bg-neutral-500 rounded-full mr-1 animate-bounce [animation-delay:0.2s]"></div>diff --git a/client/src/components/ui/input-with-suggestions.tsx b/client/src/components/ui/input-with-suggestions.tsxindex f6b52f445..42efddf96 100644--- a/client/src/components/ui/input-with-suggestions.tsx+++ b/client/src/components/ui/input-with-suggestions.tsx@@ -2,6 +2,7 @@import { Input } from "@/components/ui/input";import * as React from "react";+import { createPortal } from "react-dom";export interface SuggestionOption {value: string;@@ -18,6 +19,23 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWithconst [open, setOpen] = React.useState(false);const [internalValue, setInternalValue] = React.useState("");const wrapperRef = React.useRef<HTMLDivElement>(null);+ const inputRef = React.useRef<HTMLInputElement>(null);+ const dropdownRef = React.useRef<HTMLDivElement>(null);+ const [portalContainer, setPortalContainer] = React.useState<HTMLElement | null>(null);+ const [dropdownStyle, setDropdownStyle] = React.useState<{+ top: number;+ left: number;+ width: number;+ } | null>(null);++ // Find the best container to portal into (dialog content or body)+ React.useEffect(() => {+ if (wrapperRef.current) {+ // Look for a Radix dialog content container+ const dialogContent = wrapperRef.current.closest("[role='dialog']");+ setPortalContainer((dialogContent as HTMLElement) || document.body);+ }+ }, []);// Use controlled value if provided, otherwise use internal stateconst value = controlledValue !== undefined ? controlledValue : internalValue;@@ -26,9 +44,27 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWithsuggestion.value.toLowerCase().includes(String(value).toLowerCase()));+ const updateDropdownPosition = React.useCallback(() => {+ if (inputRef.current && portalContainer) {+ const inputRect = inputRef.current.getBoundingClientRect();+ const containerRect = portalContainer.getBoundingClientRect();++ // Calculate position relative to the portal container+ setDropdownStyle({+ top: inputRect.bottom - containerRect.top + 4,+ left: inputRect.left - containerRect.left,+ width: inputRect.width,+ });+ }+ }, [portalContainer]);+React.useEffect(() => {const handleClickOutside = (event: MouseEvent) => {- if (wrapperRef.current && !wrapperRef.current.contains(event.target as Node)) {+ const target = event.target as Node;+ const clickedInWrapper = wrapperRef.current?.contains(target);+ const clickedInDropdown = dropdownRef.current?.contains(target);++ if (!clickedInWrapper && !clickedInDropdown) {setOpen(false);}};@@ -37,6 +73,18 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWithreturn () => document.removeEventListener("mousedown", handleClickOutside);}, []);+ React.useEffect(() => {+ if (open) {+ updateDropdownPosition();+ window.addEventListener("scroll", updateDropdownPosition, true);+ window.addEventListener("resize", updateDropdownPosition);+ return () => {+ window.removeEventListener("scroll", updateDropdownPosition, true);+ window.removeEventListener("resize", updateDropdownPosition);+ };+ }+ }, [open, updateDropdownPosition]);+const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {const newValue = e.target.value;if (controlledValue === undefined) {@@ -64,7 +112,14 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWithreturn (<div ref={wrapperRef} className="relative"><Input- ref={ref}+ ref={(node) => {+ inputRef.current = node;+ if (typeof ref === "function") {+ ref(node);+ } else if (ref) {+ ref.current = node;+ }+ }}value={value}onChange={handleInputChange}onFocus={() => setOpen(true)}@@ -72,19 +127,33 @@ export const InputWithSuggestions = React.forwardRef<HTMLInputElement, InputWithclassName={className}{...props}/>- {open && filteredSuggestions.length > 0 && (- <div className="absolute z-50 mt-1 w-full max-h-60 overflow-auto rounded-md border border-neutral-150 bg-white shadow-md dark:border-neutral-800 dark:bg-neutral-900">- {filteredSuggestions.map(suggestion => (- <div- key={suggestion.value}- className="relative cursor-pointer px-3 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-800"- onClick={() => handleSuggestionClick(suggestion.value)}- >- {suggestion.label || suggestion.value}- </div>- ))}- </div>- )}+ {open &&+ filteredSuggestions.length > 0 &&+ dropdownStyle &&+ portalContainer &&+ createPortal(+ <div+ ref={dropdownRef}+ className="absolute z-[100] max-h-60 overflow-auto rounded-md border border-neutral-150 bg-white shadow-md dark:border-neutral-800 dark:bg-neutral-900"+ style={{+ top: dropdownStyle.top,+ left: dropdownStyle.left,+ width: dropdownStyle.width,+ }}+ >+ {filteredSuggestions.map((suggestion) => (+ <div+ key={suggestion.value}+ className="relative cursor-pointer px-3 py-2 text-sm hover:bg-neutral-100 dark:hover:bg-neutral-800"+ onMouseDown={(e) => e.preventDefault()}+ onClick={() => handleSuggestionClick(suggestion.value)}+ >+ {suggestion.label || suggestion.value}+ </div>+ ))}+ </div>,+ portalContainer+ )}</div>);}