Skip to content

fix: Add onPress function/handler to web Select trigger #65

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

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
18 changes: 15 additions & 3 deletions packages/select/src/select.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@rn-primitives/hooks';
import * as Slot from '@rn-primitives/slot';
import * as React from 'react';
import { Pressable, Text, View } from 'react-native';
import { GestureResponderEvent, Pressable, Text, View } from 'react-native';
import type {
ContentProps,
ContentRef,
Expand Down Expand Up @@ -112,8 +112,14 @@ function useRootContext() {
}

const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
({ asChild, role: _role, disabled, ...props }, ref) => {
({ asChild, onPress: onPressProp, role: _role, disabled, ...props }, ref) => {
const { open, onOpenChange } = useRootContext();
function onPress(ev: GestureResponderEvent) {
if (disabled) return;
onOpenChange(!open);
onPressProp?.(ev);
}
Comment on lines +117 to +121
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.


const augmentedRef = useAugmentedRef({
ref,
methods: {
Expand All @@ -137,7 +143,13 @@ const Trigger = React.forwardRef<TriggerRef, TriggerProps>(
const Component = asChild ? Slot.Pressable : Pressable;
return (
<Select.Trigger disabled={disabled ?? undefined} asChild>
<Component ref={augmentedRef} role='button' disabled={disabled} {...props} />
<Component
onPress={onPress}
ref={augmentedRef}
role='button'
disabled={disabled}
{...props}
/>
</Select.Trigger>
);
}
Expand Down