Skip to content

Commit

Permalink
[@mantine/notifications] Fix limit prop not working (#5105)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtivital committed Nov 7, 2023
1 parent 9bcc42e commit 66f05d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
DirectionProvider,
useDirection,
} from '@mantine/core';
import { Notifications } from '@mantine/notifications';
import { theme } from '../docs/theme';

export const parameters = { layout: 'fullscreen' };
Expand Down Expand Up @@ -45,7 +44,6 @@ function DirectionWrapper({ children }: { children: React.ReactNode }) {
>
{dir === 'ltr' ? <IconTextDirectionLtr /> : <IconTextDirectionRtl />}
</ActionIcon>
<Notifications />
{children}
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/mantine-notifications/src/Notifications.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default { title: 'Notifications' };
export function Usage() {
return (
<div style={{ padding: 40 }}>
<Notifications autoClose={false} position="top-center" />
<Notifications autoClose={false} position="top-center" limit={1} />

<Group>
<Button
Expand Down
6 changes: 5 additions & 1 deletion src/mantine-notifications/src/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useRef, useEffect } from 'react';
import {
Transition as _Transition,
TransitionGroup,
Expand Down Expand Up @@ -182,6 +182,10 @@ export const Notifications = factory<NotificationsFactory>((_props, ref) => {
varsResolver,
});

useEffect(() => {
store?.updateState((current) => ({ ...current, limit: limit || 5 }));
}, [limit]);

useDidUpdate(() => {
if (data.notifications.length > previousLength.current) {
setTimeout(() => forceUpdate(), 0);
Expand Down

0 comments on commit 66f05d8

Please sign in to comment.