Skip to content

Commit 7edaadc

Browse files
mbrookesoliviertassinari
authored andcommitted
[Popover] Deprecate transition onX props (#22202)
1 parent 9445d1f commit 7edaadc

File tree

6 files changed

+195
-50
lines changed

6 files changed

+195
-50
lines changed

docs/pages/api-docs/popover.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ The `MuiPopover` name can be used for providing [default props](/customization/g
4040
| <span class="prop-name">getContentAnchorEl</span> | <span class="prop-type">func</span> | | This function is called in order to retrieve the content anchor element. It's the opposite of the `anchorEl` prop. The content anchor element should be an element inside the popover. It's used to correctly scroll and set the position of the popover. The positioning strategy tries to make the content anchor element just above the anchor element. |
4141
| <span class="prop-name">marginThreshold</span> | <span class="prop-type">number</span> | <span class="prop-default">16</span> | Specifies how close to the edge of the window the popover can appear. |
4242
| <span class="prop-name">onClose</span> | <span class="prop-type">func</span> | | Callback fired when the component requests to be closed. |
43-
| <span class="prop-name">onEnter</span> | <span class="prop-type">func</span> | | Callback fired before the component is entering. |
44-
| <span class="prop-name">onEntered</span> | <span class="prop-type">func</span> | | Callback fired when the component has entered. |
45-
| <span class="prop-name">onEntering</span> | <span class="prop-type">func</span> | | Callback fired when the component is entering. |
46-
| <span class="prop-name">onExit</span> | <span class="prop-type">func</span> | | Callback fired before the component is exiting. |
47-
| <span class="prop-name">onExited</span> | <span class="prop-type">func</span> | | Callback fired when the component has exited. |
48-
| <span class="prop-name">onExiting</span> | <span class="prop-type">func</span> | | Callback fired when the component is exiting. |
43+
| ~~<span class="prop-name">onEnter</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired before the component is entering. |
44+
| ~~<span class="prop-name">onEntered</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired when the component has entered. |
45+
| ~~<span class="prop-name">onEntering</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired when the component is entering. |
46+
| ~~<span class="prop-name">onExit</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired before the component is exiting. |
47+
| ~~<span class="prop-name">onExited</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired when the component has exited. |
48+
| ~~<span class="prop-name">onExiting</span>~~ | <span class="prop-type">func</span> | | *Deprecated*. Use the `TransitionProps` prop instead.<br><br>Callback fired when the component is exiting. |
4949
| <span class="prop-name required">open<abbr title="required">*</abbr></span> | <span class="prop-type">bool</span> | | If `true`, the popover is visible. |
5050
| <span class="prop-name">PaperProps</span> | <span class="prop-type">{ component?: element type }</span> | <span class="prop-default">{}</span> | Props applied to the [`Paper`](/api/paper/) element. |
5151
| <span class="prop-name">transformOrigin</span> | <span class="prop-type">{ horizontal: 'center'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right'<br>&#124;&nbsp;number, vertical: 'bottom'<br>&#124;&nbsp;'center'<br>&#124;&nbsp;'top'<br>&#124;&nbsp;number }</span> | <span class="prop-default">{ vertical: 'top', horizontal: 'left',}</span> | This is the point on the popover which will attach to the anchor's origin.<br>Options: vertical: [top, center, bottom, x(px)]; horizontal: [left, center, right, x(px)]. |

packages/material-ui/src/Menu/Menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const Menu = React.forwardRef(function Menu(props, ref) {
135135
getContentAnchorEl={getContentAnchorEl}
136136
classes={PopoverClasses}
137137
onClose={onClose}
138-
onEntering={handleEntering}
138+
TransitionProps={{ onEntering: handleEntering }}
139139
anchorOrigin={theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN}
140140
transformOrigin={theme.direction === 'rtl' ? RTL_ORIGIN : LTR_ORIGIN}
141141
PaperProps={{

packages/material-ui/src/Menu/Menu.test.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ describe('<Menu />', () => {
4444

4545
const wrapper = mount(
4646
<Menu
47-
onEnter={handleEnter}
48-
onEntering={handleEntering}
49-
onEntered={() => {
50-
expect(handleEnter.callCount).to.equal(1);
51-
expect(handleEnter.args[0].length).to.equal(2);
52-
expect(handleEntering.callCount).to.equal(1);
53-
expect(handleEntering.args[0].length).to.equal(2);
54-
done();
47+
TransitionProps={{
48+
onEnter: handleEnter,
49+
onEntering: handleEntering,
50+
onEntered: () => {
51+
expect(handleEnter.callCount).to.equal(1);
52+
expect(handleEnter.args[0].length).to.equal(2);
53+
expect(handleEntering.callCount).to.equal(1);
54+
expect(handleEntering.args[0].length).to.equal(2);
55+
done();
56+
},
5557
}}
5658
{...defaultProps}
5759
/>,
@@ -70,14 +72,16 @@ describe('<Menu />', () => {
7072

7173
const wrapper = mount(
7274
<Menu
73-
onExit={handleExit}
74-
onExiting={handleExiting}
75-
onExited={() => {
76-
expect(handleExit.callCount).to.equal(1);
77-
expect(handleExit.args[0].length).to.equal(1);
78-
expect(handleExiting.callCount).to.equal(1);
79-
expect(handleExiting.args[0].length).to.equal(1);
80-
done();
75+
TransitionProps={{
76+
onExit: handleExit,
77+
onExiting: handleExiting,
78+
onExited: () => {
79+
expect(handleExit.callCount).to.equal(1);
80+
expect(handleExit.args[0].length).to.equal(1);
81+
expect(handleExiting.callCount).to.equal(1);
82+
expect(handleExiting.args[0].length).to.equal(1);
83+
done();
84+
},
8185
}}
8286
{...defaultProps}
8387
open
@@ -161,28 +165,34 @@ describe('<Menu />', () => {
161165
expect(false).to.equal(menuEl.contains(document.activeElement));
162166
});
163167

164-
it('should call props.onEntering with element if exists', () => {
168+
it('should call TransitionProps.onEntering with element if exists', () => {
165169
const onEnteringSpy = spy();
166-
const wrapper = mount(<Menu {...defaultProps} onEntering={onEnteringSpy} />);
170+
const wrapper = mount(
171+
<Menu {...defaultProps} TransitionProps={{ onEntering: onEnteringSpy }} />,
172+
);
167173
const popover = wrapper.find(Popover);
168174

169175
const elementForHandleEnter = { clientHeight: MENU_LIST_HEIGHT };
170176

171-
popover.props().onEntering(elementForHandleEnter);
177+
popover.props().TransitionProps.onEntering(elementForHandleEnter);
172178
expect(onEnteringSpy.callCount).to.equal(1);
173179
expect(onEnteringSpy.calledWith(elementForHandleEnter)).to.equal(true);
174180
});
175181

176-
it('should call props.onEntering, disableAutoFocusItem', () => {
182+
it('should call TransitionProps.onEntering, disableAutoFocusItem', () => {
177183
const onEnteringSpy = spy();
178184
const wrapper = mount(
179-
<Menu disableAutoFocusItem {...defaultProps} onEntering={onEnteringSpy} />,
185+
<Menu
186+
disableAutoFocusItem
187+
{...defaultProps}
188+
TransitionProps={{ onEntering: onEnteringSpy }}
189+
/>,
180190
);
181191
const popover = wrapper.find(Popover);
182192

183193
const elementForHandleEnter = { clientHeight: MENU_LIST_HEIGHT };
184194

185-
popover.props().onEntering(elementForHandleEnter);
195+
popover.props().TransitionProps.onEntering(elementForHandleEnter);
186196
expect(onEnteringSpy.callCount).to.equal(1);
187197
expect(onEnteringSpy.calledWith(elementForHandleEnter)).to.equal(true);
188198
});

packages/material-ui/src/Popover/Popover.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import clsx from 'clsx';
1212
import ownerDocument from '../utils/ownerDocument';
1313
import ownerWindow from '../utils/ownerWindow';
1414
import createChainedFunction from '../utils/createChainedFunction';
15+
import deprecatedPropType from '../utils/deprecatedPropType';
1516
import withStyles from '../styles/withStyles';
1617
import Modal from '../Modal';
1718
import Grow from '../Grow';
@@ -554,27 +555,27 @@ Popover.propTypes = {
554555
/**
555556
* Callback fired before the component is entering.
556557
*/
557-
onEnter: PropTypes.func,
558+
onEnter: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
558559
/**
559560
* Callback fired when the component has entered.
560561
*/
561-
onEntered: PropTypes.func,
562+
onEntered: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
562563
/**
563564
* Callback fired when the component is entering.
564565
*/
565-
onEntering: PropTypes.func,
566+
onEntering: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
566567
/**
567568
* Callback fired before the component is exiting.
568569
*/
569-
onExit: PropTypes.func,
570+
onExit: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
570571
/**
571572
* Callback fired when the component has exited.
572573
*/
573-
onExited: PropTypes.func,
574+
onExited: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
574575
/**
575576
* Callback fired when the component is exiting.
576577
*/
577-
onExiting: PropTypes.func,
578+
onExiting: deprecatedPropType(PropTypes.func, 'Use the `TransitionProps` prop instead.'),
578579
/**
579580
* If `true`, the popover is visible.
580581
*/

packages/material-ui/src/Popover/Popover.test.js

Lines changed: 148 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('<Popover />', () => {
215215

216216
// transitions towards entered
217217
const wrapper = mount(
218-
<Popover {...defaultProps} open transitionDuration={0} {...handlers}>
218+
<Popover {...defaultProps} open transitionDuration={0} TransitionProps={{ ...handlers }}>
219219
<div />
220220
</Popover>,
221221
);
@@ -271,7 +271,7 @@ describe('<Popover />', () => {
271271
it('should set the inline styles for the enter phase', () => {
272272
const handleEntering = spy();
273273
const wrapper = mount(
274-
<Popover {...defaultProps} onEntering={handleEntering}>
274+
<Popover {...defaultProps} TransitionProps={{ onEntering: handleEntering }}>
275275
<div />
276276
</Popover>,
277277
);
@@ -335,9 +335,11 @@ describe('<Popover />', () => {
335335
anchorEl={anchorEl}
336336
anchorOrigin={anchorOrigin}
337337
transitionDuration={0}
338-
onEntered={() => {
339-
popoverEl = document.querySelector('[data-mui-test="Popover"]');
340-
resolve();
338+
TransitionProps={{
339+
onEntered: () => {
340+
popoverEl = document.querySelector('[data-mui-test="Popover"]');
341+
resolve();
342+
},
341343
}}
342344
>
343345
<div />
@@ -481,9 +483,11 @@ describe('<Popover />', () => {
481483
anchorPosition={anchorPosition}
482484
anchorOrigin={anchorOrigin}
483485
transitionDuration={0}
484-
onEntered={() => {
485-
popoverEl = document.querySelector('[data-mui-test="Popover"]');
486-
resolve();
486+
TransitionProps={{
487+
onEntered: () => {
488+
popoverEl = document.querySelector('[data-mui-test="Popover"]');
489+
resolve();
490+
},
487491
}}
488492
>
489493
<div />
@@ -525,9 +529,11 @@ describe('<Popover />', () => {
525529
{...defaultProps}
526530
anchorReference="none"
527531
transitionDuration={0}
528-
onEntered={() => {
529-
popoverEl = document.querySelector('[data-mui-test="Popover"]');
530-
resolve();
532+
TransitionProps={{
533+
onEntered: () => {
534+
popoverEl = document.querySelector('[data-mui-test="Popover"]');
535+
resolve();
536+
},
531537
}}
532538
PaperProps={{
533539
style: {
@@ -578,7 +584,7 @@ describe('<Popover />', () => {
578584
<Popover
579585
anchorEl={mockedAnchor}
580586
open
581-
onEntering={handleEntering}
587+
TransitionProps={{ onEntering: handleEntering }}
582588
transitionDuration={0}
583589
marginThreshold={8}
584590
>
@@ -663,7 +669,7 @@ describe('<Popover />', () => {
663669
<Popover
664670
anchorEl={anchorEl}
665671
open
666-
onEntering={handleEntering}
672+
TransitionProps={{ onEntering: handleEntering }}
667673
marginThreshold={marginThreshold}
668674
PaperProps={{ component: FakePaper }}
669675
>
@@ -785,7 +791,7 @@ describe('<Popover />', () => {
785791
mount(
786792
<Popover
787793
anchorEl={mockedAnchorEl}
788-
onEntering={handleEntering}
794+
TransitionProps={{ onEntering: handleEntering }}
789795
getContentAnchorEl={getContentAnchorEl}
790796
open
791797
>
@@ -822,6 +828,15 @@ describe('<Popover />', () => {
822828
});
823829

824830
describe('prop: TransitionProp', () => {
831+
beforeEach(() => {
832+
PropTypes.resetWarningCache();
833+
stub(console, 'error');
834+
});
835+
836+
afterEach(() => {
837+
console.error.restore();
838+
});
839+
825840
it('chains onEntering with the apparent onEntering prop', () => {
826841
const apparentHandler = spy();
827842
const transitionHandler = spy();
@@ -861,4 +876,123 @@ describe('<Popover />', () => {
861876
expect(transitionHandler.callCount).to.equal(1);
862877
});
863878
});
879+
880+
describe('deprecated transition callback props', () => {
881+
beforeEach(() => {
882+
PropTypes.resetWarningCache();
883+
stub(console, 'error');
884+
});
885+
886+
afterEach(() => {
887+
console.error.restore();
888+
});
889+
890+
describe('prop: onEnter', () => {
891+
it('issues a warning', () => {
892+
PropTypes.checkPropTypes(
893+
Popover.Naked.propTypes,
894+
{
895+
onEnter: () => [],
896+
},
897+
'prop',
898+
'Popover',
899+
);
900+
901+
expect(console.error.callCount).to.equal(2);
902+
expect(console.error.firstCall.args[0]).to.equal(
903+
'Warning: Failed prop type: The prop `onEnter` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
904+
);
905+
});
906+
});
907+
908+
describe('prop: onEntering', () => {
909+
it('issues a warning', () => {
910+
PropTypes.checkPropTypes(
911+
Popover.Naked.propTypes,
912+
{
913+
onEntering: () => [],
914+
},
915+
'prop',
916+
'Popover',
917+
);
918+
919+
expect(console.error.callCount).to.equal(2);
920+
expect(console.error.firstCall.args[0]).to.equal(
921+
'Warning: Failed prop type: The prop `onEntering` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
922+
);
923+
});
924+
});
925+
926+
describe('prop: onEntered', () => {
927+
it('issues a warning', () => {
928+
PropTypes.checkPropTypes(
929+
Popover.Naked.propTypes,
930+
{
931+
onEntered: () => [],
932+
},
933+
'prop',
934+
'Popover',
935+
);
936+
937+
expect(console.error.callCount).to.equal(2);
938+
expect(console.error.firstCall.args[0]).to.equal(
939+
'Warning: Failed prop type: The prop `onEntered` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
940+
);
941+
});
942+
});
943+
944+
describe('prop: onExit', () => {
945+
it('issues a warning', () => {
946+
PropTypes.checkPropTypes(
947+
Popover.Naked.propTypes,
948+
{
949+
onExit: () => [],
950+
},
951+
'prop',
952+
'Popover',
953+
);
954+
955+
expect(console.error.callCount).to.equal(2);
956+
expect(console.error.firstCall.args[0]).to.equal(
957+
'Warning: Failed prop type: The prop `onExit` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
958+
);
959+
});
960+
});
961+
962+
describe('prop: onExiting', () => {
963+
it('issues a warning', () => {
964+
PropTypes.checkPropTypes(
965+
Popover.Naked.propTypes,
966+
{
967+
onExiting: () => [],
968+
},
969+
'prop',
970+
'Popover',
971+
);
972+
973+
expect(console.error.callCount).to.equal(2);
974+
expect(console.error.firstCall.args[0]).to.equal(
975+
'Warning: Failed prop type: The prop `onExiting` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
976+
);
977+
});
978+
});
979+
980+
describe('prop: onExited', () => {
981+
it('issues a warning', () => {
982+
PropTypes.checkPropTypes(
983+
Popover.Naked.propTypes,
984+
{
985+
onExited: () => [],
986+
},
987+
'prop',
988+
'Popover',
989+
);
990+
991+
expect(console.error.callCount).to.equal(2);
992+
expect(console.error.firstCall.args[0]).to.equal(
993+
'Warning: Failed prop type: The prop `onExited` of `Popover` is deprecated. Use the `TransitionProps` prop instead.',
994+
);
995+
});
996+
});
997+
});
864998
});

packages/material-ui/src/Select/Select.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ describe('<Select />', () => {
540540
it('should apply additional props to the Menu component', () => {
541541
const onEntered = spy();
542542
const { getByRole } = render(
543-
<Select MenuProps={{ onEntered, transitionDuration: 100 }} value="10">
543+
<Select MenuProps={{ TransitionProps: { onEntered }, transitionDuration: 100 }} value="10">
544544
<MenuItem value="10">Ten</MenuItem>
545545
</Select>,
546546
);

0 commit comments

Comments
 (0)