Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 6 additions & 15 deletions packages/ra-ui-materialui/src/layout/Notification.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import {
useNotify,
useCloseNotification,
} from 'ra-core';
import {
Alert,
Button,
SnackbarContent,
SnackbarContentProps,
Stack,
} from '@mui/material';
import { Alert, Button, SnackbarContent, Stack } from '@mui/material';

import { Notification } from './Notification';

Expand Down Expand Up @@ -214,11 +208,7 @@ export const ConsecutiveUndoable = ({
</CoreAdminContext>
);

// forwardRef is required for Snackbar to work (transitions) in React 18
const CustomNotificationWithActionContent = React.forwardRef<
HTMLDivElement,
SnackbarContentProps
>((props, ref) => {
const CustomNotificationWithActionContent = props => {
const closeNotification = useCloseNotification();
const handleClick = () => {
console.log('Custom action');
Expand All @@ -229,15 +219,16 @@ const CustomNotificationWithActionContent = React.forwardRef<
message="Applied automatic changes"
action={<Button onClick={handleClick}>Cancel</Button>}
{...props}
ref={ref}
/>
);
});
};

const CustomNotificationElementWithAction = () => {
const notify = useNotify();
React.useEffect(() => {
notify(<CustomNotificationWithActionContent />);
notify(<CustomNotificationWithActionContent />, {
autoHideDuration: null,
});
}, [notify]);
return null;
};
Expand Down
8 changes: 5 additions & 3 deletions packages/ra-ui-materialui/src/layout/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ export const Notification = (inProps: NotificationProps) => {
>
{message &&
typeof message !== 'string' &&
React.isValidElement(message)
? message
: undefined}
React.isValidElement(message) ? (
// Wrap the element in a div to avoid forcing our users to wrap their component with forwardRef
// which is required for animating the Snackbar
<div>{message}</div>
) : undefined}
</StyledSnackbar>
</CloseNotificationContext.Provider>
);
Expand Down