Skip to content

Commit fa88b02

Browse files
committed
[Snackbar] remove transition onX props
1 parent f434177 commit fa88b02

File tree

4 files changed

+7
-138
lines changed

4 files changed

+7
-138
lines changed

docs/pages/api-docs/snackbar.md

-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ The `MuiSnackbar` name can be used for providing [default props](/customization/
3939
| <span class="prop-name">key</span> | <span class="prop-type">any</span> | | When displaying multiple consecutive Snackbars from a parent rendering a single &lt;Snackbar/>, add the key prop to ensure independent treatment of each message. e.g. &lt;Snackbar key={message} />, otherwise, the message may update-in-place and features such as autoHideDuration may be canceled. |
4040
| <span class="prop-name">message</span> | <span class="prop-type">node</span> | | The message to display. |
4141
| <span class="prop-name">onClose</span> | <span class="prop-type">func</span> | | Callback fired when the component requests to be closed. Typically `onClose` is used to set state in the parent component, which is used to control the `Snackbar` `open` prop. The `reason` parameter can optionally be used to control the response to `onClose`, for example ignoring `clickaway`.<br><br>**Signature:**<br>`function(event: object, reason: string) => void`<br>*event:* The event source of the callback.<br>*reason:* Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`. |
42-
| <span class="prop-name">onEnter</span> | <span class="prop-type">func</span> | | Callback fired before the transition is entering. |
43-
| <span class="prop-name">onEntered</span> | <span class="prop-type">func</span> | | Callback fired when the transition has entered. |
44-
| <span class="prop-name">onEntering</span> | <span class="prop-type">func</span> | | Callback fired when the transition is entering. |
45-
| <span class="prop-name">onExit</span> | <span class="prop-type">func</span> | | Callback fired before the transition is exiting. |
46-
| <span class="prop-name">onExited</span> | <span class="prop-type">func</span> | | Callback fired when the transition has exited. |
47-
| <span class="prop-name">onExiting</span> | <span class="prop-type">func</span> | | Callback fired when the transition is exiting. |
4842
| <span class="prop-name">open</span> | <span class="prop-type">bool</span> | | If `true`, `Snackbar` is open. |
4943
| <span class="prop-name">resumeHideDuration</span> | <span class="prop-type">number</span> | | The number of milliseconds to wait before dismissing after user interaction. If `autoHideDuration` prop isn't specified, it does nothing. If `autoHideDuration` prop is specified but `resumeHideDuration` isn't, we default to `autoHideDuration / 2` ms. |
5044
| <span class="prop-name">TransitionComponent</span> | <span class="prop-type">elementType</span> | <span class="prop-default">Grow</span> | The component used for the transition. [Follow this guide](/components/transitions/#transitioncomponent-prop) to learn more about the requirements for this component. |

packages/material-ui/src/Snackbar/Snackbar.d.ts

-24
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,6 @@ export interface SnackbarProps
7171
* @param {string} reason Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`.
7272
*/
7373
onClose?: (event: React.SyntheticEvent<any>, reason: SnackbarCloseReason) => void;
74-
/**
75-
* Callback fired before the transition is entering.
76-
*/
77-
onEnter?: TransitionHandlerProps['onEnter'];
78-
/**
79-
* Callback fired when the transition has entered.
80-
*/
81-
onEntered?: TransitionHandlerProps['onEntered'];
82-
/**
83-
* Callback fired when the transition is entering.
84-
*/
85-
onEntering?: TransitionHandlerProps['onEntering'];
86-
/**
87-
* Callback fired before the transition is exiting.
88-
*/
89-
onExit?: TransitionHandlerProps['onExit'];
90-
/**
91-
* Callback fired when the transition has exited.
92-
*/
93-
onExited?: TransitionHandlerProps['onExited'];
94-
/**
95-
* Callback fired when the transition is exiting.
96-
*/
97-
onExiting?: TransitionHandlerProps['onExiting'];
9874
/**
9975
* If `true`, `Snackbar` is open.
10076
*/

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

+7-36
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ const Snackbar = React.forwardRef(function Snackbar(props, ref) {
108108
disableWindowBlurListener = false,
109109
message,
110110
onClose,
111-
onEnter,
112-
onEntered,
113-
onEntering,
114-
onExit,
115-
onExited,
116-
onExiting,
117111
onMouseEnter,
118112
onMouseLeave,
119113
open,
@@ -218,6 +212,13 @@ const Snackbar = React.forwardRef(function Snackbar(props, ref) {
218212
return null;
219213
}
220214

215+
if (TransitionProps !== undefined && TransitionProps.onEnter !== undefined) {
216+
TransitionProps.onEnter = createChainedFunction(handleEnter, TransitionProps.onEnter);
217+
};
218+
if (TransitionProps !== undefined && TransitionProps.onExited !== undefined) {
219+
TransitionProps.onExited = createChainedFunction(handleExited, TransitionProps.onExited);
220+
}
221+
221222
return (
222223
<ClickAwayListener onClickAway={handleClickAway} {...ClickAwayListenerProps}>
223224
<div
@@ -234,12 +235,6 @@ const Snackbar = React.forwardRef(function Snackbar(props, ref) {
234235
<TransitionComponent
235236
appear
236237
in={open}
237-
onEnter={createChainedFunction(handleEnter, onEnter)}
238-
onEntered={onEntered}
239-
onEntering={onEntering}
240-
onExit={onExit}
241-
onExited={createChainedFunction(handleExited, onExited)}
242-
onExiting={onExiting}
243238
timeout={transitionDuration}
244239
direction={vertical === 'top' ? 'down' : 'up'}
245240
{...TransitionProps}
@@ -323,30 +318,6 @@ Snackbar.propTypes = {
323318
* @param {string} reason Can be: `"timeout"` (`autoHideDuration` expired), `"clickaway"`.
324319
*/
325320
onClose: PropTypes.func,
326-
/**
327-
* Callback fired before the transition is entering.
328-
*/
329-
onEnter: PropTypes.func,
330-
/**
331-
* Callback fired when the transition has entered.
332-
*/
333-
onEntered: PropTypes.func,
334-
/**
335-
* Callback fired when the transition is entering.
336-
*/
337-
onEntering: PropTypes.func,
338-
/**
339-
* Callback fired before the transition is exiting.
340-
*/
341-
onExit: PropTypes.func,
342-
/**
343-
* Callback fired when the transition has exited.
344-
*/
345-
onExited: PropTypes.func,
346-
/**
347-
* Callback fired when the transition is exiting.
348-
*/
349-
onExiting: PropTypes.func,
350321
/**
351322
* @ignore
352323
*/

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

-72
Original file line numberDiff line numberDiff line change
@@ -45,78 +45,6 @@ describe('<Snackbar />', () => {
4545
});
4646
});
4747

48-
describe('Consecutive messages', () => {
49-
let clock;
50-
51-
beforeEach(() => {
52-
clock = useFakeTimers();
53-
});
54-
55-
afterEach(() => {
56-
clock.restore();
57-
});
58-
59-
it('should support synchronous onExited callback', () => {
60-
const messageCount = 2;
61-
let view;
62-
const handleCloseSpy = spy();
63-
const handleClose = () => {
64-
view.setProps({ open: false });
65-
handleCloseSpy();
66-
};
67-
const handleExitedSpy = spy();
68-
const handleExited = () => {
69-
handleExitedSpy();
70-
if (handleExitedSpy.callCount < messageCount) {
71-
view.setProps({ open: true });
72-
}
73-
};
74-
const duration = 250;
75-
view = render(
76-
<Snackbar
77-
open={false}
78-
onClose={handleClose}
79-
onExited={handleExited}
80-
message="message"
81-
autoHideDuration={duration}
82-
transitionDuration={duration / 2}
83-
/>,
84-
);
85-
86-
expect(handleCloseSpy.callCount).to.equal(0);
87-
expect(handleExitedSpy.callCount).to.equal(0);
88-
89-
view.setProps({ open: true });
90-
act(() => {
91-
clock.tick(duration);
92-
});
93-
94-
expect(handleCloseSpy.callCount).to.equal(1);
95-
expect(handleExitedSpy.callCount).to.equal(0);
96-
97-
act(() => {
98-
clock.tick(duration / 2);
99-
});
100-
101-
expect(handleCloseSpy.callCount).to.equal(1);
102-
expect(handleExitedSpy.callCount).to.equal(1);
103-
104-
act(() => {
105-
clock.tick(duration);
106-
});
107-
108-
expect(handleCloseSpy.callCount).to.equal(messageCount);
109-
expect(handleExitedSpy.callCount).to.equal(1);
110-
111-
act(() => {
112-
clock.tick(duration / 2);
113-
});
114-
115-
expect(handleCloseSpy.callCount).to.equal(messageCount);
116-
expect(handleExitedSpy.callCount).to.equal(messageCount);
117-
});
118-
});
119-
12048
describe('prop: autoHideDuration', () => {
12149
let clock;
12250

0 commit comments

Comments
 (0)