Skip to content

Commit 796e0d3

Browse files
committed
Set the tab index of a cell and style the table row when tabbed
1 parent 8ad7443 commit 796e0d3

File tree

1 file changed

+14
-4
lines changed
  • apps/webapp/app/components/primitives

1 file changed

+14
-4
lines changed

apps/webapp/app/components/primitives/Table.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ export const TableRow = forwardRef<HTMLTableRowElement, TableRowProps>(
8080
return (
8181
<tr
8282
ref={ref}
83-
tabIndex={disabled ? -1 : 0}
8483
className={cn(
85-
"group/table-row relative w-full cursor-pointer outline-none after:absolute after:bottom-0 after:left-3 after:right-0 after:h-px after:bg-grid-dimmed focus-visible:bg-background-bright",
84+
"group/table-row relative w-full cursor-pointer outline-none after:absolute after:bottom-0 after:left-3 after:right-0 after:h-px after:bg-grid-dimmed",
85+
"has-[[tabindex='0']:focus]:bg-background-bright",
8686
disabled && "opacity-50",
8787
isSelected && isSelectedStyle,
8888
className
@@ -153,6 +153,7 @@ type TableCellProps = TableCellBasicProps & {
153153
actionClassName?: string;
154154
rowHoverStyle?: keyof typeof rowHoverStyles;
155155
isSelected?: boolean;
156+
isTabbableCell?: boolean;
156157
};
157158

158159
const rowHoverStyles = {
@@ -183,6 +184,7 @@ export const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
183184
isSticky = false,
184185
rowHoverStyle = "default",
185186
isSelected,
187+
isTabbableCell = false,
186188
},
187189
ref
188190
) => {
@@ -220,11 +222,19 @@ export const TableCell = forwardRef<HTMLTableCellElement, TableCellProps>(
220222
colSpan={colSpan}
221223
>
222224
{to ? (
223-
<Link to={to} className={cn("focus-custom", flexClasses, actionClassName)}>
225+
<Link
226+
to={to}
227+
className={cn("focus:outline-none", flexClasses, actionClassName)}
228+
tabIndex={isTabbableCell ? 0 : -1}
229+
>
224230
{children}
225231
</Link>
226232
) : onClick ? (
227-
<button onClick={onClick} className={cn("focus-custom", flexClasses, actionClassName)}>
233+
<button
234+
onClick={onClick}
235+
className={cn("focus:outline-none", flexClasses, actionClassName)}
236+
tabIndex={isTabbableCell ? 0 : -1}
237+
>
228238
{children}
229239
</button>
230240
) : (

0 commit comments

Comments
 (0)