Skip to content
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

DOP-5342: ListTable consolidates cell content inside of divs #1346

Merged
merged 5 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/components/ListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const baseCellStyle = css`
* {
// Wrap in selector to ensure it cascades down to every element
font-size: ${theme.fontSize.small} !important;
line-height: inherit;
}

// Ensure each cell is no higher than the highest content in row
Expand All @@ -78,23 +77,25 @@ const bodyCellStyle = css`
flex-direction: column;
align-items: flex-start;
}
`;

const bodyCellContentStyle = css`
*,
p,
a {
line-height: 20px;
}

// Target any nested components (paragraphs, admonitions, tables) and any paragraphs within those nested components
& > div > *,
& > div > div p {
margin: 0 0 12px;
& > *,
& > div p {
margin: 0 0 12px !important;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayangler is there any way we can use another approach other than!important? if not, then it is what it is. !important is normally considered to be bad practice, and can make maintaining difficult down the road.

Copy link
Collaborator Author

@rayangler rayangler Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not a fan of !important either. Honestly, I don't really understand it but when I was trying to work on it on local development, it was working fine without !important, but when statically built, the order of CSS was different, causing the styling of these components to be different as well. I couldn't think of or find a more straightforward way to handle it.

I can timebox 30-60 minutes at some point to look into this more to see if there are other options that don't require writing some roundabout CSS/JS logic. Would that work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayangler that would be perfect, but please don't spend anything more than what you mentioned above. I don't think it is worth eating up too much of your time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time looking into it but couldn't find a full fix for it that kept changes minimal. I've tried upgrading a couple of dependencies @leafygreen-ui/emotion and gatsby-plugin-emotion, and modifying the selectors to be a little bit more specific (this worked for some elements but not for others, and it might require an exhaustive list of HTML since tables can have any elements in them).

Some things I didn't try that might be interesting in the future would be:

  • Pass some table-cell-content classname down to all cell child components and then use those classnames as the selectors? (Unsure how well this would work with deeply nested components; we might have to make sure every component is passing that exact classname every time)
  • We have a context that can keep track if a component is inside of a table or not. Maybe we can leverage that and write some conditional css at the component level to handle the styling accordingly (this may be annoying to have to add to every possible nested component though...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayangler thank you for looking into this a bit more. Those are some interesting approaches, and like you said, something we can look into in the possible future.

}

// Prevent extra margin below last element (such as when multiple paragraphs are present)
& > div > div *:last-child,
& > div > *:last-child {
margin-bottom: 0;
& > div *:last-child,
& > *:last-child {
margin-bottom: 0 !important;
}
`;

Expand Down Expand Up @@ -308,7 +309,8 @@ const ListTable = ({ nodeData: { children, options }, ...rest }) => {
{headerGroup.headers.map((header) => {
return (
<HeaderCell className={cx(baseCellStyle, headerCellStyle)} key={header.id} header={header}>
{flexRender(header.column.columnDef.header, header.getContext())}
{/* Wraps cell content inside of a div so that all of its content are together when laid out. */}
<div>{flexRender(header.column.columnDef.header, header.getContext())}</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only request: Maybe we leave a comment here and below to explain why the div is there so no one removes it one day.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout. This sounds like a div I'd accidentally remove

</HeaderCell>
);
})}
Expand All @@ -323,7 +325,8 @@ const ListTable = ({ nodeData: { children, options }, ...rest }) => {
const role = isStub ? 'rowheader' : null;
return (
<Cell key={cell.id} className={cx(baseCellStyle, bodyCellStyle, isStub && stubCellStyle)} role={role}>
{cell.renderValue()}
{/* Wraps cell content inside of a div so that all of its content are together when laid out. */}
<div className={cx(bodyCellContentStyle)}>{cell.renderValue()}</div>
</Cell>
);
})}
Expand Down
Loading