fix(dashboard): Add safe zone around link Table rows (#8058)

**What**
- After adding Table rows as links there was an issue where clicking close to a Checkbox in a row would click the link. This PR adds a safe zone around the Checkboxes, so you don't end up navigating when trying to select a row.

![image](https://github.com/medusajs/medusa/assets/45367945/7091d6d5-665d-41c7-8b2b-63244fef73b2)

RESOLVES CORE-2566
This commit is contained in:
Kasper Fabricius Kristensen
2024-07-10 10:34:11 +00:00
committed by GitHub
parent 046a34bdfc
commit 04ec8e758f
@@ -140,7 +140,7 @@ export const DataTableRoot = <TData,>({
<Table.Row <Table.Row
key={headerGroup.id} key={headerGroup.id}
className={clx({ className={clx({
"border-b-0 [&_th:last-of-type]:w-[1%] [&_th:last-of-type]:whitespace-nowrap": "relative border-b-0 [&_th:last-of-type]:w-[1%] [&_th:last-of-type]:whitespace-nowrap":
hasActions, hasActions,
"[&_th:first-of-type]:w-[1%] [&_th:first-of-type]:whitespace-nowrap": "[&_th:first-of-type]:w-[1%] [&_th:first-of-type]:whitespace-nowrap":
hasSelect, hasSelect,
@@ -171,7 +171,7 @@ export const DataTableRoot = <TData,>({
: undefined, : undefined,
}} }}
className={clx({ className={clx({
"bg-ui-bg-base sticky left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']": "bg-ui-bg-base sticky inset-y-0 left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']":
isStickyHeader, isStickyHeader,
"left-[68px]": "left-[68px]":
isStickyHeader && hasSelect && !isSelectHeader, isStickyHeader && hasSelect && !isSelectHeader,
@@ -206,7 +206,7 @@ export const DataTableRoot = <TData,>({
key={row.id} key={row.id}
data-selected={row.getIsSelected()} data-selected={row.getIsSelected()}
className={clx( className={clx(
"transition-fg group/row [&_td:last-of-type]:w-[1%] [&_td:last-of-type]:whitespace-nowrap", "transition-fg group/row group relative [&_td:last-of-type]:w-[1%] [&_td:last-of-type]:whitespace-nowrap",
"has-[[data-row-link]:focus-visible]:bg-ui-bg-base-hover", "has-[[data-row-link]:focus-visible]:bg-ui-bg-base-hover",
{ {
"bg-ui-bg-subtle hover:bg-ui-bg-subtle-hover": isOdd, "bg-ui-bg-subtle hover:bg-ui-bg-subtle-hover": isOdd,
@@ -241,23 +241,27 @@ export const DataTableRoot = <TData,>({
? row.depth * 14 + 24 ? row.depth * 14 + 24
: undefined : undefined
const hasLeftOfsset =
isStickyCell && hasSelect && !isSelectCell
const Inner = flexRender( const Inner = flexRender(
cell.column.columnDef.cell, cell.column.columnDef.cell,
cell.getContext() cell.getContext()
) )
const isTabableLink = index === 0 && !!to const isTabableLink = isFirstCell && !!to
const shouldRenderAsLink = !!to && !isSelectCell
return ( return (
<Table.Cell <Table.Cell
key={cell.id} key={cell.id}
className={clx({ className={clx({
"bg-ui-bg-base group-data-[selected=true]/row:bg-ui-bg-highlight group-data-[selected=true]/row:group-hover/row:bg-ui-bg-highlight-hover group-hover/row:bg-ui-bg-base-hover transition-fg has-[[data-row-link]:focus-visible]:bg-ui-bg-base-hover sticky left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']": "!pl-0 !pr-0": shouldRenderAsLink,
"bg-ui-bg-base group-data-[selected=true]/row:bg-ui-bg-highlight group-data-[selected=true]/row:group-hover/row:bg-ui-bg-highlight-hover group-hover/row:bg-ui-bg-base-hover transition-fg group-has-[[data-row-link]:focus-visible]:bg-ui-bg-base-hover sticky inset-y-0 left-0 after:absolute after:inset-y-0 after:right-0 after:h-full after:w-px after:bg-transparent after:content-['']":
isStickyCell, isStickyCell,
"bg-ui-bg-subtle group-hover/row:bg-ui-bg-subtle-hover": "bg-ui-bg-subtle group-hover/row:bg-ui-bg-subtle-hover":
isOdd && isStickyCell, isOdd && isStickyCell,
"left-[68px]": "bottom-0 left-[68px] top-0": hasLeftOfsset,
isStickyCell && hasSelect && !isSelectCell,
"after:bg-ui-border-base": "after:bg-ui-border-base":
showStickyBorder && isStickyCell && !isSelectCell, showStickyBorder && isStickyCell && !isSelectCell,
"!bg-ui-bg-disabled !hover:bg-ui-bg-disabled": "!bg-ui-bg-disabled !hover:bg-ui-bg-disabled":
@@ -269,14 +273,23 @@ export const DataTableRoot = <TData,>({
: undefined, : undefined,
}} }}
> >
{to ? ( {shouldRenderAsLink ? (
<Link <Link
to={to} to={to}
className="outline-none" className="size-full outline-none"
data-row-link data-row-link
tabIndex={isTabableLink ? 0 : -1} tabIndex={isTabableLink ? 0 : -1}
> >
{Inner} <div
className={clx(
"flex size-full items-center pr-6",
{
"pl-6": isTabableLink && !hasLeftOfsset,
}
)}
>
{Inner}
</div>
</Link> </Link>
) : ( ) : (
Inner Inner