Skip to content

Commit

Permalink
Improved table cell links
Browse files Browse the repository at this point in the history
  • Loading branch information
calebjacob committed Nov 20, 2024
1 parent 6e5fa3e commit b8ac905
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-pagoda/ui",
"version": "2.1.0",
"version": "2.1.1",
"description": "A React component library that implements the official NEAR design system.",
"license": "MIT",
"repository": {
Expand Down
19 changes: 12 additions & 7 deletions src/components/Table/Table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
.row {
&:hover {
td {
background: var(--sand-3);
background: var(--sand-2);
}
}
}
Expand Down Expand Up @@ -140,6 +140,7 @@
vertical-align: middle;
transition: var(--transitions);
font: var(--text-s);
position: relative;

&:first-child {
border-top-left-radius: var(--table-border-radius);
Expand All @@ -157,7 +158,7 @@
outline: var(--table-default-outline);

&:hover {
background: var(--sand-4) !important;
background: var(--violet-3) !important;
}

&:focus-visible,
Expand All @@ -170,16 +171,20 @@
pointer-events: none;
opacity: 0.5;
}

&[data-link='true'] {
padding: 0;
}
}

.cellAnchor {
display: block;
display: flex;
align-items: center;
position: absolute;
inset: 0;
padding: var(--table-half-padding);
color: currentColor;
text-decoration: none;
outline: none;
}

.cellAnchorHiddenChildren {
opacity: 0;
pointer-events: none;
}
15 changes: 10 additions & 5 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ type CellProps = ComponentPropsWithRef<'td'> & {

export const Cell = forwardRef<HTMLTableCellElement, CellProps>(
({ children, disabled, href, spanAllColumns, target, ...props }, ref) => {
const clickable = !!props.onClick;
const clickable = !!props.onClick || !!href;
const isButton = !!props.onClick && !href;
const role = isButton ? 'button' : undefined;
const tabIndex = isButton ? (disabled ? -1 : 0) : undefined;
Expand All @@ -277,7 +277,6 @@ export const Cell = forwardRef<HTMLTableCellElement, CellProps>(
className={s.cell}
aria-disabled={disabled}
data-clickable={clickable}
data-link={!!href}
role={role}
tabIndex={tabIndex}
ref={ref}
Expand All @@ -286,9 +285,15 @@ export const Cell = forwardRef<HTMLTableCellElement, CellProps>(
onKeyDown={onKeyDown}
>
{href ? (
<Link href={href} className={s.cellAnchor} target={target}>
{children}
</Link>
<>
<Link href={href} className={s.cellAnchor} target={target}>
{children}
</Link>

<span className={s.cellAnchorHiddenChildren} aria-hidden="true">
{children}
</span>
</>
) : (
children
)}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Text.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ a.text {
&[data-parent-clickable='true'] {
[role='button']:hover &,
[role='button']:focus-visible &,
[data-clickable='true']:hover &,
[data-clickable='true']:focus-visible &,
button:hover &,
button:focus-visible &,
a:hover &,
Expand Down

0 comments on commit b8ac905

Please sign in to comment.