DataViews Field rendering: Context should be not be assumed by fields when rendering #56320
Labels
[Feature] DataViews
Work surrounding upgrading and evolving views in the site editor and beyond
[Focus] Accessibility (a11y)
Changes that impact accessibility and need corresponding review (e.g. markup changes).
[Type] Enhancement
A suggestion for improvement.
Related: #55083
What problem does this address?
Field rendering is context-unaware, and the same output is generated regardless of which layout is being used. This means that we should ensure rendered content is appropriate in any view.
For example, while
<h3>{ title }</h3>
is appropriate in a grid, it should be<th scope="row">{ title }</th>
in a list.What is your proposed solution?
Layouts should render their own context (e.g.
<h3>
,<th>
) and fields should not be opinionated on this. Currently, for example, the list view renders its own<td>
s, which wrap every field:gutenberg/packages/edit-site/src/components/dataviews/view-list.js
Lines 489 to 507 in 447a6de
The
DataViews
component could gain aprimaryField
prop, or thefields
API could be adjusted to include anisPrimary
flag, either of which layouts could use to render context appropriately...The alternative is to make sure that
field.render
checks the view type that is passed in, but that adds complexity that is probably not worth it. Every field would have to know to render a<th>
or<td>
in some instances, an<h3>
in others, and as the list of available layouts changes, they would have to stay on top of that.The text was updated successfully, but these errors were encountered: