Skip to content

Commit 9346992

Browse files
eduterZeeshanTamboli
authored andcommitted
[material-ui][Popover] Allow null in anchorEl function return type (#45045)
Signed-off-by: eduter <[email protected]> Co-authored-by: ZeeshanTamboli <[email protected]>
1 parent 123b4ba commit 9346992

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

packages/mui-material/src/Popover/Popover.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ export interface PopoverProps
108108
anchorEl?:
109109
| null
110110
| Element
111-
| (() => Element)
112111
| PopoverVirtualElement
113-
| (() => PopoverVirtualElement);
112+
| (() => Element | PopoverVirtualElement | null);
114113
/**
115114
* This is the point on the anchor where the popover's
116115
* `anchorEl` will attach to. This is not used when the

packages/mui-material/src/Popover/Popover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ const Popover = React.forwardRef(function Popover(inProps, ref) {
349349
setPositioningStyles();
350350
});
351351

352-
const containerWindow = ownerWindow(anchorEl);
352+
const containerWindow = ownerWindow(resolveAnchorEl(anchorEl));
353353
containerWindow.addEventListener('resize', handleResize);
354354
return () => {
355355
handleResize.clear();

packages/mui-material/src/Popover/Popover.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,9 @@ function Custom2(props: PopoverProps) {
7171
</Popover>
7272
);
7373
}
74+
75+
function TestAnchorElementFunctionReturnType() {
76+
const buttonRef = React.useRef<HTMLButtonElement>(null);
77+
78+
return <Popover open anchorEl={() => buttonRef.current} />;
79+
}

0 commit comments

Comments
 (0)