Skip to content

Dataviews: When isItemClickable returns false , image thumbnails lose their consistent size and aspect ratio #71220

@talldan

Description

@talldan

Description

This is a problem in Table and Grid views.

This seems like a bug as isItemClickable shouldn't affect appearance.

The cause is the way ItemClickWrapper works. When isItemClickable is `false, it omits the element that specifies the aspect ratio:

export function ItemClickWrapper< Item >( {
item,
isItemClickable,
onClickItem,
renderItemLink,
className,
children,
...extraProps
}: {
item: Item;
isItemClickable: ( item: Item ) => boolean;
onClickItem?: ( item: Item ) => void;
renderItemLink?: (
props: {
item: Item;
} & ComponentProps< 'a' >
) => ReactElement;
className?: string;
children: ReactNode;
} ) {
if ( ! isItemClickable( item ) ) {
return children;
}
// If we have a renderItemLink, use it
if ( renderItemLink ) {
return renderItemLink( {
item,
className: `${ className } ${ className }--clickable`,
...extraProps,
children,
} );
}
// Otherwise use the classic click handler approach
const clickProps = getClickableItemProps( {
item,
isItemClickable,
onClickItem,
className,
} );
return (
<div { ...clickProps } { ...extraProps }>
{ children }
</div>
);
}

Step-by-step reproduction instructions

  1. Run npm run storybook:dev
  2. When the storybook opens go to the Default DataViews story
  3. Change this line in the story from true to false:
  4. Observe the images are now all different sizes and aspect ratios. Switch to Grid layout and see the same.

Screenshots, screen recording, code snippet

Image

Environment info

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] DataViewsWork surrounding upgrading and evolving views in the site editor and beyond[Package] DataViews/packages/dataviews[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions