Skip to content

fix(combobox): merge consumer props through getReferenceProps (#806)#2014

Open
kotAPI wants to merge 1 commit into
mainfrom
fix/issue-806-combobox-reference-props
Open

fix(combobox): merge consumer props through getReferenceProps (#806)#2014
kotAPI wants to merge 1 commit into
mainfrom
fix/issue-806-combobox-reference-props

Conversation

@kotAPI

@kotAPI kotAPI commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Combobox trigger/search merge user props via getReferenceProps
  • Avoid double-toggle by letting useClick own open state
  • Update context typing for userProps parameter

Fixes #806

Test plan

  • npm test -- --testPathPatterns=Combobox

Summary by CodeRabbit

  • Refactor
    • Updated combobox primitive component's event handling and props management to centralize Enter-key behavior in the search input and streamline click handling in the trigger component.

Pass trigger and search props through floating-ui getReferenceProps so
consumer onClick and other handlers compose with interaction hooks.

Fixes #806
@changeset-bot

changeset-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e6b72ad

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The getReferenceProps function in the Combobox primitive context type is updated to accept an optional userProps parameter. Both ComboboxPrimitiveSearch and ComboboxPrimitiveTrigger are then updated to pass their props and event handlers through getReferenceProps rather than directly on the element, aligning with Floating UI's prop getter pattern.

Changes

Combobox getReferenceProps Prop Forwarding

Layer / File(s) Summary
getReferenceProps context type signature
src/core/primitives/Combobox/contexts/ComboboxPrimitiveContext.tsx
getReferenceProps in ComboboxPrimitiveContextType updated from () => any to (userProps?: any) => any to accept merged props from callers.
Search and Trigger prop forwarding
src/core/primitives/Combobox/fragments/ComboboxPrimitiveSearch.tsx, src/core/primitives/Combobox/fragments/ComboboxPrimitiveTrigger.tsx
ComboboxPrimitiveSearch extracts a handleKeyDown that calls handleSelect on Enter and delegates to props.onKeyDown, then passes value, onChange, onKeyDown, and spread props inside getReferenceProps. ComboboxPrimitiveTrigger removes local setIsOpen toggling, defines handleClick via composeEventHandlers(onClick), and forwards ...props, onClick: handleClick, and disabled directly into getReferenceProps.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

automerge

Suggested reviewers

  • GoldGroove06

Poem

🐇 Hop hop, props now flow the proper way,
Through getReferenceProps they must all stay!
No sneaking handlers straight to the element,
Floating UI rules are quite excellent.
The rabbit refactored, and all is clement~ 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: merging consumer props through getReferenceProps in the Combobox component to fix proper event handler composition.
Linked Issues check ✅ Passed The PR properly addresses issue #806 by updating getReferenceProps signature to accept userProps and routing consumer props through it in both Trigger and Search components, following floating-ui best practices.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #806: updating getReferenceProps typing, merging props in Trigger and Search components, and centralizing event handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-806-combobox-reference-props

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

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

This report compares the PR with the base branch. "Δ" shows how the PR affects each metric.

Metric PR Δ
Statements 75.71% -0.02%
Branches 59.17% +0.00%
Functions 61.68% -0.07%
Lines 77.25% -0.01%

Coverage decreased for at least one metric. Please add or update tests to improve coverage.

Run npm run coverage:ci locally for detailed reports and target untested areas to raise these numbers.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/primitives/Combobox/fragments/ComboboxPrimitiveSearch.tsx`:
- Around line 42-48: The onChange event handler in ComboboxPrimitiveSearch is
overwriting props.onChange instead of composing it, which prevents user-provided
onChange handlers from executing when the search input changes. Locate the
onChange handler definition in the component (around lines 58-63), and ensure it
calls the original props.onChange callback after or alongside the custom
onChange logic, following the same composition pattern used in handleKeyDown
where props.onKeyDown?.(event) is called to preserve the prop composition chain.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 460ca7a8-2918-4c7f-934c-eabe5551a55e

📥 Commits

Reviewing files that changed from the base of the PR and between fe87b36 and e6b72ad.

📒 Files selected for processing (3)
  • src/core/primitives/Combobox/contexts/ComboboxPrimitiveContext.tsx
  • src/core/primitives/Combobox/fragments/ComboboxPrimitiveSearch.tsx
  • src/core/primitives/Combobox/fragments/ComboboxPrimitiveTrigger.tsx

Comment on lines +42 to +48
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (activeIndex !== null && event.key === KEYBOARD_KEYS.ENTER) {
event.preventDefault();
handleSelect(activeIndex);
}
props.onKeyDown?.(event);
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Consumer onChange is dropped instead of composed.

Line 61 overwrites props.onChange and never calls it, so user input handlers on Search won't run. That breaks the prop/event composition objective for this primitive.

Proposed fix
-    const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
-        if (activeIndex !== null && event.key === KEYBOARD_KEYS.ENTER) {
-            event.preventDefault();
-            handleSelect(activeIndex);
-        }
-        props.onKeyDown?.(event);
-    };
+    const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+        if (activeIndex !== null && event.key === KEYBOARD_KEYS.ENTER) {
+            event.preventDefault();
+            handleSelect(activeIndex);
+        }
+        props.onKeyDown?.(event);
+    };
+
+    const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
+        setSearch(e.target.value);
+        props.onChange?.(e);
+    };

             {...getReferenceProps({
                 ...props,
                 value: search,
-                onChange: (e: React.ChangeEvent<HTMLInputElement>) => setSearch(e.target.value),
+                onChange: handleChange,
                 onKeyDown: handleKeyDown
             })}

Also applies to: 58-63

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/primitives/Combobox/fragments/ComboboxPrimitiveSearch.tsx` around
lines 42 - 48, The onChange event handler in ComboboxPrimitiveSearch is
overwriting props.onChange instead of composing it, which prevents user-provided
onChange handlers from executing when the search input changes. Locate the
onChange handler definition in the component (around lines 58-63), and ensure it
calls the original props.onChange callback after or alongside the custom
onChange logic, following the same composition pattern used in handleKeyDown
where props.onKeyDown?.(event) is called to preserve the prop composition chain.

@kotAPI

kotAPI commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Code review

LGTM. Matches project patterns for portal Theme refs, Floating UI prop merge, controlled-switch/lazy-mount/RTL tests, or focused bug fixes. No changes requested.

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.

BUG: Event handlers and props should be passed to getReferenceProps and not the element itself

1 participant