Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nested drawer onOpenChange issue #516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,9 @@ export function Root({

set(drawerRef.current, {
transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)` : `scale(${scale}) translate3d(${initialTranslate}, 0, 0)`,
transform: isVertical(direction)
? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)`
: `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`,
});

if (!o && drawerRef.current) {
Expand Down Expand Up @@ -1093,16 +1095,23 @@ export const Handle = React.forwardRef<HTMLDivElement, HandleProps>(function (

Handle.displayName = 'Drawer.Handle';

export function NestedRoot({ onDrag, onOpenChange, ...rest }: DialogProps) {
export function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }: DialogProps) {
const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();

if (!onNestedDrag) {
throw new Error('Drawer.NestedRoot must be placed in another drawer');
}

React.useEffect(() => {
setTimeout(() => {
onNestedOpenChange(!!nestedIsOpen);
}, TRANSITIONS.DURATION * 1000 + 50);
}, [nestedIsOpen]);

return (
<Root
nested
open={nestedIsOpen}
onClose={() => {
onNestedOpenChange(false);
}}
Expand All @@ -1114,6 +1123,7 @@ export function NestedRoot({ onDrag, onOpenChange, ...rest }: DialogProps) {
if (o) {
onNestedOpenChange(o);
}
onOpenChange?.(o);
}}
onRelease={onNestedRelease}
{...rest}
Expand Down