Skip to content

Conversation

@fxamauri
Copy link

@fxamauri fxamauri commented Oct 17, 2025

Description

This PR adds a new closeOnBackPress prop to the Dialog component, allowing to control how the physical BackPress button behaves on React Native.

Motivation

Previously, the Dialog would always close automatically when the Android back button was pressed. In some scenarios, it's necessary to keep the dialog open or handle the back press action more granularly.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added closeOnBackPress prop to the Dialog Root component (native platforms only), allowing control over whether the dialog closes when pressing the hardware back button. Enabled by default.
  • Documentation

    • Updated Dialog documentation with formatting improvements and details for the new closeOnBackPress prop.

@vercel
Copy link

vercel bot commented Oct 17, 2025

@fxamauri is attempting to deploy a commit to the Ronin Technologies Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Oct 17, 2025

Walkthrough

This PR adds a new optional closeOnBackPress prop to the Dialog Root component (Native only) with a default value of true. The prop is forwarded through DialogContext to the Content component, where it conditionally prevents dialog closure on hardware back button press when set to false. Changes include type definitions, implementation logic, and documentation updates.

Changes

Cohort / File(s) Summary
Documentation
apps/docs/src/content/docs/dialog.mdx
Added closeOnBackPress prop to the Root component props table; minor formatting and indentation adjustments to code examples and headers.
Type Definitions
packages/dialog/src/types.ts
Added optional closeOnBackPress?: boolean property to RootProps and RootContext types with Platform: NATIVE ONLY annotation.
Implementation
packages/dialog/src/dialog.tsx
Added closeOnBackPress prop to Root component (default true), forwarded through DialogContext.Provider; Content component now conditionally closes on back press based on context value; back press handler effect dependency updated.

Sequence Diagram

sequenceDiagram
    actor User
    participant Dialog Root
    participant Dialog Context
    participant Dialog Content
    participant Hardware

    User->>Dialog Root: Define closeOnBackPress prop
    Dialog Root->>Dialog Context: Provide closeOnBackPress value
    Dialog Content->>Dialog Context: Read closeOnBackPress
    Hardware->>Dialog Content: Back button pressed
    alt closeOnBackPress === true
        Dialog Content->>Dialog Content: Call onOpenChange(false)
        Dialog Content->>User: Dialog closes
    else closeOnBackPress === false
        Dialog Content->>User: Dialog remains open
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "feat: add closeOnBackPress prop to Dialog" is a clear and specific summary that directly aligns with the primary changes in the changeset. The title accurately describes the main feature being introduced—a new prop to control the Dialog component's Android back-press behavior—which is reflected across all modified files: the component implementation, type definitions, and documentation updates. The title uses conventional commit formatting, is concise and readable, and provides enough specificity that a teammate reviewing the commit history would immediately understand the core change without ambiguity.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13c40e2 and 8f440d6.

📒 Files selected for processing (3)
  • apps/docs/src/content/docs/dialog.mdx (4 hunks)
  • packages/dialog/src/dialog.tsx (3 hunks)
  • packages/dialog/src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/dialog/src/types.ts (4)
packages/popover/src/popover.tsx (3)
  • IRootContext (22-30)
  • backHandler (211-223)
  • onPress (145-165)
packages/alert-dialog/src/alert-dialog.web.tsx (2)
  • open (25-39)
  • props (108-131)
packages/dialog/src/dialog.web.tsx (2)
  • open (25-39)
  • props (93-100)
packages/context-menu/src/context-menu.web.tsx (1)
  • close (77-79)
packages/dialog/src/dialog.tsx (1)
packages/popover/src/popover.tsx (1)
  • backHandler (211-223)
apps/docs/src/content/docs/dialog.mdx (1)
packages/dialog/src/dialog.web.tsx (4)
  • props (175-182)
  • props (93-100)
  • open (25-39)
  • props (106-132)
🔇 Additional comments (4)
packages/dialog/src/types.ts (1)

14-18: LGTM! Type definitions are consistent and well-documented.

The closeOnBackPress prop is correctly defined as an optional boolean in both RootContext and RootProps, with appropriate platform annotations. This aligns well with the implementation pattern.

Also applies to: 25-29

packages/dialog/src/dialog.tsx (2)

28-37: LGTM! Root component properly handles the new prop.

The closeOnBackPress prop is correctly implemented with a sensible default value of true that maintains backward compatibility. The prop is properly forwarded through the context to descendant components.

Also applies to: 48-59


148-151: Verify the intended back press event consumption behavior.

The back handler always returns true (consuming the event) regardless of the closeOnBackPress value. This means when closeOnBackPress={false}, the back button is still intercepted but the dialog stays open—users cannot use back navigation while the dialog is visible.

If the intent is to allow back press propagation (e.g., to close the app or navigate) when closeOnBackPress={false}, consider returning the value of closeOnBackPress instead:

   const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
     if (closeOnBackPress) {
       onOpenChange(false);
     }
-    return true;
+    return closeOnBackPress;
   });

Otherwise, the current behavior is correct for a modal dialog that should prevent back navigation.

apps/docs/src/content/docs/dialog.mdx (1)

140-146: LGTM! Documentation accurately reflects the new prop.

The closeOnBackPress prop is properly documented in the Root component's props table with the correct platform annotation and optional designation.

Comment on lines 146 to +157
React.useEffect(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
onOpenChange(false);
if (closeOnBackPress) {
onOpenChange(false);
}
return true;
});

return () => {
backHandler.remove();
};
}, []);
}, [closeOnBackPress]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add onOpenChange to the effect dependency array.

The useEffect hook calls onOpenChange inside the back handler but doesn't include it in the dependency array. This can lead to stale closure bugs where an outdated version of onOpenChange is invoked.

Apply this diff:

     React.useEffect(() => {
       const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
         if (closeOnBackPress) {
           onOpenChange(false);
         }
         return true;
       });
 
       return () => {
         backHandler.remove();
       };
-    }, [closeOnBackPress]);
+    }, [closeOnBackPress, onOpenChange]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
React.useEffect(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
onOpenChange(false);
if (closeOnBackPress) {
onOpenChange(false);
}
return true;
});
return () => {
backHandler.remove();
};
}, []);
}, [closeOnBackPress]);
React.useEffect(() => {
const backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
if (closeOnBackPress) {
onOpenChange(false);
}
return true;
});
return () => {
backHandler.remove();
};
}, [closeOnBackPress, onOpenChange]);
🤖 Prompt for AI Agents
In packages/dialog/src/dialog.tsx around lines 146 to 157, the useEffect
registers a hardwareBackPress handler that calls onOpenChange but onOpenChange
is missing from the dependency array; update the effect dependencies to include
onOpenChange (i.e., change the dependency array from [closeOnBackPress] to
[closeOnBackPress, onOpenChange]) so the latest callback is used and
stale-closure bugs are avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant