-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Fix alignment when viewing a DataView with table layout and non-default column alignment #73398
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
Fix alignment when viewing a DataView with table layout and non-default column alignment #73398
Conversation
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @xristos3490! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I tested this a bit and this is what I found:
|
| return ( | ||
| <th | ||
| key={ column } | ||
| className={ clsx( { |
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.
This works. It's so similar to #73385 where @jameskoster suggested a different approach (introduce an unstyled button variant, so that the container would control the spacing of buttons), that I'd rather ask what your thoughts are on this, James.
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.
I don't think it would hurt to merge something like this in the short-term. But yes, this button is already applying custom styles which suggests an unstyled button variant would be useful.
| font-weight: $font-weight-medium; | ||
|
|
||
| &:has(.dataviews-view-table-header-button):not(:first-child) { | ||
| padding-left: $grid-unit-05; |
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.
If we just added padding-right: $grid-unit-05; here would that solve the issue without all the extra logic and CSS?
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.
Ah, I appreciate the clear thinking, @jameskoster! I tried this out, but it actually breaks the rules' specificity when handling the first and last child—such as when (a) the table has no primary column or checkboxes, and (b) there are no actions, causing a regular column to be placed to the last child.
This exploration also made me realize that the current approach won't work as expected in the aforementioned (b) case.
However, we could modify the header-specific rules to make this work without adding any extra classes. I took a stab at this here.
|
Thank you, @oandregal and @jameskoster, for the swift reviews! Following James's suggestion, I went with a more straightforward, CSS-based approach to fix this, which seems to cover all cases: Case A: No primary columns
Case B: No actions column
Can you please take another look? Thanks!
Nice catch, André! Happy to follow up on this! 🙇 |
…-header-alignment-styles
| &:has(.dataviews-view-table-header-button):first-child { | ||
| padding-left: $grid-unit-60; | ||
|
|
||
| .dataviews-view-table-header-button { | ||
| margin-left: - #{$grid-unit-10}; | ||
| } | ||
| } |
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.
Instead of a negative margin could it make sense to just set the left padding to $grid-unit-50? 🤔
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.
This is a spot-on suggestion, @jameskoster! I believe I carried over the negative margin from before, where we were setting the padding for both table cells and headers. Simplified the rules, and it works as expected in my testing. Also added a few comments to clarify; not sure about the comments policy, happy to remove them to keep it clean.
Done in eba86ee
While testing this, I realized the compact density needed a small fix too, which I added here: 128db12
See:
| Before | After |
|---|---|
![]() |
![]() |
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.
It's pretty hard to keep track of what some of these styles are for, so I think the comments are a great idea.
|
Thanks for the changes here @xristos3490 There's some conflicts with the changelog, so you need to rebase this PR. I'll be happy to merge it afterwards! |
…-header-alignment-styles
|
Rebased in 49e9b64, @oandregal! Thanks for the reviews, folks! 🙇 |
|
Congrats on your 1st PR merged, @xristos3490 You're welcome to send many more :) |
|
Congrats Chris - Onwards and upwards! |








What?
When applying a non-default alignment to a Dataview column in the table layout, the header element's spacing becomes misaligned with the rest of the data in that list.
Closes #73397
Why?
Alignment needs to be on point.
How?
This PR does the following:
dataviews-view-table__header-align-{end, center}textAlignstyle.Testing Instructions
Testing Instructions for Keyboard
npm run storybook:dev.layout.styles.[column].align = end(andcenter). The screenshots below have the following view configured:Screenshots or screencast
Align:end
Align:center