Skip to content

Commit

Permalink
[@mantine/modals] Fix incorrect close modal logic (#3300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Njiallu committed Jan 17, 2023
1 parent 86b3733 commit a5ee0a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/mantine-modals/src/ModalsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ 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: 3 additions & 2 deletions src/mantine-modals/src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export function modalsReducer(
};
}
case 'CLOSE': {
const modals = state.modals.filter((m) => m.id !== action.payload);
return {
current: state.modals[state.modals.length - 2] || null,
modals: state.modals.filter((m) => m.id !== action.payload),
current: modals[modals.length - 1],
modals,
};
}
case 'CLOSE_ALL': {
Expand Down

0 comments on commit a5ee0a4

Please sign in to comment.