Skip to content

Commit cb4bd40

Browse files
committed
fix: async drawer
1 parent 87eb883 commit cb4bd40

File tree

6 files changed

+49
-29
lines changed

6 files changed

+49
-29
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"bugs": {
1717
"url": "https://github.com/Codpoe/shadcn-react/issues"
1818
},
19-
"homepage": "https://github.com/Codpoe/shadcn-react#readme",
19+
"homepage": "https://codpoe.github.io/shadcn-react",
2020
"author": "Codpoe <[email protected]> (https://github.com/codpoe)",
2121
"engines": {
2222
"node": ">=18.18.0",

src/Dialog/index.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,27 @@ export function Dialog(props: DialogProps) {
5858
setOkLoading(true);
5959
}, 50);
6060

61-
await onOk?.(ev);
62-
clearTimeout(timer);
63-
setOkLoading(false);
64-
closeBtnRef.current?.click();
61+
try {
62+
await onOk?.(ev);
63+
closeBtnRef.current?.click();
64+
} finally {
65+
clearTimeout(timer);
66+
setOkLoading(false);
67+
}
6568
};
6669

6770
const handleCancel = async (ev: MouseEvent) => {
6871
const timer = setTimeout(() => {
6972
setCancelLoading(true);
7073
}, 50);
7174

72-
await onCancel?.(ev);
73-
clearTimeout(timer);
74-
setCancelLoading(false);
75-
closeBtnRef.current?.click();
75+
try {
76+
await onCancel?.(ev);
77+
closeBtnRef.current?.click();
78+
} finally {
79+
clearTimeout(timer);
80+
setCancelLoading(false);
81+
}
7682
};
7783

7884
return (

src/Drawer/index.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,27 @@ export function Drawer(props: DrawerProp) {
6363
setOkLoading(true);
6464
}, 50);
6565

66-
await onOk?.(ev);
67-
clearTimeout(timer);
68-
setOkLoading(false);
69-
closeBtnRef.current?.click();
66+
try {
67+
await onOk?.(ev);
68+
closeBtnRef.current?.click();
69+
} finally {
70+
clearTimeout(timer);
71+
setOkLoading(false);
72+
}
7073
};
7174

7275
const handleCancel = async (ev: MouseEvent) => {
7376
const timer = setTimeout(() => {
7477
setCancelLoading(true);
7578
}, 50);
7679

77-
await onCancel?.(ev);
78-
clearTimeout(timer);
79-
setCancelLoading(false);
80-
closeBtnRef.current?.click();
80+
try {
81+
await onCancel?.(ev);
82+
closeBtnRef.current?.click();
83+
} finally {
84+
clearTimeout(timer);
85+
setCancelLoading(false);
86+
}
8187
};
8288

8389
return (

src/Dropdown/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ export interface DropdownItemProps
6666
}
6767

6868
export interface DropdownProps
69-
extends DropdownMenuProps,
70-
Omit<DropdownMenuContentProps, 'content'> {
69+
extends Omit<DropdownMenuProps, 'children'>,
70+
Omit<DropdownMenuContentProps, 'content' | 'children'> {
7171
content?: React.ReactNode;
72+
children?: React.ReactNode;
7273
className?: string;
7374
style?: React.CSSProperties;
7475
}

src/Sheet/index.tsx

+14-8
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,27 @@ export function Sheet(props: SheetProps) {
6262
setOkLoading(true);
6363
}, 50);
6464

65-
await onOk?.(ev);
66-
clearTimeout(timer);
67-
setOkLoading(false);
68-
closeBtnRef.current?.click();
65+
try {
66+
await onOk?.(ev);
67+
closeBtnRef.current?.click();
68+
} finally {
69+
clearTimeout(timer);
70+
setOkLoading(false);
71+
}
6972
};
7073

7174
const handleCancel = async (ev: MouseEvent) => {
7275
const timer = setTimeout(() => {
7376
setCancelLoading(true);
7477
}, 50);
7578

76-
await onCancel?.(ev);
77-
clearTimeout(timer);
78-
setCancelLoading(false);
79-
closeBtnRef.current?.click();
79+
try {
80+
await onCancel?.(ev);
81+
closeBtnRef.current?.click();
82+
} finally {
83+
clearTimeout(timer);
84+
setCancelLoading(false);
85+
}
8086
};
8187

8288
return (

src/Tooltip/index.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ interface TooltipContentProps
1010
extends ComponentPropsWithoutRef<typeof TooltipContent> {}
1111

1212
export interface TooltipProps
13-
extends ComponentPropsWithoutRef<typeof UiTooltip>,
14-
Omit<TooltipContentProps, 'content'> {
13+
extends Omit<ComponentPropsWithoutRef<typeof UiTooltip>, 'children'>,
14+
Omit<TooltipContentProps, 'content' | 'children'> {
15+
children?: React.ReactNode;
1516
content?: React.ReactNode;
1617
className?: string;
1718
style?: React.CSSProperties;

0 commit comments

Comments
 (0)