diff --git a/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.js b/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.js
index 5cbb1432..4fab0d4d 100644
--- a/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.js
+++ b/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.js
@@ -65,7 +65,7 @@ const CAspectRatioBox = {
left: 0,
...vnode.data.attrs
}
- })
+ }, vnode.componentOptions.children || [])
return h('div', {
class: this.className,
diff --git a/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.stories.js b/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.stories.js
index 4f70bfbe..ff1ee77c 100644
--- a/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.stories.js
+++ b/packages/chakra-ui-core/src/CAspectRatioBox/CAspectRatioBox.stories.js
@@ -22,3 +22,23 @@ storiesOf('UI | AspectRatioBox', module)
}
}
}))
+ .add('Nested Elements', () => ({
+ components: { CAspectRatioBox, CBox },
+ template: `
+
+
+
+
+ See the Vue
+ Vue makes front-end development a breeze.
+
+
+
+
+ `,
+ data () {
+ return {
+ showCollapsed: true
+ }
+ }
+ }))
diff --git a/packages/chakra-ui-core/src/CAspectRatioBox/tests/CAspectRatioBox.test.js b/packages/chakra-ui-core/src/CAspectRatioBox/tests/CAspectRatioBox.test.js
index 2e8752c9..9cdeb4f8 100644
--- a/packages/chakra-ui-core/src/CAspectRatioBox/tests/CAspectRatioBox.test.js
+++ b/packages/chakra-ui-core/src/CAspectRatioBox/tests/CAspectRatioBox.test.js
@@ -6,7 +6,9 @@ const renderComponent = (props) => {
components: { CAspectRatioBox, CBox },
template: `
-
+
+
+
`,
...props
@@ -22,9 +24,11 @@ it('should render correctly', () => {
const [emotionClassName] = [...screen.getByTestId('aspectRatioBox').classList]
const pseudoStyles = getElementStyles(`.${emotionClassName}:before`)
- expect(pseudoStyles).toContain(`
+ expect(pseudoStyles).toContain(
+ `
padding-bottom: 100%
- `.trim())
+ `.trim()
+ )
})
it('should have correct styles', () => {
@@ -32,25 +36,38 @@ it('should have correct styles', () => {
renderComponent({ inlineAttrs })
const image = screen.getByTestId('image')
const aspectRatioBox = screen.getByTestId('aspectRatioBox')
+ const child = screen.getByTestId('child')
const [emotionClassName] = [...aspectRatioBox.classList] // second className has the pseudo styles
const pseudoStyles = getElementStyles(`.${emotionClassName}:before`)
- expect(pseudoStyles).toContain(`
+ expect(pseudoStyles).toContain(
+ `
padding-bottom: 50%
- `.trim())
+ `.trim()
+ )
expect(aspectRatioBox).toHaveStyle(`
max-width: 400px;
position: relative;
`)
- expect(image).toHaveStyle(`
- object-fit: cover;
+ // aspectRatioBox should contain exactly 1 immediate child
+ expect(aspectRatioBox.childElementCount).toEqual(1)
+
+ expect(child).toHaveStyle(`
position: absolute;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
`)
+
+ expect(child).not.toBeEmpty()
+
+ expect(image).toHaveStyle(`
+ object-fit: cover;
+ width: 100%;
+ height: 100%;
+ `)
})
diff --git a/packages/chakra-ui-core/src/CAspectRatioBox/tests/__snapshots__/CAspectRatioBox.test.js.snap b/packages/chakra-ui-core/src/CAspectRatioBox/tests/__snapshots__/CAspectRatioBox.test.js.snap
index 3b939e55..532a905a 100644
--- a/packages/chakra-ui-core/src/CAspectRatioBox/tests/__snapshots__/CAspectRatioBox.test.js.snap
+++ b/packages/chakra-ui-core/src/CAspectRatioBox/tests/__snapshots__/CAspectRatioBox.test.js.snap
@@ -7,13 +7,19 @@ exports[`should render correctly 1`] = `
data-chakra-component="CAspectRatioBox"
data-testid="aspectRatioBox"
>
-
+ data-testid="child"
+ >
+
+
`;