Skip to content

[EuiWrappingPopover] Migrate from class component to functional component #9471#9537

Open
parbhat-cpp wants to merge 3 commits intoelastic:mainfrom
parbhat-cpp:main
Open

[EuiWrappingPopover] Migrate from class component to functional component #9471#9537
parbhat-cpp wants to merge 3 commits intoelastic:mainfrom
parbhat-cpp:main

Conversation

@parbhat-cpp
Copy link
Copy Markdown

@parbhat-cpp parbhat-cpp commented Mar 26, 2026

Summary

  • What: Refactor EuiWrappingPopover from class to functional Component.
  • Why: #9471 raised for migration.
  • How: By observing the component behavior and did equivalent changes to the file. Tested by executing yarn test-unit, yarn test-unit popover and through storybook.

API Changes none

Screenshots

Impact Assessment

- [ ] 🔴 Breaking changes — What will break? How many usages in Kibana/Cloud UI are impacted?
- [ ] 💅 Visual changes — May impact style overrides; could require visual testing. Explain and estimate impact.
- [ ] 🧪 Test impact — May break functional or snapshot tests (e.g., HTML structure, class names, default values).
- [ ] 🔧 Hard to integrate — If integration is complex, stage commits in Kibana/Cloud UI branches for cherry-picking and link to them below.

Impact level: 🟢 None

Release Readiness

- [ ] Documentation: {link to docs page(s)}
- [ ] Figma: {link to Figma or issue}
- [ ] Migration guide: {steps or link, for breaking/visual changes or deprecations}
- [ ] Adoption plan (new features): {link to issue/doc or outline who will integrate this and where}

QA instructions for reviewer

  • Run storybook and navigate to EuiWrappingPopover to check if the component is working as expected.

Checklist before marking Ready for Review

Reviewer checklist

  • Approved Impact Assessment — Acceptable to merge given the consumer impact.
  • Approved Release Readiness — Docs, Figma, and migration info are sufficient to ship.

@parbhat-cpp parbhat-cpp requested a review from a team as a code owner March 26, 2026 15:44
Copilot AI review requested due to automatic review settings March 26, 2026 15:44
@cla-checker-service
Copy link
Copy Markdown

cla-checker-service bot commented Mar 26, 2026

💚 CLA has been signed

@github-actions
Copy link
Copy Markdown

👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?

@github-actions github-actions bot added the community contribution (Don't delete - used for automation) label Mar 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors EuiWrappingPopover from a class component to a functional component while preserving its core behavior of portaling the popover next to an existing DOM anchor element and restoring that anchor on unmount.

Changes:

  • Migrated EuiWrappingPopover from Component lifecycle methods to hooks (useLayoutEffect, refs, callbacks).
  • Replaced instance fields/methods with useRef + useCallback equivalents for portal/anchor handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +46
const setAnchorRef = useCallback(
(node: HTMLDivElement | null) => {
node?.insertAdjacentElement('beforebegin', button);
},
[button]
);

useLayoutEffect(() => {
return () => {
if (button.parentNode && portalRef.current) {
portalRef.current.insertAdjacentElement('beforebegin', button);
}
}
}

setPortalRef = (node: HTMLElement | null) => {
this.portal = node;
};

setAnchorRef = (node: HTMLElement | null) => {
node?.insertAdjacentElement('beforebegin', this.props.button);
};

render() {
const { button, ...rest } = this.props;

return (
<EuiPortal
portalRef={this.setPortalRef}
insert={{ sibling: this.props.button, position: 'after' }}
>
<EuiPopover
{...rest}
button={
<div
ref={this.setAnchorRef}
className="euiWrappingPopover__anchor"
/>
}
/>
</EuiPortal>
);
}
};
}, [button]);
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

EuiWrappingPopover's core behavior (moving the external button element into the portal/anchor and restoring it on unmount) changed implementation significantly but currently has no dedicated unit test coverage. Please add a test (e.g. in the popover test suite) that asserts: 1) after mount, the original button is moved into the popover anchor, and 2) after unmount, the button is restored to its original DOM position (not removed with the portal).

Copilot uses AI. Check for mistakes.
@parbhat-cpp
Copy link
Copy Markdown
Author

❌ Author of the following commits did not sign a Contributor Agreement:
d8d69b1, ec6486a, adf5cef

Please, read and sign the above mentioned agreement if you want to contribute to this project

I have signed the agreement, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community contribution (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants