Skip to content

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

Open
kmcfaul wants to merge 1 commit into
patternfly:mainfrom
kmcfaul:page-main-ref
Open

feat(Page): add ref prop for main element#12588
kmcfaul wants to merge 1 commit 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 a custom reference to a page’s main content area.
    • When no reference is provided, the page continues to manage one automatically.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The Page component now accepts an optional mainRef prop and uses it for the main section, falling back to an internally created 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, and Page uses the provided ref or creates a fallback ref.

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

Suggested reviewers: thatblindgeye

🚥 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 matches the main change: exposing a ref prop for the Page main element.
Linked Issues check ✅ Passed The PR exposes the Page main ref declaratively via a new mainRef prop, which satisfies issue #12428.
Out of Scope Changes check ✅ Passed The changes are narrowly focused on the Page main ref and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 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 on lines +100 to +101
/** Reference for the main section of the page */
mainRef?: React.RefObject<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

Prevent mainRef from leaking onto the outer DOM element.

Because mainRef is not destructured in render, it remains in ...rest and is spread onto the page’s outer <div>, causing an invalid custom DOM prop/warning. Remove it from rest while using it as the main element’s ref.

🤖 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 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.

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

1 participant