The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Remove nested buttons from table selection checkboxes
Rafi2cdd0105eef4
diff --git a/packages/ui/src/table/selection-toolbar.tsx b/packages/ui/src/table/selection-toolbar.tsxindex 1a05505142..61d2cdbd57 100644--- a/packages/ui/src/table/selection-toolbar.tsx+++ b/packages/ui/src/table/selection-toolbar.tsx@@ -1,6 +1,6 @@import { cn } from "@dub/utils";import { Table } from "@tanstack/react-table";-import { ReactNode, useEffect, useState } from "react";+import { MouseEvent, ReactNode, useEffect, useState } from "react";import { Checkbox } from "../checkbox";import { useKeyboardShortcut } from "../hooks";@@ -26,6 +26,11 @@ export function SelectionToolbar<T>({modal: false,});+ const onSelectAll = (e: MouseEvent<HTMLElement>) => {+ e.stopPropagation();+ table.toggleAllRowsSelected();+ };+return (<divclassName={cn(@@ -40,17 +45,13 @@ export function SelectionToolbar<T>({><div className="flex h-11 items-center py-2.5 pr-2"><div className="relative flex h-full w-12 shrink-0 items-center justify-center">- <button- type="button"- className="absolute inset-0 flex items-center justify-center"- onClick={(e) => {- e.stopPropagation();- table.toggleAllRowsSelected();- }}+ <div+ className="absolute inset-0 flex cursor-pointer items-center justify-center"+ onClick={onSelectAll}title="Select all"><Checkbox- className="border-border-default pointer-events-none size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"+ className="border-border-default size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"checked={table.getIsAllRowsSelected()? true@@ -58,8 +59,10 @@ export function SelectionToolbar<T>({? "indeterminate": false}+ onClick={onSelectAll}+ aria-label="Select all"/>- </button>+ </div></div><div className="flex min-w-0 items-center gap-2.5 pl-1"><spandiff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsxindex 8e91b29238..5fe7213efe 100644--- a/packages/ui/src/table/table.tsx+++ b/packages/ui/src/table/table.tsx@@ -154,30 +154,37 @@ export function useTable<T extends any>(minSize: SELECT_COLUMN_WIDTH,size: SELECT_COLUMN_WIDTH,maxSize: SELECT_COLUMN_WIDTH,- header: ({ table }: { table: TableType<T> }) => (- <button- type="button"- className="flex size-full items-center justify-center"- onClick={(e) => {- e.stopPropagation();- table.toggleAllRowsSelected();- }}- title="Select all"- >- <Checkbox- className="border-border-default pointer-events-none size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"- checked={- table.getIsAllRowsSelected()- ? true- : table.getIsSomeRowsSelected()- ? "indeterminate"- : false- }- />- </button>- ),+ header: ({ table }: { table: TableType<T> }) => {+ const onSelectAll = (e: MouseEvent<HTMLElement>) => {+ e.stopPropagation();+ table.toggleAllRowsSelected();+ };++ // The checkbox is the control, the wrapper only widens the+ // click area (a <button> wrapper would nest two buttons)+ return (+ <div+ className="flex size-full cursor-pointer items-center justify-center"+ onClick={onSelectAll}+ title="Select all"+ >+ <Checkbox+ className="border-border-default size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"+ checked={+ table.getIsAllRowsSelected()+ ? true+ : table.getIsSomeRowsSelected()+ ? "indeterminate"+ : false+ }+ onClick={onSelectAll}+ aria-label="Select all"+ />+ </div>+ );+ },cell: ({ row, table }: { row: Row<T>; table: TableType<T> }) => {- const onSelectRow = (e: MouseEvent<HTMLButtonElement>) => {+ const onSelectRow = (e: MouseEvent<HTMLElement>) => {e.stopPropagation();const currentId = getRowId?.(row.original);const rows = table.getRowModel().rows;@@ -239,17 +246,18 @@ export function useTable<T extends any>(};return (- <button- type="button"- className="flex size-full items-center justify-center"+ <div+ className="flex size-full cursor-pointer items-center justify-center"onClick={onSelectRow}title="Select"><Checkbox- className="border-border-default pointer-events-none size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"+ className="border-border-default size-4 rounded data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"checked={row.getIsSelected()}+ onClick={onSelectRow}+ aria-label="Select"/>- </button>+ </div>);},},