Skip to content

fix(menu): merge content props through getFloatingProps (#806)#2024

Open
kotAPI wants to merge 1 commit into
mainfrom
fix/issue-806-menu-content-floating-props
Open

fix(menu): merge content props through getFloatingProps (#806)#2024
kotAPI wants to merge 1 commit into
mainfrom
fix/issue-806-menu-content-floating-props

Conversation

@kotAPI

@kotAPI kotAPI commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Menu content merges consumer props via getFloatingProps

Fixes #806

Test plan

  • npm test -- --testPathPatterns=MenuPrimitive.test

Summary by CodeRabbit

  • Refactor
    • Improved internal property handling in the Menu component for better code reliability.

Pass menu content props into getFloatingProps for correct handler merge.

Fixes #806
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5f30d03

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 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

In MenuPrimitiveContent, the <div> now passes ...props, className, and style: floatingStyles as a single merged object argument to getFloatingProps(...), replacing the previous pattern of calling getFloatingProps() with no arguments and applying those values as separate props/spreads on the element.

Changes

Menu Floating Props Fix

Layer / File(s) Summary
Merge props into getFloatingProps call
src/core/primitives/Menu/fragments/MenuPrimitiveContent.tsx
getFloatingProps now receives a single object merging ...props, className, and style: floatingStyles, replacing the prior pattern of passing no arguments and spreading those values directly on the <div>.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • mrkazmi333

Poem

🐇 No more props left floating free,
Into the getter they all must be!
className, style, and all the rest —
Merged in one call, that works the best.
Floating UI says "pass them right,"
And now our menu feels just right! ✨

🚥 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 clearly and specifically describes the main change: merging content props through getFloatingProps in the Menu component.
Linked Issues check ✅ Passed The PR addresses issue #806 by implementing the required fix to merge consumer props through getFloatingProps, aligning with Floating UI best practices for proper event handler and prop composition.
Out of Scope Changes check ✅ Passed All changes in MenuPrimitiveContent are directly related to the objective of merging props through getFloatingProps, with no out-of-scope modifications detected.
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-menu-content-floating-props

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

@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.73% +0.00%
Branches 59.17% +0.00%
Functions 61.75% +0.00%
Lines 77.26% +0.00%

Coverage improved or stayed the same. Great job!

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/Menu/fragments/MenuPrimitiveContent.tsx`:
- Around line 39-43: In MenuPrimitiveContentProps, expand the type definition to
accept standard HTML div attributes (such as data attributes, event handlers,
and style properties) in addition to the currently restricted children and
className. In the MenuPrimitiveContent component where getFloatingProps is
called, modify the style composition to merge floatingStyles with any custom
style from props rather than overwriting it, ensuring that custom styles are
preserved while floating positioning styles are applied. This allows consumers
to pass through additional attributes and maintain style precedence as intended.
🪄 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: 74bd67b6-2871-4538-a642-9828134c9c20

📥 Commits

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

📒 Files selected for processing (1)
  • src/core/primitives/Menu/fragments/MenuPrimitiveContent.tsx

Comment on lines +39 to +43
{...getFloatingProps({
...props,
className,
style: floatingStyles
})}

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.

🎯 Functional Correctness | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/core/primitives/Menu/fragments/MenuPrimitiveContent.tsx"

echo "=== Type definition and call site ==="
nl -ba "$FILE" | sed -n '1,90p'

echo
echo "=== Check whether props type includes HTML attributes ==="
rg -n "export type MenuPrimitiveContentProps|HTMLAttributes<HTMLDivElement>" "$FILE" -C2

echo
echo "=== Check current style merge order in getFloatingProps ==="
rg -n "getFloatingProps\\(|\\.\\.\\.props|style:\\s*floatingStyles" "$FILE" -C2

Repository: rad-ui/ui

Length of output: 225


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/core/primitives/Menu/fragments/MenuPrimitiveContent.tsx"

echo "=== File contents lines 1-90 ==="
cat -n "$FILE" | head -90

echo ""
echo "=== Type definition ==="
rg -n "export type MenuPrimitiveContentProps" "$FILE" -A5

echo ""
echo "=== getFloatingProps call site ==="
rg -n "getFloatingProps" "$FILE" -B3 -A5

Repository: rad-ui/ui

Length of output: 3337


Consumer prop composition remains incomplete and style merging overwrites custom styles.

The style: floatingStyles assignment at line 42 deterministically overwrites any style from ...props. Additionally, MenuPrimitiveContentProps narrowly restricts consumers to children and className only, preventing them from passing standard HTML div attributes (data attributes, event handlers, etc.) that the ...props spread attempts but cannot accommodate due to the type constraint.

Suggested fix
-export type MenuPrimitiveContentProps = {
-    children: React.ReactNode;
-    className?: string;
-};
+export type MenuPrimitiveContentProps = React.HTMLAttributes<HTMLDivElement> & {
+    children: React.ReactNode;
+};

 const MenuPrimitiveContent = forwardRef<HTMLDivElement, MenuPrimitiveContentProps>(
-    ({ children, className, ...props }, propRef) => {
+    ({ children, className, style: styleProp, ...props }, propRef) => {
         const context = useContext(MenuPrimitiveRootContext);
         const mergedRef = Floater.useMergeRefs([
             context?.refs.setFloating,
@@ -37,7 +37,7 @@ const MenuPrimitiveContent = forwardRef<HTMLDivElement, MenuPrimitiveContentPro
                     <div
                         ref={mergedRef}
                         {...getFloatingProps({
                             ...props,
                             className,
-                            style: floatingStyles
+                            style: { ...styleProp, ...floatingStyles }
                         })}
🤖 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/Menu/fragments/MenuPrimitiveContent.tsx` around lines 39
- 43, In MenuPrimitiveContentProps, expand the type definition to accept
standard HTML div attributes (such as data attributes, event handlers, and style
properties) in addition to the currently restricted children and className. In
the MenuPrimitiveContent component where getFloatingProps is called, modify the
style composition to merge floatingStyles with any custom style from props
rather than overwriting it, ensuring that custom styles are preserved while
floating positioning styles are applied. This allows consumers to pass through
additional attributes and maintain style precedence as intended.

@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