Skip to content

Commit

Permalink
fix(collapse): show children if initial in prop is true
Browse files Browse the repository at this point in the history
  • Loading branch information
TimKolberger committed Nov 25, 2020
1 parent c81326e commit 2416cf9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/sixty-lizards-provide.md
@@ -0,0 +1,6 @@
---
"@chakra-ui/transition": patch
---

Fixed a bug where children of `<Collapse />` where not rendered if prop `in` was
true on first render
2 changes: 1 addition & 1 deletion packages/transition/src/collapse.tsx
Expand Up @@ -99,7 +99,7 @@ export const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>(
const [display, setDisplay] = React.useState<Display>(() => {
if (!fromZeroHeight) return "block"
const hidden = getInitialHidden()
return hidden ? "block" : "none"
return hidden ? "none" : "block"
})

useUpdateEffect(() => {
Expand Down
16 changes: 16 additions & 0 deletions packages/transition/stories/collapse.stories.tsx
Expand Up @@ -43,3 +43,19 @@ export const WithUnmount = () => <CollapseExample unmountOnExit />
export const WithoutOpacityTransition = () => (
<CollapseExample animateOpacity={false} />
)

export const WithInitialIn = () => (
<Collapse in>
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the
1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book. It has survived not only five centuries, but
also the leap into electronic typesetting, remaining essentially
unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop
publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</div>
</Collapse>
)
23 changes: 23 additions & 0 deletions packages/transition/tests/collapse.test.tsx
@@ -0,0 +1,23 @@
import * as React from "react"
import { Collapse } from "../src"
import { render, screen } from "@chakra-ui/test-utils"

describe("<Collapse />", () => {
it("should hide its children", async () => {
render(
<Collapse>
<div data-testid="collapse-children">Test</div>
</Collapse>,
)
expect(await screen.findByTestId("collapse-children")).not.toBeVisible()
})

it("should render its children on initial in", async () => {
render(
<Collapse in>
<div data-testid="collapse-children">Test</div>
</Collapse>,
)
expect(await screen.findByTestId("collapse-children")).toBeVisible()
})
})

0 comments on commit 2416cf9

Please sign in to comment.