Skip to content

Commit

Permalink
[@mantine/modals] Fix modals closing issues #3300
Browse files Browse the repository at this point in the history
This reverts commit a5ee0a4.
  • Loading branch information
rtivital committed Jan 25, 2023
1 parent 5a92ed5 commit 02a5053
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/mantine-modals/src/ModalsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export function ModalsProvider({ children, modalProps, labels, modals }: ModalsP
};

const closeModal = (id: string, canceled?: boolean) => {
if (state.modals.length <= 1) {
closeAll(canceled);
return;
}

const modal = state.modals.find((item) => item.id === id);
if (modal?.type === 'confirm' && canceled) {
modal.props?.onCancel?.();
Expand Down
5 changes: 2 additions & 3 deletions src/mantine-modals/src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ export function modalsReducer(
};
}
case 'CLOSE': {
const modals = state.modals.filter((m) => m.id !== action.payload);
return {
current: modals[modals.length - 1],
modals,
current: state.modals[state.modals.length - 2] || null,
modals: state.modals.filter((m) => m.id !== action.payload),
};
}
case 'CLOSE_ALL': {
Expand Down

0 comments on commit 02a5053

Please sign in to comment.