Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Collapse] Deprecate classes.container #24084

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/pages/api-docs/collapse.md
Original file line number Diff line number Diff line change
@@ -46,9 +46,9 @@ Any other props supplied will be provided to the root element ([Transition](http

| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">container</span> | <span class="prop-name">.MuiCollapse-container</span> | Styles applied to the container element.
| <span class="prop-name">entered</span> | <span class="prop-name">.MuiCollapse-entered</span> | Styles applied to the container element when the transition has entered.
| <span class="prop-name">hidden</span> | <span class="prop-name">.MuiCollapse-hidden</span> | Styles applied to the container element when the transition has exited and `collapsedHeight` != 0px.
| <span class="prop-name">root</span> | <span class="prop-name">.MuiCollapse-root</span> | Styles applied to the root element.
| <span class="prop-name">entered</span> | <span class="prop-name">.MuiCollapse-entered</span> | Styles applied to the root element when the transition has entered.
| <span class="prop-name">hidden</span> | <span class="prop-name">.MuiCollapse-hidden</span> | Styles applied to the root element when the transition has exited and `collapsedHeight` != 0px.
| <span class="prop-name">wrapper</span> | <span class="prop-name">.MuiCollapse-wrapper</span> | Styles applied to the outer wrapper element.
| <span class="prop-name">wrapperInner</span> | <span class="prop-name">.MuiCollapse-wrapperInner</span> | Styles applied to the inner wrapper element.

2 changes: 1 addition & 1 deletion packages/material-ui/src/Collapse/Collapse.d.ts
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ export interface CollapseProps extends StandardProps<TransitionProps, CollapseCl
timeout?: TransitionProps['timeout'] | 'auto';
}

export type CollapseClassKey = 'container' | 'entered' | 'hidden' | 'wrapper' | 'wrapperInner';
export type CollapseClassKey = 'root' | 'entered' | 'hidden' | 'wrapper' | 'wrapperInner';

/**
* The Collapse transition is used by the
22 changes: 17 additions & 5 deletions packages/material-ui/src/Collapse/Collapse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { chainPropTypes } from '@material-ui/utils';
import { Transition } from 'react-transition-group';
import withStyles from '../styles/withStyles';
import { duration } from '../styles/transitions';
@@ -9,18 +10,18 @@ import useTheme from '../styles/useTheme';
import { useForkRef } from '../utils';

export const styles = (theme) => ({
/* Styles applied to the container element. */
container: {
/* Styles applied to the root element. */
root: {
height: 0,
overflow: 'hidden',
transition: theme.transitions.create('height'),
},
/* Styles applied to the container element when the transition has entered. */
/* Styles applied to the root element when the transition has entered. */
entered: {
height: 'auto',
overflow: 'visible',
},
/* Styles applied to the container element when the transition has exited and `collapsedHeight` != 0px. */
/* Styles applied to the root element when the transition has exited and `collapsedHeight` != 0px. */
hidden: {
visibility: 'hidden',
},
@@ -196,6 +197,7 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
{(state, childProps) => (
<Component
className={clsx(
classes.root,
classes.container,
{
[classes.entered]: state === 'entered',
@@ -232,7 +234,17 @@ Collapse.propTypes = {
* Override or extend the styles applied to the component.
* See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
classes: chainPropTypes(PropTypes.object, (props) => {
if (props.classes && props.classes.container) {
throw new Error([
'Material-UI: the classes.container key is deprecated.',
'Use `classes.root` instead',
'The name of the pseudo-class was changed for consistency.',
]).join('\n');
}

return null;
}),
/**
* @ignore
*/
4 changes: 2 additions & 2 deletions packages/material-ui/src/Collapse/Collapse.test.js
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ describe('<Collapse />', () => {

it('should render a container around the wrapper', () => {
const { container } = render(
<Collapse {...defaultProps} classes={{ container: 'woofCollapse1' }} />,
<Collapse {...defaultProps} classes={{ root: 'woofCollapse1' }} />,
);
const collapse = container.firstChild;
expect(collapse.tagName).to.equal('DIV');
expect(collapse).to.have.class(classes.container);
expect(collapse).to.have.class(classes.root);
expect(collapse).to.have.class('woofCollapse1');
});