Skip to content

feat: add image fill prop - #1280

Open
nanhu95 wants to merge 1 commit into
mainfrom
add-image-fill-prop
Open

feat: add image fill prop#1280
nanhu95 wants to merge 1 commit into
mainfrom
add-image-fill-prop

Conversation

@nanhu95

@nanhu95 nanhu95 commented Jul 31, 2026

Copy link
Copy Markdown

Add a prop for component images to size
the image to either "fill" or "fit".

Screen.Recording.2026-07-31.at.10.20.02.mov

Add a prop for component images to size
the image to either "fill" or "fit".
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f122afbc-98af-4b44-9c4e-b092f56adb97

📥 Commits

Reviewing files that changed from the base of the PR and between a6c28b5 and f4586e1.

📒 Files selected for processing (11)
  • packages/visual-editor/src/components/atoms/image.test.tsx
  • packages/visual-editor/src/components/atoms/image.tsx
  • packages/visual-editor/src/components/contentBlocks/image/HeroImage.tsx
  • packages/visual-editor/src/components/contentBlocks/image/Image.tsx
  • packages/visual-editor/src/components/contentBlocks/image/styling.test.ts
  • packages/visual-editor/src/components/contentBlocks/image/styling.ts
  • packages/visual-editor/src/components/migrations/0079_image_fill_type.ts
  • packages/visual-editor/src/components/migrations/migrationRegistry.ts
  • packages/visual-editor/src/components/pageSections/PhotoGallerySection/PhotoGalleryWrapper.tsx
  • packages/visual-editor/src/types/images.ts
  • packages/visual-editor/src/utils/migrate.test.ts

Walkthrough

The change adds the shared ImageFillType type with fill and fit options. The Image component maps these values to object-fit styles across all rendering paths while allowing explicit style overrides. Image content blocks and photo galleries pass the setting directly to Image. Styling fields expose the new selector. Migration 0079 defaults missing values to fill and preserves existing values. Tests cover rendering, field configuration, and migration behavior.

Sequence Diagram(s)

sequenceDiagram
  participant Editor
  participant ImageWrapper
  participant Image
  participant Browser
  Editor->>ImageWrapper: configure imageFillType
  ImageWrapper->>Image: pass imageFillType
  Image->>Image: map fit to contain or fill to cover
  Image->>Browser: render image with computed object-fit
Loading

Possibly related PRs

Suggested reviewers: benlife5, mkilpatrick

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the addition of an image fill prop, which is the primary change.
Description check ✅ Passed The description accurately explains that images can use either "fill" or "fit" sizing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-image-fill-prop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These components were written pre-heavy use of Codex and so we haven't really set a post-Codex testing strategy. I have mixed feelings on whether tests like this are useful -- more coverage is good, but also they tend to be a lot of test code for testing small functionality & are prone to constant changes. So, I'd tend to say that we shouldn't commit tests like this and keep relying on the screenshot tests, but I'm open to other opinions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with this

For the other components we generally don't have tests like this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note bc this is fairly common - both your PR and my PR has a new migration, so whoever merges second will need to merge main and renumber the migration

};
}

const photoGalleryImageStylingFields = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - just put this object inline on 117

import { ImageType } from "@yext/pages-components";
import { TranslatableString } from "./types.ts";

export type ImageFillType = "fill" | "fit";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a brief tsdoc

import { removeMapboxApiKeyPropsMigration } from "../components/migrations/0078_remove_mapbox_api_key_props.ts";
import { imageFillTypeMigration } from "../components/migrations/0079_image_fill_type.ts";
import { ProductCard } from "../components/pageSections/ProductSection/ProductCard.tsx";
import { ImageWrapper } from "../components/contentBlocks/image/Image.tsx";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't import the components here -- if there's future changes, they will drift. I don't think migrate actually needs the components for this sort of test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with this

For the other components we generally don't have tests like this

@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";

Copy link
Copy Markdown
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 this test is super necessary

Can remove it

},
styles: {
aspectRatio: 1.78,
imageFillType: "fill" as const,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as const is kind of weird

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants