Skip to content

feat(Page): add ref prop for main element - #12588

Open
kmcfaul wants to merge 2 commits into
patternfly:mainfrom
kmcfaul:page-main-ref
Open

feat(Page): add ref prop for main element#12588
kmcfaul wants to merge 2 commits into
patternfly:mainfrom
kmcfaul:page-main-ref

Conversation

@kmcfaul

@kmcfaul kmcfaul commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What: Closes #12428

Adds mainRef property to allow a user to pass their own ref to Page's main element.

Summary by CodeRabbit

  • New Features
    • Added support for providing an optional custom reference to a page’s main content container.
    • When a reference is supplied, the page will use it; otherwise it will continue to handle the main container reference automatically.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c632b1c-ca1c-493f-845f-71e418841da3

📥 Commits

Reviewing files that changed from the base of the PR and between bc2c812 and 91736fe.

📒 Files selected for processing (1)
  • packages/react-core/src/components/Page/Page.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-core/src/components/Page/Page.tsx

Walkthrough

The Page component now accepts an optional mainRef prop, using it for the main section or creating an internal ref when none is provided.

Changes

Page main ref support

Layer / File(s) Summary
Page main ref contract and fallback
packages/react-core/src/components/Page/Page.tsx
PageProps exposes an optional mainRef; Page uses the provided ref or creates a fallback ref and includes it in render prop handling.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 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 is concise and accurately reflects the Page main ref addition.
Linked Issues check ✅ Passed The Page component now accepts mainRef and uses it for the main element, matching the requested declarative ref exposure.
Out of Scope Changes check ✅ Passed The changes stay focused on exposing the Page main ref with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@packages/react-core/src/components/Page/Page.tsx`:
- Around line 100-101: Update the Page component’s render/destructuring logic to
explicitly extract mainRef from the props before collecting ...rest, then
continue applying mainRef to the main section ref. Ensure mainRef is excluded
from the outer div’s spread props while preserving all other rest properties.
- Around line 137-140: Update the Page component’s mainRef handling so the
constructor or field initializer only creates a stable internal fallback, while
rendering and lifecycle logic resolve this.props.mainRef on each update. Track
the effective ref identity and rebind mousedown/touch listeners whenever it
changes, ensuring listeners are removed from the previous element and attached
to the current one.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f836f8df-09a3-4b35-b8e4-f280c29d03bd

📥 Commits

Reviewing files that changed from the base of the PR and between 7a55868 and bc2c812.

📒 Files selected for processing (1)
  • packages/react-core/src/components/Page/Page.tsx

Comment thread packages/react-core/src/components/Page/Page.tsx
Comment on lines +137 to +140
getVerticalBreakpoint,
mainRef: undefined
};
mainRef = createRef<HTMLDivElement>();
mainRef = this.props?.mainRef ? this.props.mainRef : createRef<HTMLDivElement>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Resolve mainRef from current props, not once at construction.

The field initializer permanently captures the initial prop. If a caller supplies or replaces mainRef after mount, the component continues using the old ref; its mousedown/touch listeners are also attached to the wrong element. Keep a stable internal fallback, resolve the current prop during rendering/lifecycle updates, and rebind listeners when the ref identity changes.

🤖 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 `@packages/react-core/src/components/Page/Page.tsx` around lines 137 - 140,
Update the Page component’s mainRef handling so the constructor or field
initializer only creates a stable internal fallback, while rendering and
lifecycle logic resolve this.props.mainRef on each update. Track the effective
ref identity and rebind mousedown/touch listeners whenever it changes, ensuring
listeners are removed from the previous element and attached to the current one.

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.

Expose Page main ref

2 participants