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.

fixed InlineBadgePopoverMenu

Steven Tey88c483e15ca5
diff --git a/apps/web/ui/partners/rewards/inline-badge-popover.tsx b/apps/web/ui/partners/rewards/inline-badge-popover.tsx
index f61d31c56c..9ea3350cb6 100644
--- a/apps/web/ui/partners/rewards/inline-badge-popover.tsx
+++ b/apps/web/ui/partners/rewards/inline-badge-popover.tsx
@@ -36,7 +36,12 @@ export function InlineBadgePopover({
text,
invalid,
children,
-}: PropsWithChildren<{ text: ReactNode; invalid?: boolean }>) {
+ buttonClassName,
+}: PropsWithChildren<{
+ text: ReactNode;
+ invalid?: boolean;
+ buttonClassName?: string;
+}>) {
const [isOpen, setIsOpen] = useState(false);
return (
@@ -63,6 +68,7 @@ export function InlineBadgePopover({
invalid
? "bg-orange-50 text-orange-500 hover:bg-orange-100 data-[state=open]:bg-orange-100"
: "bg-blue-50 text-blue-700 hover:bg-blue-100 data-[state=open]:bg-blue-100",
+ buttonClassName,
)}
>
{text}
@@ -91,17 +97,13 @@ export function InlineBadgePopoverMenu<T extends any>({
}) {
const isMultiSelect = Array.isArray(selectedValue);
- const { isOpen, setIsOpen } = useContext(InlineBadgePopoverContext);
-
const scrollRef = useRef<HTMLDivElement>(null);
const { scrollProgress, updateScrollProgress } = useScrollProgress(scrollRef);
const [sortedItems, setSortedItems] = useState<MenuItem<T>[]>(items);
- // Sort items so that the selected values are always at the top, but only when the popover is closed
+ // Sort items so that the selected values are always at the top
useEffect(() => {
- if (isOpen) return;
-
setSortedItems(
items.sort((a, b) => {
const aSelected = isMultiSelect
@@ -114,11 +116,11 @@ export function InlineBadgePopoverMenu<T extends any>({
// First sort by whether the items are selected
if (aSelected !== bSelected) return aSelected ? -1 : 1;
- // Then sort alphabetically
- return a.text.localeCompare(b.text);
+ // Then sort as per the original order of the items
+ return items.indexOf(a) - items.indexOf(b);
}),
);
- }, [isOpen, items, isMultiSelect, selectedValue]);
+ }, [items, isMultiSelect, selectedValue]);
return (
<Command loop className="focus:outline-none">
@@ -145,7 +147,6 @@ export function InlineBadgePopoverMenu<T extends any>({
onSelect={() => {
itemOnSelect?.();
onSelect?.(value);
- !isMultiSelect && setIsOpen(false);
}}
className="flex cursor-pointer items-center justify-between rounded-md px-1.5 py-1 transition-colors duration-150 data-[selected=true]:bg-neutral-100"
>