Skip to content

Conversation

@xristos3490
Copy link
Contributor

@xristos3490 xristos3490 commented Nov 18, 2025

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:

  • Adds two new class names to the header element: dataviews-view-table__header-align-{end, center}
  • Removes the inline textAlign style.
  • Introduces CSS to control the spacing and text alignment within the newly added class names.

Testing Instructions

Testing Instructions for Keyboard

  • Run npm run storybook:dev.
  • Navigate to DataViews examples.
  • Edit the default view and specify layout.styles.[column].align = end (and center). The screenshots below have the following view configured:
const [ view, setView ] = useState< View >( {
		...DEFAULT_VIEW,
		fields: [ 'categories' ],
		titleField: 'title',
		descriptionField: 'description',
		mediaField: 'image',
		layout: {
			styles:
				{
					categories: {
						align: 'end', // 'center'
					},
				},
			},
		} );

Screenshots or screencast

Align:end

Before Before(Hover)
Screenshot 2025-11-18 at 5 43 16 PM Screenshot 2025-11-18 at 5 43 24 PM
After After(hover)
Screenshot 2025-11-18 at 5 46 03 PM Screenshot 2025-11-18 at 5 46 10 PM

Align:center

Before After
Screenshot 2025-11-18 at 5 45 17 PM Screenshot 2025-11-18 at 5 45 38 PM

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 18, 2025
@github-actions
Copy link

👋 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.

@xristos3490 xristos3490 marked this pull request as ready for review November 18, 2025 16:32
@github-actions
Copy link

github-actions bot commented Nov 18, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: xristos3490 <[email protected]>
Co-authored-by: oandregal <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: mikejolley <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@oandregal oandregal added [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Bug An existing feature does not function as intended labels Nov 18, 2025
@oandregal
Copy link
Member

I tested this a bit and this is what I found:

  • The title ("primary column") is unaffected by the alignment. This also happens in trunk. @xristos3490 is this something you could take a look at as a follow-up? I don't think that's intentional.
  • Columns that render buttons (all but actions) are now properly aligned at the end.
Before After
Screenshot 2025-11-18 at 18 08 04 Screenshot 2025-11-18 at 18 03 19

return (
<th
key={ column }
className={ clsx( {
Copy link
Member

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.

Copy link
Contributor

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

See:
b-case-miss

However, we could modify the header-specific rules to make this work without adding any extra classes. I took a stab at this here.

@xristos3490
Copy link
Contributor Author

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

First column end-aligned First column start-aligned
Screenshot 2025-11-19 at 12 33 56 PM Screenshot 2025-11-19 at 12 34 24 PM

Case B: No actions column

Screenshot 2025-11-19 at 12 38 00 PM

Can you please take another look? Thanks!

The title ("primary column") is unaffected by the alignment. This also happens in trunk. @xristos3490 is this something you could take a look at as a follow-up? I don't think that's intentional.

Nice catch, André! Happy to follow up on this! 🙇

Comment on lines 163 to 169
&:has(.dataviews-view-table-header-button):first-child {
padding-left: $grid-unit-60;

.dataviews-view-table-header-button {
margin-left: - #{$grid-unit-10};
}
}
Copy link
Contributor

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? 🤔

Copy link
Contributor Author

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
Screenshot 2025-11-19 at 3 48 56 PM Screenshot 2025-11-19 at 3 49 10 PM

Copy link
Contributor

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.

@oandregal
Copy link
Member

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!

@xristos3490
Copy link
Contributor Author

Rebased in 49e9b64, @oandregal! Thanks for the reviews, folks! 🙇

@oandregal oandregal merged commit ffd5c2b into WordPress:trunk Nov 25, 2025
34 checks passed
@oandregal
Copy link
Member

Congrats on your 1st PR merged, @xristos3490 You're welcome to send many more :)

@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 25, 2025
@PanosSynetos
Copy link

Congrats Chris - Onwards and upwards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alignment issue when viewing a DataView with table layout and non-default column alignment

4 participants