Skip to content

Commit

Permalink
Update unmountOnExit behaviour docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Jan 5, 2024
1 parent 23fc7c4 commit 549b303
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/data/material/components/accordion/accordion.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ accordions it might be a good idea to change this default behavior by enabling t
`unmountOnExit` in `TransitionProps`:

```jsx
<Accordion TransitionProps={{ unmountOnExit: true }} />
<Accordion slotProps={{ transition: { unmountOnExit: true } }} />
```

As with any performance optimization this is not a silver bullet.
Expand Down
26 changes: 25 additions & 1 deletion packages/mui-material/src/Accordion/Accordion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('<Accordion />', () => {
testVariantProps: { variant: 'rounded' },
slots: {
transition: {
expectedClassName: '',
testWithElement: null,
},
},
skip: ['componentProp', 'componentsProp', 'slotPropsCallback'],
Expand Down Expand Up @@ -227,4 +227,28 @@ describe('<Accordion />', () => {
expect(getByTestId('transition-testid')).not.to.equal(null);
});
});

describe('details unmounting behavior', () => {
it('does not unmount by default', () => {
const { queryByTestId } = render(
<Accordion expanded={false}>
<AccordionSummary>Summary</AccordionSummary>
<div data-testid="details">Details</div>
</Accordion>,
);

expect(queryByTestId('details')).not.to.equal(null);
});

it('unmounts if opted in via slotProps.transition', () => {
const { queryByTestId } = render(
<Accordion expanded={false} slotProps={{ transition: { unmountOnExit: true } }}>
<AccordionSummary>Summary</AccordionSummary>
<div data-testid="details">Details</div>
</Accordion>,
);

expect(queryByTestId('details')).to.equal(null);
});
});
});

0 comments on commit 549b303

Please sign in to comment.