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: Add onPress function/handler to web Select trigger #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthewjchurch
Copy link

@matthewjchurch matthewjchurch commented Mar 5, 2025

Summary by CodeRabbit

  • New Features
    • Improved press interaction for the select trigger component, which now supports a custom action when pressed. This enhancement ensures that additional logic is executed only when the component is active, delivering a more controlled user experience.

Copy link

vercel bot commented Mar 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rn-primitives ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 5, 2025 5:13pm

Copy link

coderabbitai bot commented Mar 5, 2025

Walkthrough

This change updates the press event handling in the Trigger component within the select package. A new onPress prop is introduced and an internal onPress function handles the press events by first checking if the component is disabled. If not, it toggles the open state via onOpenChange and invokes the new onPress callback with the event object. Additionally, the type import for GestureResponderEvent is added for proper type checking.

Changes

Files Change Summary
packages/select/.../select.web.tsx - Added new onPress prop to the Trigger component signature
- Implemented internal onPress function to check disabled state and invoke onOpenChange and external onPress callback
- Added import for GestureResponderEvent

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant T as Trigger Component
    participant O as onOpenChange Handler
    participant P as onPress Callback

    U->>+T: Triggers press event
    T-->>T: Check if component is disabled
    alt Component enabled
        T->>+O: Toggle open state
        O-->>-T: Open state toggled
        T->>+P: Call onPress with event
        P-->>-T: Callback executed
    else Component disabled
        T-->>U: No action taken (disabled)
    end
Loading

Poem

I'm a rabbit, hopping through code,
With a new press event mode,
Checking if disabled before I act,
On open change, I'm exact!
Pressing on with joy and might,
My changes hop into the light!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (1)
packages/select/src/select.web.tsx (1)

114-155: Consider adding documentation for the new onPress prop.

The implementation is correct, but it would be helpful to add JSDoc comments for the new onPress prop to help consumers understand its purpose and usage, similar to how other components in this file are documented.

You could add something like:

const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
  /** 
   * Trigger component for the Select
   * @param onPress - Optional callback when the trigger is pressed
   */
  ({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 699fe56 and 6fc3854.

📒 Files selected for processing (1)
  • packages/select/src/select.web.tsx (3 hunks)
🔇 Additional comments (4)
packages/select/src/select.web.tsx (4)

9-9: Added GestureResponderEvent type import correctly.

Good addition of the GestureResponderEvent type import from react-native, which is needed for proper type checking of the event parameter in the new onPress function.


115-115: Added onPress prop to Trigger component correctly.

Good implementation of adding the onPress prop to the Trigger component's props, allowing consumers to provide their own press handler while maintaining the component's core functionality.


117-121: Well-implemented onPress handler function.

The onPress function implementation follows good practices:

  1. It first checks if the component is disabled before proceeding
  2. It handles the core functionality (toggling open state)
  3. It then calls the custom handler if provided

This approach ensures the component's primary behavior works as expected while allowing for extensibility.


146-152: Updated Component JSX to use the new onPress handler.

The Component JSX has been properly updated to use the new onPress function, ensuring that both the core functionality and any custom behavior will be executed when the component is pressed.

Comment on lines +117 to +121
function onPress(ev: GestureResponderEvent) {
if (disabled) return;
onOpenChange(!open);
onPressProp?.(ev);
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider unit testing the new onPress functionality.

The implementation is good, but you might want to verify:

  1. The default toggle behavior works as expected
  2. The custom onPress handler is called when provided
  3. Neither function executes when the component is disabled

🏁 Script executed:

#!/bin/bash
# Check if there are any unit tests for the Trigger component

echo "Searching for existing tests..."
find . -type f -name "*.test.tsx" -o -name "*.spec.tsx" | xargs grep -l "Trigger" || echo "No test files found mentioning Trigger"

echo "Checking if onPress is tested in any files..."
find . -type f -name "*.test.tsx" -o -name "*.spec.tsx" | xargs grep -l "onPress.*Trigger" || echo "No test files found testing onPress on Trigger"

Length of output: 538


Action Required: Add Unit Tests for onPress Functionality

The implementation in packages/select/src/select.web.tsx looks correct. However, our verification indicates that there are no existing tests covering the onPress functionality. Please add unit tests to ensure:

  • The default toggle behavior (onOpenChange(!open)) works as expected.
  • The custom onPressProp callback is invoked when provided.
  • Neither action is executed when the component is disabled.

@matthewjchurch
Copy link
Author

This is with reference to issue #66

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