DataViews: Make grid and table item preview aspect ratio configurable - #79329
Conversation
0a12995 to
3ce3734
Compare
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @vianasw! 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. |
3ce3734 to
54c2fd0
Compare
cb8fbd8 to
ef4af68
Compare
|
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @vianasw. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
|
Thanks for the PR! Let's also get some design feedback (@WordPress/gutenberg-design) and maybe @oandregal has thoughts too. |
|
At a glance, this seems valid enough to me, assuming it looks good with image-less placeholders too. It also addresses a point raised by Jay, who has worked with DataViews long enough that I trust his previously asserted instincts. 👍 |
b997531 to
21d6390
Compare
|
We'd need to update view-config schema to include this new prop. I think it's fine to handle as a follow-up, as there's no functional impact in the meantime. It also involves a couple of extra small changes, because the PHP layout schemas are shared between |
The grid layout's media preview is hard-coded to a `1/1` (square) aspect ratio. Some consumers need a different shape — e.g. a video library wants `16/9` to match how the media actually appears when embedded. Add an `aspectRatio` option to the grid `layout` config. It is applied uniformly to every item via a `--dataviews-grid-media-aspect-ratio` CSS custom property and defaults to `1/1`, so existing consumers are unaffected. This implements the uniform, consumer-set case from WordPress#60891 and leaves the user-facing toggle (and `auto`/variable per-item ratios) out of scope — that was the part that stalled the earlier attempt in WordPress#63487. Part of WordPress#60891 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the aspectRatio layout option to ViewTable as well: the value is surfaced on the table element and read by the primary column's media styles, which switch from a fixed square (width/height) to height + aspect-ratio so row heights are unchanged and the preview widens instead. A 16/9 preview at the default height still fits the wrapper's existing max-width. Since the CSS custom property is now read by more than one layout, rename it from --dataviews-grid-media-aspect-ratio to --dataviews-media-aspect-ratio (safe pre-release: the original commit is part of this unmerged PR). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Constrain the aspectRatio layout option from a free-form string to a MediaAspectRatio union of preset ratios (1/1, 4/3, 3/4, 3/2, 2/3, 16/9, 9/16 — mirroring Core's default aspect-ratio presets), following the same pattern as the density option. Starting narrow is the safe API direction: widening the union later is backward compatible, while narrowing a shipped free-form string would be a breaking change. Runtime behavior is unchanged — the value still reaches CSS as a custom property. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The trunk merge landed while three @wordpress/dataviews releases had shipped since this branch was cut, so the entry's original surroundings (the old Unreleased section) had become the 17.0.0 section — taking the entry with them. Restore 17.0.0 to its released contents and list the entry under Unreleased, where the changelog CI check expects it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Rename the custom property to --wp-dataviews-media-aspect-ratio, matching the existing --wp-dataviews-color-background convention. - Always set the property (with the 1/1 default) on the grid and table roots, so an identically-named variable set by a consumer on an ancestor can't leak into previews when the view doesn't configure a ratio. - Gate the table media sizing behind a has-media-aspect-ratio modifier (same pattern as has-*-density): the base .dataviews-column-primary__media rules are restored to exactly what trunk ships, and the fixed-height + ratio sizing (with the img filling the box) only applies when the view sets layout.aspectRatio. Views without it see no change, including media renders taller than the 32px default. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…x sub-square table previews Address the second round of review feedback: - Add a shared MEDIA_ASPECT_RATIOS constant and derive the MediaAspectRatio type from it, so the runtime list and the type can't drift apart. Both layouts now validate layout.aspectRatio against the presets (like density) and fall back to the square default; the table only applies the has-media-aspect-ratio modifier for a valid preset. - Drop the redundant CSSProperties annotation in favor of the single cast, in both layouts. - Release the base rule's min-width under the has-media-aspect-ratio modifier: it equals the fixed height, so sub-square presets (3/4, 2/3, 9/16) derived a width below it and rendered square. - Widen the table's srcset sizes hint from the validated ratio: with a ratio configured the preview box is width-variable (up to the 60px max-width), and the hardcoded 32px hint made consumers that honor it pick an undersized, blurry source for wide ratios. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014CG2FSyrhQ581KmpSmjcco
f5cd7c4 to
bca4649
Compare
ntsekouras
left a comment
There was a problem hiding this comment.
This LGTM. Thanks for effort and the iterations! Great work!
|
👍 to prepare a follow-up with the schema changes. Heads up that I'm working on generating the docs and the PHP schema from the JSON schema at #81168 so, depending on timing, one of them will need rebase. |
Sounds good. I can open the follow up after your changes have landed. |
|
Congratulations on your first merged pull request, @vianasw! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts: https://profiles.wordpress.org/me/profile/edit/ And if you don't have a WordPress.org account, you can create one on this page: https://login.wordpress.org/register Kudos! |
What?
See #60891
The DataViews
gridlayout renders item previews (the media field) at a hard-coded1/1(square) aspect ratio, and thetablelayout does the same for the primary column's media preview. This adds anaspectRatiooption to thegridandtablelayoutconfigs so consumers can choose the shape, defaulting to1/1so nothing changes for existing consumers.Why?
#60891 asks for the grid preview aspect ratio to be consumer configurable — a square crop isn't ideal for every dataset (tall templates, wide media, video thumbnails, etc.). For example, a video library wants
16/9previews so the thumbnail matches how the video actually appears.A previous attempt (#63487) stalled on the UX of a user-facing toggle between
1/1andauto(variable per-item ratios), which raised "visual rivers" / masonry concerns. This PR deliberately sidesteps that debate: it exposes a single consumer-set, uniform aspect ratio, applied identically to every item — the form even the prior reviewers were comfortable with ("it should change the aspect ratio of all previews"). The user-facing toggle andauto/variable per-item ratios are intentionally left as a follow-up.Scope is limited to the
gridandtablelayouts;pickerGrid/pickerTableparity is a straightforward follow-up.How?
aspectRatio?: MediaAspectRatiotoViewGrid['layout']andViewTable['layout'], whereMediaAspectRatiois a union of preset ratios ('1/1' | '4/3' | '3/4' | '3/2' | '2/3' | '16/9' | '9/16', mirroring Core's default aspect-ratio presets) — the same constrained-union pattern asdensity. Starting with presets keeps the API easy to widen later without a breaking change, and avoids consumers setting degenerate ratios.--wp-dataviews-media-aspect-ratioCSS custom property (matching the existing--wp-dataviews-color-backgroundnaming) on the layout root (the grid container — both the standard and infinite-scroll roots — and thetableelement). The property is always set, defaulting to1/1, so a same-named variable set by a consumer on an ancestor can't leak into the previews..dataviews-view-grid__mediarule reads it with a1/1fallback:aspect-ratio: var(--wp-dataviews-media-aspect-ratio, 1/1).has-media-aspect-ratiomodifier (same pattern ashas-*-density) that the table only carries when the view setslayout.aspectRatio. Under the modifier, the.dataviews-column-primary__mediawrapper takesheight+aspect-ratio, with theimgfilling it — sizing the wrapper rather than theimgkeeps custom media field renders (nested elements instead of a bareimg) covered too. Row heights are unchanged; the preview widens instead, and a16/9preview at the default height still fits the wrapper's existingmax-width. WithoutaspectRatio, the base rules are exactly what trunk ships today.1/1default and the table keeps its current sizing until a view opts in.Testing Instructions
gridDataView, set the layout'saspectRatio, e.g.view = { type: 'grid', layout: { aspectRatio: '16/9' }, … }.'4/3','1/1') and confirm they apply uniformly to every item.tableDataView with a media field, setlayout.aspectRatio: '16/9'and confirm the primary column's thumbnail renders 16:9 at the same height — row heights don't change.aspectRatio(or use an existing grid/table consumer such as the Pages/Templates views) and confirm previews stay square (1/1) — no regression.previewSizeanddensitystill work alongside it.Testing Instructions for Keyboard
No interaction changes — the option only affects preview dimensions, so existing keyboard navigation of the grid and table is unaffected.
Screenshots or screencast
1/1)aspectRatio: '16/9')Use of AI Tools
This PR was authored with the assistance of AI tooling (Claude Code). The implementation, scope decisions, and this description were AI-assisted and reviewed by me before submission; I take responsibility for the contents.