Skip to content

Commit

Permalink
fix(gatsby-plugin-image): Apply object-fit and object-position to pla…
Browse files Browse the repository at this point in the history
…ceholder (#30894) (#30944)

(cherry picked from commit 8affcf5)

Co-authored-by: Matt Kane <matt@gatsbyjs.com>
  • Loading branch information
GatsbyJS Bot and ascorbic committed Apr 19, 2021
1 parent ef8feae commit 2ee989c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const GatsbyImage: FunctionComponent<GatsbyImageProps> = function GatsbyI
layout,
width,
height,
placeholderBackgroundColor
placeholderBackgroundColor,
objectFit,
objectPosition
)}
/>

Expand Down
11 changes: 10 additions & 1 deletion packages/gatsby-plugin-image/src/components/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ export function getPlaceholderProps(
layout: Layout,
width?: number,
height?: number,
backgroundColor?: string
backgroundColor?: string,
objectFit?: CSSProperties["objectFit"],
objectPosition?: CSSProperties["objectPosition"]
): PlaceholderImageAttrs {
const wrapperStyle: CSSProperties = {}

Expand All @@ -339,6 +341,13 @@ export function getPlaceholderProps(
}
}

if (objectFit) {
wrapperStyle.objectFit = objectFit
}

if (objectPosition) {
wrapperStyle.objectPosition = objectPosition
}
const result: PlaceholderImageAttrs = {
...placeholder,
"aria-hidden": true,
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-plugin-image/src/components/lazy-hydrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function lazyHydrate(
layout,
width,
height,
wrapperBackgroundColor
wrapperBackgroundColor,
objectFit,
objectPosition
)}
/>

Expand Down

0 comments on commit 2ee989c

Please sign in to comment.