Skip to content

DataViews: Apply width styles to titleField in table layout#69191

Open
SainathPoojary wants to merge 2 commits intoWordPress:trunkfrom
SainathPoojary:fix/dataviews-title-field-styles
Open

DataViews: Apply width styles to titleField in table layout#69191
SainathPoojary wants to merge 2 commits intoWordPress:trunkfrom
SainathPoojary:fix/dataviews-title-field-styles

Conversation

@SainathPoojary
Copy link
Contributor

@SainathPoojary SainathPoojary commented Feb 13, 2025

Closes: #69185

What?

Apply layout styles (width, maxWidth, minWidth) to the primary column (titleField) in DataViews table layout, consistent with how they are applied to other fields.

Why?

Currently, width-related styles from view.layout.styles are only applied to regular fields but not to the primary column (titleField). This inconsistency prevents consumers from controlling table layout shifts through min/max widths for all columns, including the primary column.

How?

Added style properties to both the table header () and table cell () elements for the primary column, applying the same width-related styles that are already supported for other fields:

  • width
  • maxWidth
  • minWidth

The styles are conditionally applied based on the existence of the titleField and its corresponding styles in the view.layout configuration.

Testing Instructions

  1. Start the Storybook development server: npm run storybook:dev
  2. Navigate to "DataViews > DataViews > Default" story
  3. Modify the default view configuration to include width styles for both title and categories:
const [view, setView] = useState<View>({
  ...DEFAULT_VIEW,
  fields: ['categories'],
  titleField: 'title',
  descriptionField: 'description',
  mediaField: 'image',
  layout: {
    styles: {
      title: {
        maxWidth: '200px',
      },
      categories: {
        maxWidth: '200px',
      },
    },
  },
});
  1. Inspect the DataViews table in the browser
  2. Verify that both the title and categories columns have the maxWidth style applied to their respective cells

Screenshots

Before After
image image

@SainathPoojary SainathPoojary marked this pull request as ready for review February 14, 2025 06:55
@github-actions
Copy link

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: SainathPoojary <sainathpoojary@git.wordpress.org>
Co-authored-by: nani-samireddy <nanisamireddy@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Package] DataViews /packages/dataviews labels Feb 14, 2025
@SainathPoojary SainathPoojary force-pushed the fix/dataviews-title-field-styles branch from d8aa755 to 8d372a4 Compare March 5, 2025 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataViews: layout styles are not applied to titleField column

2 participants