diff --git a/docs/api-reference/next/image.md b/docs/api-reference/next/image.md index 93f01c3615160..6ce19500a0134 100644 --- a/docs/api-reference/next/image.md +++ b/docs/api-reference/next/image.md @@ -113,6 +113,18 @@ Should only be used when the image is visible above the fold. Defaults to false. In some cases, you may need more advanced usage. The `Image` component optionally accepts the following advanced properties. +### objectFit + +The image fit when using `layout="fill"`. + +[Learn more](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit) + +### objectPosition + +The image position when using `layout="fill"`. + +[Learn more](https://developer.mozilla.org/en-US/docs/Web/CSS/object-position) + ### loading The loading behavior of the image. Defaults to `lazy`. diff --git a/examples/image-component/pages/background.js b/examples/image-component/pages/background.js index d2bded5e1bb9f..b2680e7cd797c 100644 --- a/examples/image-component/pages/background.js +++ b/examples/image-component/pages/background.js @@ -1,5 +1,5 @@ import Image from 'next/image' -import { bgWrap, bgText, objectFitCover } from '../styles.module.css' +import { bgWrap, bgText } from '../styles.module.css' const Background = () => (
diff --git a/examples/image-component/pages/layout-fill.js b/examples/image-component/pages/layout-fill.js index a65587cb6c928..824958478c581 100644 --- a/examples/image-component/pages/layout-fill.js +++ b/examples/image-component/pages/layout-fill.js @@ -1,9 +1,4 @@ import Image from 'next/image' -import { - objectFitContain, - objectFitCover, - objectFitNone, -} from '../styles.module.css' const Fill = () => (
Layout Fill
Layout Fill
diff --git a/test/integration/image-component/default/test/index.test.js b/test/integration/image-component/default/test/index.test.js index 4cf85eb54c121..35ad401a47a1d 100644 --- a/test/integration/image-component/default/test/index.test.js +++ b/test/integration/image-component/default/test/index.test.js @@ -294,6 +294,15 @@ function runTests(mode) { }) expect(await getComputed(browser, id, 'width')).toBe(smallWidth) expect(await getComputed(browser, id, 'height')).toBe(smallHeight) + + const objectFit = await browser.eval( + `document.getElementById("${id}").style.objectFit` + ) + const objectPosition = await browser.eval( + `document.getElementById("${id}").style.objectPosition` + ) + expect(objectFit).toBe('cover') + expect(objectPosition).toBe('left center') } finally { if (browser) { await browser.close() diff --git a/test/integration/image-component/typescript/pages/valid.tsx b/test/integration/image-component/typescript/pages/valid.tsx index dede52cea1448..640211ea9c560 100644 --- a/test/integration/image-component/typescript/pages/valid.tsx +++ b/test/integration/image-component/typescript/pages/valid.tsx @@ -44,6 +44,20 @@ const Page = () => { width={100} height={100} /> +This is valid usage of the Image component
)