Skip to content

Commit eae7201

Browse files
authored
#88 added hideOnClose flag (#89)
* #88 add hideOnClose flag * #88 fixed eslint issues * #88 patch 2.4.1
1 parent b6c8bc1 commit eae7201

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.4.0",
2+
"version": "2.4.1",
33
"license": "MIT",
44
"name": "mui-modal-provider",
55
"author": "Quernest",

src/modal-provider.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('ModalProvider', () => {
2727

2828
const modalOptions: Options = {
2929
rootId,
30+
hideOnClose: true,
3031
};
3132

3233
let uidSpy: jest.SpyInstance;
@@ -138,6 +139,7 @@ describe('ModalProvider', () => {
138139
[id]: {
139140
component: Modal,
140141
options: {
142+
hideOnClose: true,
141143
rootId: rootId,
142144
},
143145
props: {

src/modal-provider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ export default function ModalProvider({
142142
const { component: Component, props, options } = state[id];
143143

144144
const handleClose = (...args: any[]) => {
145+
if (options && options.hideOnClose) {
146+
hide(id);
147+
}
148+
145149
if (options && options.destroyOnClose) {
146150
destroy(id);
147-
} else {
148-
hide(id);
149151
}
150152

151153
if (props && props.onClose) {

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Props {
1010
}
1111

1212
export interface Options {
13+
hideOnClose?: boolean;
1314
destroyOnClose?: boolean;
1415
rootId?: string;
1516
}

src/use-modal.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('useModal', () => {
4242
options: {
4343
rootId,
4444
destroyOnClose: true,
45+
hideOnClose: true,
4546
},
4647
props: {
4748
open: true,

src/use-modal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export default function useModal(options: UseModalOptions = defaultOptions) {
3232
return {
3333
showModal: useCallback<ShowFn>(
3434
(component, props, options) =>
35-
showModal(component, props, { rootId: id.current, ...options }),
35+
showModal(component, props, {
36+
rootId: id.current,
37+
hideOnClose: true,
38+
...options,
39+
}),
3640
[showModal]
3741
),
3842
destroyModal,

0 commit comments

Comments
 (0)