-
Notifications
You must be signed in to change notification settings - Fork 889
fix: Wrap TableCell with Link for native browser routing #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Link from "@material-ui/core/Link" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import TableCell, { TableCellProps } from "@material-ui/core/TableCell" | ||
import { Link as RouterLink } from "react-router-dom" | ||
import { combineClasses } from "../../util/combineClasses" | ||
|
||
// TableCellLink wraps a TableCell filling the entirety with a Link. | ||
// This allows table rows to be clickable with browser-behavior like ctrl+click. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
export const TableCellLink: React.FC< | ||
TableCellProps & { | ||
to: string | ||
} | ||
> = (props) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<TableCell className={styles.cell} {...props}> | ||
<Link | ||
component={RouterLink} | ||
to={props.to} | ||
className={combineClasses([styles.link, "MuiTableCell-root", "MuiTableCell-body"])} | ||
> | ||
{props.children} | ||
</Link> | ||
</TableCell> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
cell: { | ||
// This must override all padding for all rules on a TableCell. | ||
// Otherwise, the link will not cover the entire region. | ||
// It's unfortuante to use `!important`, but this seems to be | ||
// a reasonable use-case. | ||
padding: "0 !important", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately the MUI styles will override, and that can't work for the padding (because this needs to fill the entire cell). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. I wonder if we could use specificity in class naming to get around this. Not a blocker for this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I shall try! |
||
}, | ||
link: { | ||
display: "block", | ||
width: "100%", | ||
border: "none", | ||
background: "none", | ||
paddingTop: theme.spacing(2), | ||
paddingBottom: theme.spacing(2), | ||
// This is required to hide all underlines for child elements! | ||
textDecoration: "none !important", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get more specific with a selector? |
||
}, | ||
})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?: why are we removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointer still exists, it's just provided by the "a" tag now!