Skip to content

Commit

Permalink
[Popover] Fix default value
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jun 5, 2018
1 parent ab3bc94 commit 95a45f2
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/material-ui/src/Collapse/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ Collapse.defaultProps = {
timeout: duration.standard,
};

Collapse.muiSupportAuto = true;

export default withStyles(styles, {
withTheme: true,
name: 'MuiCollapse',
Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/Grow/Grow.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ Grow.defaultProps = {
timeout: 'auto',
};

Grow.muiSupportAuto = true;

export default withTheme()(Grow);
8 changes: 7 additions & 1 deletion packages/material-ui/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,17 @@ class Popover extends React.Component {
role,
transformOrigin,
TransitionComponent,
transitionDuration,
transitionDuration: transitionDurationProp,
TransitionProps,
...other
} = this.props;

let transitionDuration = transitionDurationProp;

if (transitionDurationProp === 'auto' && !TransitionComponent.muiSupportAuto) {
transitionDuration = undefined;
}

// If the container prop is provided, use that
// If the anchorEl prop is provided, use its parent body element as the container
// If neither are provided let the Modal take care of choosing the container
Expand Down
21 changes: 21 additions & 0 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,25 @@ describe('<Popover />', () => {
popoverActions.updatePosition();
});
});

describe('prop: transitionDuration', () => {
it('should apply the auto property if supported', () => {
const wrapper = shallow(
<Popover {...defaultProps}>
<div />
</Popover>,
);
assert.strictEqual(wrapper.find(Grow).props().timeout, 'auto');
});

it('should not apply the auto property if not supported', () => {
const TransitionComponent = props => <div {...props} />;
const wrapper = shallow(
<Popover {...defaultProps} TransitionComponent={TransitionComponent}>
<div />
</Popover>,
);
assert.strictEqual(wrapper.find(TransitionComponent).props().timeout, undefined);
});
});
});
8 changes: 7 additions & 1 deletion packages/material-ui/src/StepContent/StepContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function StepContent(props) {
optional,
orientation,
TransitionComponent,
transitionDuration,
transitionDuration: transitionDurationProp,
TransitionProps,
...other
} = props;
Expand All @@ -43,6 +43,12 @@ function StepContent(props) {
'Material-UI: <StepContent /> is only designed for use with the vertical stepper.',
);

let transitionDuration = transitionDurationProp;

if (transitionDurationProp === 'auto' && !TransitionComponent.muiSupportAuto) {
transitionDuration = undefined;
}

return (
<div className={classNames(classes.root, { [classes.last]: last }, className)} {...other}>
<TransitionComponent
Expand Down
29 changes: 25 additions & 4 deletions packages/material-ui/src/StepContent/StepContent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Collapse from '../Collapse';
describe('<StepContent />', () => {
let shallow;
let mount;
const props = {
const defaultProps = {
orientation: 'vertical',
};

Expand All @@ -21,7 +21,7 @@ describe('<StepContent />', () => {
});

it('renders a div', () => {
const wrapper = shallow(<StepContent {...props}>Here is the content</StepContent>);
const wrapper = shallow(<StepContent {...defaultProps}>Here is the content</StepContent>);
assert.strictEqual(wrapper.type(), 'div');
});

Expand All @@ -30,7 +30,7 @@ describe('<StepContent />', () => {
<StepContent
style={{ paddingRight: 200, color: 'purple', border: '1px solid tomato' }}
role="Tabpanel"
{...props}
{...defaultProps}
>
Lorem ipsum
</StepContent>,
Expand All @@ -44,7 +44,7 @@ describe('<StepContent />', () => {

it('renders children inside an Collapse component', () => {
const wrapper = shallow(
<StepContent {...props}>
<StepContent {...defaultProps}>
<div className="test-content">This is my content!</div>
</StepContent>,
);
Expand All @@ -54,4 +54,25 @@ describe('<StepContent />', () => {
assert.strictEqual(content.length, 1);
assert.strictEqual(content.props().children, 'This is my content!');
});

describe('prop: transitionDuration', () => {
it('should apply the auto property if supported', () => {
const wrapper = shallow(
<StepContent {...defaultProps}>
<div />
</StepContent>,
);
assert.strictEqual(wrapper.find(Collapse).props().timeout, 'auto');
});

it('should not apply the auto property if not supported', () => {
const TransitionComponent = props => <div {...props} />;
const wrapper = shallow(
<StepContent {...defaultProps} TransitionComponent={TransitionComponent}>
<div />
</StepContent>,
);
assert.strictEqual(wrapper.find(TransitionComponent).props().timeout, undefined);
});
});
});

0 comments on commit 95a45f2

Please sign in to comment.