Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Popover] Allow null in anchorEl function return type #45045

Merged
merged 6 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/mui-material/src/Popover/Popover.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ export interface PopoverProps
anchorEl?:
| null
| Element
| (() => Element)
| PopoverVirtualElement
| (() => PopoverVirtualElement);
| (() => Element | PopoverVirtualElement | null);
/**
* This is the point on the anchor where the popover's
* `anchorEl` will attach to. This is not used when the
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
setPositioningStyles();
});

const containerWindow = ownerWindow(anchorEl);
const containerWindow = ownerWindow(resolveAnchorEl(anchorEl));
containerWindow.addEventListener('resize', handleResize);
return () => {
handleResize.clear();
Expand Down
6 changes: 6 additions & 0 deletions packages/mui-material/src/Popover/Popover.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ function Custom2(props: PopoverProps) {
</Popover>
);
}

function TestAnchorElementFunctionReturnType() {
const buttonRef = React.useRef<HTMLButtonElement>(null);

return <Popover open anchorEl={() => buttonRef.current} />;
}