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.

Safari select fix.

Marcus Farrell81aedad2aacc
diff --git a/packages/ui/src/table/selection-toolbar.tsx b/packages/ui/src/table/selection-toolbar.tsx
index 80b3db043b..a963f115f6 100644
--- a/packages/ui/src/table/selection-toolbar.tsx
+++ b/packages/ui/src/table/selection-toolbar.tsx
@@ -2,13 +2,17 @@ import { cn } from "@dub/utils";
import { Table } from "@tanstack/react-table";
import { ReactNode, useEffect, useState } from "react";
import { useKeyboardShortcut } from "../hooks";
+import { Checkbox } from "../checkbox";
+import { AnimatePresence, motion } from "framer-motion";
export function SelectionToolbar<T>({
table,
controls,
+ className,
}: {
table: Table<T>;
controls?: (table: Table<T>) => ReactNode;
+ className?: string;
}) {
const selectedCount = table.getSelectedRowModel().rows.length;
const [lastSelectedCount, setLastSelectedCount] = useState(0);
@@ -23,33 +27,66 @@ export function SelectionToolbar<T>({
modal: false,
});
+ // Animation variants for count and actions
+ const rowVariants = {
+ visible: {
+ transition: { staggerChildren: 0.04, delayChildren: 0.02 },
+ },
+ hidden: {},
+ };
+ const itemVariants = {
+ hidden: { opacity: 0, x: -4 },
+ visible: { opacity: 1, x: 0 },
+ };
+
return (
- <tr
- className={cn("size-0")}
- {...{
- inert: table.getSelectedRowModel().rows.length ? undefined : "",
- }}
- >
- <td colSpan={table.getHeaderGroups().length} className="contents size-0">
- <div
+ <AnimatePresence>
+ {selectedCount > 0 && (
+ <motion.div
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ transition={{ duration: 0.12 }}
className={cn(
- "pointer-events-none absolute bottom-px left-11 right-0 top-0 bg-white opacity-0 duration-100",
- selectedCount && "pointer-events-auto opacity-100",
+ "pointer-events-auto absolute z-10 left-0 right-0 top-0 min-h-[40px] border-b border-border-subtle bg-white",
+ className
)}
+ style={{ boxSizing: "border-box" }}
>
- <div
- className={cn(
- "flex size-full -translate-x-1 items-center gap-2 transition-transform duration-100",
- selectedCount && "translate-x-0",
- )}
- >
- <span className="text-content-emphasis mr-2 text-sm font-medium tabular-nums">
+ <div className="flex items-center gap-2.5 px-3.5 py-2 min-h-[40px]">
+ <Checkbox
+ className="border-border-default size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black mr-2"
+ checked={
+ table.getIsAllRowsSelected()
+ ? true
+ : table.getIsSomeRowsSelected()
+ ? "indeterminate"
+ : false
+ }
+ onCheckedChange={() => table.toggleAllRowsSelected()}
+ title="Select all"
+ />
+ <motion.span
+ variants={itemVariants}
+ initial="hidden"
+ animate="visible"
+ exit="hidden"
+ className="text-content-emphasis text-sm font-medium tabular-nums mr-2"
+ >
{lastSelectedCount} selected
- </span>
- {controls?.(table)}
+ </motion.span>
+ <motion.div
+ variants={itemVariants}
+ initial="hidden"
+ animate="visible"
+ exit="hidden"
+ className="flex items-center gap-2"
+ >
+ {controls?.(table)}
+ </motion.div>
</div>
- </div>
- </td>
- </tr>
+ </motion.div>
+ )}
+ </AnimatePresence>
);
}
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index b2658d926f..87e0bea320 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -325,6 +325,14 @@ export function Table<T>({
scrollWrapperClassName,
)}
>
+ {/* Selection Toolbar Overlay */}
+ {selectionEnabled && (
+ <SelectionToolbar
+ table={table}
+ controls={selectionControls}
+ className="top-0 left-0 right-0"
+ />
+ )}
<table
className={cn(
[
@@ -425,9 +433,7 @@ export function Table<T>({
})}
</tr>
))}
- {selectionEnabled && (
- <SelectionToolbar table={table} controls={selectionControls} />
- )}
+ {/* SelectionToolbar row removed from here */}
</thead>
<tbody>
{table.getRowModel().rows.map((row) => {